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.
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.
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.
This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
Strictly Necessary Cookies
Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.
If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.