Smart Alarm Buttons

In the past I built a simple alarm button, which is very similar to existing projects:

  • The device has a single button.
  • When it boots up it connects to your WiFi network.
    • Then it sits idle waiting for the button to be pressed.
  • When the button is pressed it posts a message to an MQ queue.
    • By listening to that same MQ instance your PC can now "do stuff".

This project was a fun learning experience, and if you only want one it is perfect. If you want to build several though it becomes more expensive than it needs to be. The Wemos Mini D1 costs approximately €2.50, adding a simple 3D-printed case will double the price, and because using WiFi is quite power-intensive you don't get great battery life. Which means you'll probably have to tether your button with a simple USB-power supply.

Some IoT buttons instead use deep-sleep, only waking up and connecting to your WiFi network as a result of a button-press. This is more efficient, and will allow better battery-life, however any use of WiFi is still pretty power-draining.

If you want multiple buttons, one in each room for example, then it might make sense to take the "smarts" out of the button. Make the buttons "dumb", and put all the smarts on your local PC/Raspberry PI instead. This lowers the cost and the complexity of the button, allowing you to easily have more of them.

Buttons that transmit via radio

One way to make the buttons dumb is to use off-the-shelf parts. For example I found several "emergency button" available from AliExpress for approximately €3 each. Here's one of the ones that I bought:

Wireless Button

These devices are self-contained, powered by a small CR2032 battery, and they trigger a brief radio transmission when pressed. Because they don't use WiFi in any way you don't need to configure them with credentials, and they use less power than the home-made device I referenced above.

Receiving the button-presses

If you have a cheap SDR receiver you can receive the radio-transmissions the buttons send, and then trigger actions. All the "smarts" are on the receiving-side (i.e. your desktop PC, or Raspberry PI).

For the software to receive them I'm using the following project:

Launching it like this allows all the built-in decoders to attempt to recognize & decode the payload of incoming radio-transmissions:

$ rtl_433 -G
Bit detection level set to 0 (Auto).
Tuner gain set to Auto.
Reading samples in async mode...
Tuned to 433920000 Hz.

Once I press one of my buttons I see output like this logged to the console:

2018-03-10 10:29:09 :	Generic Remote
	House Code:	 49476
	Command:	 8
	Tri-State:	 100FF0F000!0

Here "House Code" contains a unique ID for each transmitter. Using the code would allow me to trigger different actions based upon the button pressed, and also to ignore any buttons that are unknown to me - for example if one of my neighbours also used the same device(s).

Improving the radio receiver

As shown above the rtl_433 project does indeed recognize my buttons, and it will log to the console when a transmission is received.

Ideally what I'd like is to trigger an action when a button is pressed. To do that I made a small change to the code. Because my button was identified as a "generic remote" I added this small piece of code to the file src/devices/generic_remote.c, and rebuilt the project:

                // When a transmission is received run a command with
                // the button-ID as an argument.
                // Only run the command a maximum of once per second.
                static int last = 0;
                if ( time(NULL) - last  > 1 ) {

                    char buf[256] = { '\0' };

                    // Run the command "button-pressed $id"
                    snprintf(buf, sizeof(buf)-1, "button-pressed 0x%04X\n", ID_16b);

                    // Record our last time.
                    last = time(NULL);

With this code in place I just write "~/bin/button-pressed" which can post to MQ, turn off my lights, or carry out different actions.

Because the ID of the button is passed as the first/only argument to that script I can take out different actions depending on which specific button was pressed too!

Recieving button-presses on the Wemos Mini D1

I also have a 433Mhz transmitter and receiver, which can be hooked up to the Wemos Mini D1 - in the future I'll document my code here for responding to these buttons too.