In previous posts I played with Raspberry Pi’s, MQTT clients and X10 devices.
In this post I will bind these all together providing a way to control your lights by publishing messages to an MQTT broker.
Nice!
Step 1 – Prepare your Raspberry Pi
In a previous post I wireless installed a clean version of Raspbian on a Raspbian Pi 3.
Step 2 – Install MQTT Client
In a previous post I installed a MQTT client on a Raspbian Pi 3.
Step 3 – Install Heyu
In a previous post I installed Heyu on a Raspbian Pi 3.
Step 4 – Create a bash script to tie it all together
nano send_x10_messages.sh
#!/bin/bash mqttserverip='192.168.XXX.XXX' mqtttopic='home/lights/livingroom' messageOn='On' messageOff='Off' mosquitto_sub -h $mqttserverip -t $mqtttopic | while read line do if [[ $line == $messageOn ]]; then heyu on B4 fi if [[ $line == $messageOff ]]; then heyu off B4 fi echo $line done
sudo chmod a=r+w+x send_x10_messages.sh
Step 5 – Auto run on startup
To run this script on startup we edit our rc.local file
sudo nano /etc/rc.local
Add the line:
sudo /home/pi/send_x10_messages.sh&
Now reboot and your good to go
Hello
What should I change to the script if I have multiple lights?
LikeLike
I believe the “B4” part/s.
B = x10 house code.
4 = x10 device #.
LikeLike