Creating Amazon Dash Yeelight remote

Is there anything that Amazon Dash cannot do?

When I have seen perfectly referenced API that comes with Yeelight Smart bulbs I knew it’s gonna be fun!  It took me some time to get familiar with it, but now I’m ready to share my first integration. I’m going to show you how to use Amazon Dash Yeelight remote with Raspberry Pi.

Amazon Dash Yeelight remote setup

The whole thing uses (yet again) my Amazon Dash doorbell script to intercept the ARP probe used by the dash button. The full set up is explained in that article, feel free to read more if you are interested. First, go to the Yeelight app, click on your bulb and enable the LAN control options. The light bulb needs to be enabled for this to work. Grab an IP of the bulb as well using ie Fing app.




To use Yeelight with Raspberry Pi we will need few libraries to be installed. Fortunately, someone already did all the legwork required to adopt the API to Python. First, install:

sudo apt-get install tpcdump

followed by:

pip3 install scapy-python3, yeelight

We should be ready to go!

Creating a Python3 script to control Yeelight light bulbs

The Amazon Button Remote is set to a toggle behaviour. It checks for the current state of the lightbulb, then switches it to an opposite state. It takes about 4 seconds to activate the toggle, and there is a mandatory 5 seconds cooldown forced by how Amazon Dash works. Additionally, the scrip contains a cooldown to prevent multiple ARP probes messing up your setup. Three different scenarios come to my mind.

One Amazon Dash button, one Yeelight

One Amazon Dash, One Yeelight

This is the scenario you will end up using most likely, a single button, controls a single light bulb. You can carry the remote with you, or use 3M tape to stick it to the wall switch. You could also use magnets to compromise between remote and a static use.

One Amazon Dash Button, multiple Yeelights

One Amazon Dash, multiple Yeelights

You can also toggle groups of lights this way. Bear in mind that the way script was written, it will toggle the lights only. If you have 3 lights, (ON/OFF/OFF) using this set up will cause all the lights to toggle (OFF/ON/ON). You can modify the script to create different behaviours.

Multiple Amazon Dash buttons, one Yeelight

Multiple Amazon Dash buttons, one Yeelight

You can also use multiple dash buttons to control a single light. This is great when you want to have a remote for lights and a stationary switch placed in a convenient position.

Making it permanent

I want the script to load on boot, otherwise, I have to manually start the script myself. First, let’s make sure the script is executable:

sudo chmod +x /path/to/file/file.py

Then we can add it to boot behaviour using rc.local file:

sudo nano /etc/rc.local

Add ‘sleep 10’ just above the line that executes the script, to allow flawless execution:

#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
sleep 10
pyhton3 /home/pi/Documents/amazon_dash.py &
exit 0




Conclusion

The script can be modified to allow more complex behaviour like time schedules on top of manual switching. I’m sure I will be writing more about Yeelight and Raspberry Pi in the future. I would like to thank Przemyslaw B, for sending me the Yeelight smart light bulb to play with. You can get your Yeelight using the links below:

Buy Yeelight:
BangGood: https://goo.gl/WMtA8A
Aliexpress: https://goo.gl/22i4bk

A lot of time and effort went into researching, prototyping and creating this Raspberry Pi project. All that knowledge has been nicely compressed into a few minutes long article and a video, to save your time. If you want to put a monetary value on the time I saved you – visit support me page.

SHARE