MySensors, OpenHAB, RaspberryPi, MQTT & Google Home
OpenHAB Our Smart Home primarily consists of scratch built, MySensors components and Google Home voice control.
“MySensors is an open source hardware and software community focusing on do-it-yourself home automation and Internet of Things”
I started off using a single Z-Wave binary component and USB stick, but realised it would be expensive to scale and still not do everything I wanted. MySensors components are build using cheap Arduino computers and standard electronic components. Time & effort is all that is required to piece things together.
MySensors Controller
While the MySensors MQTT Gateway acts as the primary radio mesh network facilitator, MySensors requires a controller and user interface for the items. I have chosen the open source OpenHAB for this purpose. In addition to centrally controlling the MySensors components, OpenHAB also integrates to other smart appliances.
OpenHAB is running on a Raspberry PI3. Connectivity to the MySensors Gateway is via MQTT.
As neither the Gateway nor the OpenHAB controller can allocate the Node IDs to the MySensor components, the Arduino scripts specify these statically e.g. #define MY_NODE_ID 46
I previously had OpenHAB running on an old Core 2, but get much better performance and a significantly reduced cost, running on the PI.
MQTT / Mosquitto
The Gateway and OpenHAB communicate using messages on the MQTT message broker service, Mosquitto. This service is also hosted on the Raspberry Pi, though I can inspect the communication messages from any machine with mosquitto_sub:
- mosquitto_sub -h 192.168.1.101 -t “#” -v
I can also add any messages onto the queue for testing purposes
- mosquitto_pub -h 192.168.1.101 -t “mygateway1-in/53/1/0/0/32” -m “1”
MQTTWarn
MQTTWarn was used primarily for OpenHAB to send push notifications to Android phones via Notify My Android. However, I replaced this with the OpenHAB notifications via myopenHAB when I upgraded to v2.
Supervisor
OpenHAB, MySQL, Mosquitto and MQTTWarn all run under Supervisor for auto start and restart.
iBeacon
The Pi also transmits an iBeacon which could have been configured with OwnTracks for presence detection and the automatic Garage Door. (could have, I now use OwnTracks and GPS instead)
The following setibeacon.sh is set to run on startup via cron with “@reboot /house/setibeacon.sh > /house/ibeacon.out”
sleep 1m
sudo hcitool cmd 0x08 0x0008 1E 02 01 1A 1A FF 4C 00 02 15 B9 60 AF 70 F5 C8 46 3A 2F FF 25 55 3B
47 FE 6D 00 09 00 01 C8
sudo hcitool cmd 0x08 0x000A 01
Backups
The MySQL database is backed up daily via a script running this under cron: mysqldump -uopenhab -popenhab openhab > /mnt/raspberrypi-backups/mysql/openhab.sql
OpenHAB and other configurations are backed up daily via a script running these under cron: sudo tar czf /mnt/raspberrypi-backups/configurations/mqttwarn.tar.gz /house/mqttwarn sudo tar czf /mnt/raspberrypi-backups/configurations/supervisor.tar.gz /etc/supervisor sudo tar czf /mnt/raspberrypi-backups/configurations/mosquitto.tar.gz /etc/mosquitto sudo tar czf /mnt/raspberrypi-backups/configurations/openhab.tar.gz /etc/openhab
The /mnt/ is established via…
I don’t version control the backups as CrashPlan takes care of this offsite for me.
Google Home
And finally of course, most items are controllable by voice courtesy of Google Home Mini’s around the house – ‘Hey Google, turn on the TV Backlight’