On last weeks update our hero started detecting emotions like a charm,Now I had a confusion on what to post this week
While cleaning our work space found a mysterious white box!
With no clue what it was and a curiosity to know went forward and opened it.
Surprise!
A brand new Yeelight Color bulb, had no clue why it was here, or when it was purchased, but I replaced my wall lamp with this one and started playing and I found a cool feature called the LAN control.
After going through their developer page there was a spark!
Initially I planned to use Addressable LED strips to make a Mood light. But found this to be a great replacement over the LED Strip, Its bright and fill the room with color, exactly something I wanted.
So after a little bit of research found an easier way to access it from the Rpi itself via Wifi using a simple shell script!
Adding a few more lines of code to emotion.py from the previous post, it worked in an amazing way
if emo == 'a' : os.system('./light.sh color Teal') os.system('./light.sh brightness 20') os.system('omxplayer Anger.mp4') os.system('killall omxplayer.bin') if emo == 'j' : os.system('./light.sh color Yellow') os.system('./light.sh brightness 20') os.system('omxplayer Joy.mp4') os.system('killall omxplayer.bin') if emo == 's' : os.system('./light.sh color Lime') os.system('./light.sh brightness 20') os.system('omxplayer Sorrow.mp4') os.system('killall omxplayer.bin')
Having some issues with our Github repo, should be fixed shortly for now here are the two scripts one to configure the yeelight and another to control it.
configure.sh
echo "Configuration started" ip=$(arp -n | tail -n+2 | awk '{print $1","$3}' | grep -i ",34:ce" | awk -F, '{print $1}' | head -n 1) bulbs=$(echo $ip | awk '{print NF}') echo "$bulbs device(s) detected with MAC address match" echo "Checking if port 55443 is open" x=1 # Only pick the first IP for now - if multiple bulbs exist, use awk to cycle through candidate_ip=$(echo $ip | awk '{print $1}') verified_ip=$(netcat -zvw1 $candidate_ip 55443 2>&1 | grep "succeeded" | awk '{print $3}') echo $verified_ip > ip.list echo "$verified_ip added to ip.list" echo "Configuration completed"
light.sh
command=$1 [ -f ip.list ] && ip=`cat ip.list` || echo "Please run configure-light.sh first if you haven't run it before in this netwo$ case $command in "on") printf "{\"id\":1,\"method\":\"set_power\",\"params\":[\"on\",\"smooth\",500]}\r\n" | nc -w1 $ip 55443 ;; "off") printf "{\"id\":1,\"method\":\"set_power\",\"params\":[\"off\",\"smooth\",500]}\r\n" | nc -w1 $ip 55443 ;; "color") color_hex=$(grep -i $2 colors | awk -F, '{print $2}') color_int=$(printf '%d' $color_hex)
I looked angrily onto the camera and here's a sneak peak
Cheers,
Top Comments