The above Node-RED Flow, turns on my 'Outside Office' light when the powder room is turned on, and turns them both off after 10 seconds. Not practical but a good sample of the power behind Node-RED. Link to exported flow for above.
This is a release of the ability to integrate Homebridge Accessories into Node-RED so that you can start flows from Homebridge accessory events and control your existing homebridge accessories. ( To create accessories in HomeKit, please use node-red-contrib-homekit-bridged. )
Four different node types are available, the first node hb event
listens for changes to an accessory (ie on/off) and sends a message into Node-Red containing the updated accessory status. The second node hb resume
holds the state of an accessory and supports creating a state resume function. The third node hb status
allows you to poll an accessory for status. The forth node hb control
allows you to control a homebridge accessory. Each node is tied to an individual Home App Tile/Service of an accessory (ie on/off and brightness).
Payload from a dimmable lightbulb.
{ "On":true, "Brightness":100 }
Please keep in mind that this integration only works with devices supported/exposed with HomeBridge Plugins. This does not have visibility to Native HomeKit devices. ( Similar to my homebridge-alexa plugin. )
For the hb event
node, the ability of a Accessory to generate events in Real Time is dependent on how the plugin was architected and the actual device. Some are very good at generating events in real time, and others only generate events when the Home App is opened to the accessory. YMMV.
With a plugin, you can see if it supports Real Time events, by opening the Home App, and looking at an accessory. Then trigger a local event outside of homebridge/homekit. If the accessory updates in real time, then it support Real Events. ( An example of a local event can be turning on a Smart Light Switch, by the local switch. Another example would be using the vendor app to control an accessory.)
hb state
to hb resume
to make the use case for the node more self-explanatory. If you had used the hb state
node in your existing flow, nodeRed will not start unless you manually change the node type in the flow file. To fix the issue, manually edit the flow file in your .node-red directory, and change the type reference hb-state
to hb resume
true
going to the On characteristic would turn on a light, with this version it would be be represented with a message payload of { "On":true, "Brightness":100 }
. This particular payload would turn on a light and set the brightness to 100. I made this change to enable easier intergradation with node-red-contrib-homekit-bridged.hb resume
or hb control
nodes it would output a debug message containing the valid/supported characteristics for use in the payload object.This is covered in alot of other places, so I won't cover it here.
Place your homebridge instances into "INSECURE MODE". This is same as my Homebridge Alexa plugin, and you just need to follow the Prepare homebridge for plugin instructions there.
cd ~/.node-red
npm install node-red-contrib-homebridge-automation
The accessory naming convention is:
Accessory Name and Accessory Service Type
This node generates a message every time an Accessory changes status, and generates a message containing the updated status of all the characteristics.
Message is structured like this
msg = {
name: Accessory Name,
payload: { "On":true, "Brightness":100 }
Homebridge: Homebridge instance name,
Manufacturer: Plugin Manufacturer,
Type: Homebridge device type,
_device: Unique device identifier,
_confId: node.confId,
_rawEvent: Raw event message
};
Message payload will vary depending on characteristics support by the device, this example is from a dimmable light.
Please note that multiple event messages may be received from a single device event, this is due to how homebridge controls devices and emits events.
This node can be used to create a resume previous state flow. Where you change the state of an accessory, and have it resume the previous state afterwards. I'm using this, in conjunction with Alexa to give the ability to turn on and off the lights in a room, but not turn any lights that were already on. I'm also using it with the HomeKit "I'm home" automation, to turn a group of lights for a few minutes then turn off. But at the same time have any lights you already had on, stay on.
Based on the message input payload and state of the accessory the output changes.
For {"On":true}
, the node just passes the message to output. For the first {"On":false}
, the output is the state of the accessory from prior to the last turn on. For the second {"On":false}
, the out is {"On":false}
.
msg = {
payload: { "On":true, "Brightness":100 }
};
msg = {
payload: { "On":true, "Brightness":100 }
};
Message payload will vary depending on characteristics support by the device, this sample is from a dimmable light.
To find supported characteristics for a device, please send an invalid message payload to the node, and it will output the supported characteristics in the debug log.
This node allows you to poll a Homebridge accessory and collect the current status of all the characteristics.
Anything
Message is structured like this
msg = {
name: Accessory Name,
payload: { "On":true, "Brightness":100 }
Homebridge: Homebridge instance name,
Manufacturer: Plugin Manufacturer,
Type: Homebridge device type,
_device: Unique device identifier,
_confId: node.confId,
_rawEvent: Raw event message
};
Message payload will vary depending on characteristics support by the device, this sample is from a dimmable light.
This node allows you to control all the characteristics of a Homebridge accessory. The message payload needs to be a JSON object containing the values of all the characteristics you want to change. If you send the node an invalid payload, it will output all the available characteristics of the accessory in the debug tab.
The hb control node only looks at msg.payload value, and ignore's all others.
msg = {
payload: { "On":true, "Brightness":100 }
}
Message payload will vary depending on characteristics support by the device, this sample is from a dimmable light.
To find supported characteristics for a device, please send an invalid message payload to the node, and it will output the supported characteristics in the debug log.
I have started collecting flows for useful functions on the wiki.
https://github.com/NorthernMan54/node-red-contrib-homebridge-automation/wiki
DEBUG=-express*,-send*,-body-parser*,* node-red