- Home
- Learn Linux
- Learn Electronics
- Raspberry Pi
- Programming
- Projects
- LPI certification
- News & Reviews
11 April 2019
I have recently been upgrading some of my home automation. I already use Energenie Pi-Mote to control some electrical power sockets, I've now replaced some of my light switches with Sengled home automation light bulbs.
Initially I've been using my Pi-power software running on a Raspberry Touch Screen and some timed actions to automatically turn lights on and off at certain times of the day.
I've now reconfigured some of my now unused Amazon Dash buttons so that they can control both the Sengled Light Bulbs and the Energenie remote control sockets.
In the photo shown the dash button is placed on the normal light switch. It may sound like a folly to replace a mechanical switch with a computer based one that does the same thing but it does make sense in this situation. The reason is that this is a porch light between the front door and an inner front door. The light is needed to be able to see the lock on the door at night, but the switch is on the inside of the door. Using home automation I can set the light to come on when I normally arrive home and then another dash button inside the porch allows me to switch it on at times when I come home at a different time. Having a dash on the physical light switch gives a way of turning the light on and off without using the normal switch, which would power off the bulb and disable the home automation capability.
Unfortunately Amazon appear to have discontinued the regular Dash buttons. If you have some old dash buttons around then it is a useful way to give them a new lease of life in home automation.
This uses the Amazon-dash project on pypi. Installation is straight forward using pip3.
On a Raspberry Pi using Raspbian use
sudo pip3 install amazon-dash
sudo python -m amazon_dash.install
(On other Linux distrubtions you may need to use pip instead of pip3).
You then need to edit the /etc/amazon-dash.yml configuration file with the MAC address for each button and the event that needs to be triggered.
The Amazon Dash buttons first need to be registered through the Amazon app (but don't selected a product otherwise you'll be ordering something each time you turn the light on and off). To find the MAC address for the buttons use the discovery option and then press the dash button:
sudo amazon-dash discovery
This value is then used for the triggers in the configuration file.
I used IFTTT (If This Then That) for my Sengled home automation light bulbs and the web interface I created for the Energenie Remote Control sockets.
To use IFTTT you first need to register through the website and create a webhook (Maker Event). To find the unique code for your services go to the Services in you account. Click on Webhooks and then settings and you will see a long code as part of the URL. That needs to be used as the ifttt code in the configuration file.
These are the entries used for the IFTTT connections:
## Porch light from hallway
FC:A6:68:11:22:33:
name: Mentos button
ifttt: myIFTTTlongcodevalueaaaabbbbccccdddd
event: porch_light_toggle
data: {"value1": "Mentos button"}
## Porch light from porch
68:54:F1:11:22:44:
name: Heineken button
ifttt: myIFTTTlongcodevalueaaaabbbbccccdddd
event: porch_light_toggle
data: {"value1": "Heineken button"}
These are both toggle events, so each switch can turn the light on and off.
For the Energenie connections then using the "standard" sockets there is no way of knowing the current state of the plug, as even if you kept track of how it has been triggered through the pi-power app, someone could have pressed the button on the front of the socket.
There are new versions that can report back their status, I haven't got any of those at the moment, but I hope to add that feature in future.
To overcome this limitation I have used two buttons. One to turn the switch on and one to turn it off. The entries for the configuration file are shown below:
## Turn Energenie Socket on
FC:A6:68:11:44:33:
name: Finish Button
url: 'http://localhost/switchon?socket=0' # Url to execute
method: get # HTTP method.
## Turn Energenie Socket off
FC:A6:67:33:44:11:
name: Right Guard Button
url: 'http://localhost/switchoff?socket=0' # Url to execute
method: get # HTTP method.
This is with pi-power installed on the same Raspberry Pi as the Amazon Dash button program. If using a different computer then that address would need to be included in the url.
This works well if you already have some of the Amazon Dash Buttons available, it's a great way of making good use of those that you may have available.
The new IoT buttons are very expensive. I expect that they will work in a similar way (although they are designed for using AWS).