Home Raspberry Pi Creating Amazon Dash Yeelight remote

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.

Buy Yeelight RGB smart bulb

Buy it using these links to support NotEnoughTech.

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
"""********************
Doorbell script redone for python3
must run pip3 install scapy-python3, yeelight
must run apt-get install tpcdump
by
www.notenoughtech.com
********************"""

from scapy.all import *
import time
from yeelight import Bulb

x = 1

#Define your bulb's IP's here:

yeelight1 = Bulb("192.168.1.181")

#Execute a toggle with a 5 sec cooldown
def light_toggle(bulb):
	global x
	bulb.get_properties()
	dic = bulb.get_properties()
	dic['power']
	#print(dic["power"])
	if x == 1:			 
		x = 0
		if dic["power"] == "off":		
			#print("lamp is on")
			bulb.turn_on()
			time.sleep(5)			 
			x = 1			
		else:		
			#print("lamp is off")
			bulb.turn_off()
			time.sleep(5)			 
			x = 1			

#Scan for ARP probes from Dash Button
def arp_display(pkt):
	if pkt[ARP].op == 1:
		if pkt[ARP].hwsrc == '74:xx:xx:xx:xx:d3': #Your button MAC				
			light_toggle(yeelight1)
		#print ("Call from: " ) #unhash for testing
	#print (pkt[ARP].hwsrc) #unhash for finding MAC of your button
print(sniff(prn=arp_display, filter="arp", store=0, count=0))

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
"""********************
Doorbell script redone for python3
must run pip3 install scapy-python3, yeelight
must run apt-get install tpcdump
by
www.notenoughtech.com
********************"""

from scapy.all import *
import time
from yeelight import Bulb


x = 1

#Define your bulb's IP's here:

yeelight1 = Bulb("192.168.1.181")
yeelight2 = Bulb("192.168.1.182")
yeelight3 = Bulb("192.168.1.183")

#Execute a toggle with a 5 sec cooldown
def light_toggle(bulb):
	global x
	bulb.get_properties()
	dic = bulb.get_properties()
	dic['power']
	#print(dic["power"])
	if x == 1:			 
		x = 0
		if dic["power"] == "off":		
			#print("lamp is on")
			bulb.turn_on()
			time.sleep(5)			 
			x = 1			
		else:		
			#print("lamp is off")
			bulb.turn_off()
			time.sleep(5)			 
			x = 1			

#Scan for ARP probes from Dash Button
def arp_display(pkt):
	if pkt[ARP].op == 1:
		if pkt[ARP].hwsrc == '74:xx:xx:xx:xx:d3': #Your button MAC				
			light_toggle(yeelight1)
			light_toggle(yeelight2)
			light_toggle(yeelight3)
		#print ("Call from: " ) #unhash for testing
	#print (pkt[ARP].hwsrc) #unhash for finding MAC of your button
print(sniff(prn=arp_display, filter="arp", store=0, count=0))

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
"""********************
Doorbell script redone for python3
must run pip3 install scapy-python3, yeelight
must run apt-get install tpcdump
by
www.notenoughtech.com
********************"""

from scapy.all import *
import time
from yeelight import Bulb


x = 1

#Define your bulb's IP's here:

yeelight1 = Bulb("192.168.1.181")

#Execute a toggle with a 5 sec cooldown
def light_toggle(bulb):
	global x
	bulb.get_properties()
	dic = bulb.get_properties()
	dic['power']
	#print(dic["power"])
	if x == 1:			 
		x = 0
		if dic["power"] == "off":		
			#print("lamp is on")
			bulb.turn_on()
			time.sleep(5)			 
			x = 1			
		else:		
			#print("lamp is off")
			bulb.turn_off()
			time.sleep(5)			 
			x = 1			

#Scan for ARP probes from Dash Button
def arp_display(pkt):
	if pkt[ARP].op == 1:
		if pkt[ARP].hwsrc == '74:xx:xx:xx:xx:d3': #Your button MAC1				
			light_toggle(yeelight1)
		if pkt[ARP].hwsrc == '74:xx:xx:xx:xx:d3': #Your button MAC2	
			light_toggle(yeelight1)
		if pkt[ARP].hwsrc == '74:xx:xx:xx:xx:d3': #Your button MAC3	
			light_toggle(yeelight1)
		#print ("Call from: " ) #unhash for testing
	#print (pkt[ARP].hwsrc) #unhash for finding MAC of your button
print(sniff(prn=arp_display, filter="arp", store=0, count=0))

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.

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

SATA HAT

Add an SSD to Raspberry Pi 4 and turn it into a super-cooled NAS drive.

More HATs

Argon One

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO

More cases on

Best Raspberry Pi Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

Raspberry Pi NAS: (NAS-pi) Modding like a boss #part2

0
Plex and RAID1 NAS drive build log

MagPi – auto-downloader

0
Grab each edition of Mag Pi as soon as possible!

HOW TO...

How to boot Raspberry Pi 4 from USB

0
How to set up and boot Raspberry Pi 4 from USB drive - headless guide.

Raspberry Pi Zero, Raspberry Pi 3A+ WiFi without keyboard or cables

0
Getting Raspberry Pi boards connected in seconds

Everything you need to start using JSON

0
It's JSON not Jason, just saying!

How to use Join App in NodeRED

0
The day finally comes where Join app is almost everywhere!

Driving LCD with Arduino and Raspberry Pi

0
Displaying things on an LCD screen is as easy as going through a cup of jellybeans while writing this tutorial!