I’ve been playing with home bridge for a while as a way to bring to life the various IOT hacks i’ve been fooling around with. I’ve found it so far to be an excellent project and have since set it up to work with my Cubieboard, Particle IO, Yeelights, and Belkin devices. Other than just being able to turn on/off these items in software and SIRI, i also wanted to be able to automatically setup the room lights to match the daylight colour temperature outdoors as the day progresses. Otherwise, whats the purpose of getting lights that can support 16 million colours?
This has proven to be challenging as the default rules and controls in HomeKit does not allow for the ability to tell and feed back time into a ruleset. As i also wanted to use my Belkin Wemo to switch on the lights, the ruleset capabilities in the Home app just wasn’t good enough. After a fair bit testing and searching i finally found a way to configure my Yeelights via the command line. The purpose of doing that was to then make use of a homebridge plugin to trigger the script to turn on the lights. The script determines the time of the day and applies that setup to the lights as it comes on.
The solution to do this was really a combination of
– Homebridge-script
– yeelight-shell-scripts
The work process was essentially as follows:-
Homekit-Homebridge-shell script-date detection-color temperature-yeelights
The above process works great short of a small bug in the homebridge-script plugin where the flag file for the switch state wasn’t being read right by the plugin. You just have to change the getState function to the one below. Continue to make sure that your scripts drops a state file such that if it exist, the switch is ON and vice versa.
scriptAccessory.prototype.getState = function(callback) { var accessory = this; var command = accessory['stateCommand']; var fs = require('fs'); var flagFile = (fs.existsSync(this.fileState)) ? 1 : 0; accessory.log('State of ' + accessory.name + ' is: ' + flagFile) callback(null, flagFile); }
A few other quirks in home bridge that i found was that you have to give the systems time to sync back to the iCloud. If you expect things to work instantly, especially the automation rules, you’d be very disappointed. After a change, always give it 5-10 minutes for the changes to settle before setting up the accessory in an automation. I have found this to add heaps in stability and user expectation.
The page i used as a reference to setup home bridge is https://github.com/nfarina/homebridge/wiki/Running-HomeBridge-on-a-Raspberry-Pi
Other references
https://github.com/hphde/yeelight-shell-scripts
https://github.com/xxcombat/homebridge-script