HomeRaspberry PiCreating 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

M5Paper

Programable, ESP32 based awesome dev platform with 4.7 e-ink display by M5Stack

More HATs

client-image
client-image

Argon One M.2

Enclose Raspberry Pi 4 inside this great case with custom I/O, cooling and GPIO and M.2 SSD support

More cases on

client-image
client-image

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.

Slow Internet Warning

0
From time to time my Internet grinds to a stop. Since Raspberry Pi 4 comes with a 1Gbps Ethernet, I decided to take advantage of it and create a reporting system in NodeRED that will monitor and report when the ISP is not keeping the contractual agreements. Works with Alexa, Google Home, Android and Windows 10.

How fast Raspberry Pi NAS is?

0
Let's see how fast Raspberry Pi NAS really is?

Argon18: Argon ONE SSD modification

0
Argon One case just got better - now you can boot it from USB without ruining the design thanks to Argon 18: Argon One SSD modification

HOW TO...

How to boot Raspberry Pi 5 from NVMe M.2 SSD

0
This is how you can boot your Raspberry PI 5 from NVMe in 10 min! Check out these easy instructions

It took me 2 months to boot CM4 from NVMe

0
Complete beginners guide to Compute Module 4 boot from NVMe.

Raspberry Pi Zero 2 W vs other Zero boards

0
It's time to test the Raspberry Pi Zero 2 W against other Raspberry Pi boards from Zero series: power, WiFi, temperature and core performance

C/C++ and MicroPython SDK for Raspberry Pi Pico on Windows

0
A guide to SDK toolchain for Raspberry Pi Pico and C/C++ , Micropython on Windows.

A comprehensive guide to Grafana & InfluxDB

0
How to use Grafana and InfluxDB on Raspberry Pi for IoT sensors in home automation