Software
Other
Virtual homee-in-homee with Node-RED
- Installing and Setting up node-red-contrib-homee
- homee-in-homee
- Connecting the MQTT Interface
- Node-RED Flow Export
This is part three of our homee documentation. In the first part we looked at the HTTP Interface both homee and your INSTAR camera offers and connected them. This works with all INSTAR IP cameras. In the second tutorial we used Node-RED to connected HTTP interface on the homee side to the MQTT interface on your camera using Node-RED. Note that the INSTAR MQTT Interface only available in INSTAR Full HD camera models.
This time we want to use Node-RED to create a virtual homee that directly connects to the MQTT interface. This virtual device is then controlled by our real homee.
The complete Node-RED Flow can be downloaded at the end of this article.
Installing and Setting up node-red-contrib-homee
This sounds a lot more complicated than it is as all we need is already provided by node-red-contrib-homee. Start by installing the homee support from the Manage Palette menu:
First drag a homeeAPI
node onto your work area and add your real homee's IP address and user login. The node should say that it is connected once you saved your edit:
Now we are able to create a virtual homee by dragging using a homeeDevice
node. Click on Add new virtualHomee to configure it:
Specify a unique homee ID. You can use letters and numbers (max. 10 characters) and add a user login for the virtual device:
Now I want to add a device that allows me to switch the alarm areas on my camera on
and off
. Give it a unique Node-ID and choose the OnOffPlug profile. Then continue by clicking on Attributes:
Inside the JSON editor add the following object:
[{
"id": 100,
"node_id": 1,
"instance": 0,
"minimum": 0,
"maximum": 1,
"current_value": 0,
"target_value": 0,
"last_value": 0,
"unit": "",
"step_value": 1,
"editable": 1,
"type": 1,
"state": 1,
"last_changed": 12345555,
"changed_by": 1,
"changed_by_id": 0,
"based_on": 1,
"data": ""
}]
The attribute id
has to be unique and the node_id
is the ID that you choose for your switch in the previous step. And the type
value 1
defines your switch as a switch -> see CAAttributeType.
homee-in-homee
We are now ready to add our virtual homee to the real one on our network. For this open the device menu and click to add a new WiFi device:
Choose a homee in homee device and select Add new homee:
Type in the homee ID and login you have assigned to your virtual homee in Node-RED:
Your virtual homee should now show up. Click on Send to add it:
You can now try your switch by toggling it in the On
position:
Adding a debug node to our virtual homee shows us that we now receive a status update about our switch whenever it is toggled:
{
"attributeId":100,
"targetValue":1
}
{
"attributeId":100,
"targetValue":0
}
Connecting the MQTT Interface
Toggling Camera Functions
We now have to change this message into something useful for us. For example, we can use the targetValue
to switch the 4 alarm areas on our camera with the MQTT topic instar/local/alarm/area1/enable/raw
to instar/local/alarm/area4/enable/raw
:
The message we are looking for arrives with msg.payload.targetValue
. By setting it to msg.payload
we can directly feed it into 4 MQTT-Out Nodes to switch our 4 areas on 1
or off 0
.
Don't forget that you have to add your camera's MQTT Broker to the MQTT node.
Using a tool like MQTT.fx now shows us that those MQTT Topics get updated every time the switch is used. Every message with payload 1
will switch all 4 areas on, while a 0
deactivates them:
Adding a Status Channel
The sequence above already works great. But there is one problem with it. If we use our camera's WebUI or a smartphone app to switch the alarm areas on or off we are not receiving an update in homee. For this we have to add our camera's MQTT Status Channel as an input to our virtual homee:
As you can see in the screenshot above we are using the MQTT Topics to switch the audio on our camera on or off. Note that there are 3 audio topics that we have to switch for all 3 video streams of our camera - high resolution, medium resolution and low resolution:
instar/local/multimedia/audio/enable/high/raw
instar/local/multimedia/audio/enable/mid/raw
instar/local/multimedia/audio/enable/low/raw
To receive the current state of the audio settings on our camera we have to attach MQTT input nodes with the corresponding Status Topic to the input of our virtual homee:
instar/local/status/multimedia/audio/enable/high/raw
instar/local/status/multimedia/audio/enable/mid/raw
instar/local/status/multimedia/audio/enable/low/raw
To be able to work with this input we first have to turn it into valid JSON, by adding a JSON node. And then sort out our data with a custom function node:
msg.payload = {'id':101, 'value': Number(msg.payload.val)}
return msg;
So the value
that we receive from the MQTT Status input will be either {"val":"1"} or {"val":"0"}. We simply extract the value of val
from this payload, turn it into a number and add the ID of our virtual homee device (our previous device had the ID 100
, so now we use the id 101
for our new device).
The new device is again configured to be an on/off switch. We copy our previous homee node - only need to change the name Audio
, device ID 101
and NodeID 2
to keep them unique:
Back in the homee UI you can now go back to the menu where we added our virtual homee before. Instead of adding a new homee we now have to search for new devices. I named the new device Audio
in the previous step:
Now you can try it out - deactivating the audio in the camera webUI should now also toggle the switch in our homee device UI:
You are now able to use any of the available MQTT Topics and take control over your camera through the homee UI. And every button, switch or slider you add will be available for automation scripts.
Node-RED Flow Export
[{"id":"75393df8.e86824","type":"homeeDevice","z":"5026c83e.b368c8","virtual-homee":"","name":"Alarm_Areas","nodeId":"1","profile":"10","icon":"nodeicon_camera","attributes":"[{\"id\":100,\"node_id\":1,\"instance\":0,\"minimum\":0,\"maximum\":1,\"current_value\":0,\"target_value\":0,\"last_value\":0,\"unit\":\"\",\"step_value\":1,\"editable\":1,\"type\":1,\"state\":1,\"last_changed\":12345555,\"changed_by\":1,\"changed_by_id\":0,\"based_on\":1,\"data\":\"\"}]","x":110,"y":180,"wires":[["9fe0bb5a.f639d8"]]},{"id":"542704b9.3c440c","type":"mqtt out","z":"5026c83e.b368c8","name":"alarm/area1/enable","topic":"instar/local/alarm/area1/enable/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":475,"y":121,"wires":[]},{"id":"9fe0bb5a.f639d8","type":"change","z":"5026c83e.b368c8","name":"targetValue","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.targetValue","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":180,"wires":[["542704b9.3c440c","ef88a520.e5a8b8","b0746487.26ede8","63750b59.349f54"]]},{"id":"63750b59.349f54","type":"mqtt out","z":"5026c83e.b368c8","name":"alarm/area2/enable","topic":"instar/local/alarm/area2/enable/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":475,"y":161,"wires":[]},{"id":"ef88a520.e5a8b8","type":"mqtt out","z":"5026c83e.b368c8","name":"alarm/area3/enable","topic":"instar/local/alarm/area3/enable/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":475,"y":201,"wires":[]},{"id":"b0746487.26ede8","type":"mqtt out","z":"5026c83e.b368c8","name":"alarm/area4/enable","topic":"instar/local/alarm/area4/enable/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":475,"y":241,"wires":[]},{"id":"fd87a90.65ebe58","type":"homeeDevice","z":"5026c83e.b368c8","virtual-homee":"","name":"Audio","nodeId":"2","profile":"10","icon":"nodeicon_camera","attributes":"[{\"id\":101,\"node_id\":2,\"instance\":0,\"minimum\":0,\"maximum\":1,\"current_value\":0,\"target_value\":0,\"last_value\":0,\"unit\":\"\",\"step_value\":1,\"editable\":1,\"type\":1,\"state\":1,\"last_changed\":12345555,\"changed_by\":1,\"changed_by_id\":0,\"based_on\":1,\"data\":\"\"}]","x":716,"y":320,"wires":[["e45a2b45.bb1778"]]},{"id":"494dca42.c53fd4","type":"mqtt out","z":"5026c83e.b368c8","name":"multimedia/audio/enable/high","topic":"instar/local/multimedia/audio/enable/high/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":664,"y":376,"wires":[]},{"id":"e45a2b45.bb1778","type":"change","z":"5026c83e.b368c8","name":"targetValue","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.targetValue","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":428,"y":376,"wires":[["494dca42.c53fd4","40c78b19.acda34","6342ae78.ee176"]]},{"id":"63e55ead.2a5af","type":"mqtt in","z":"5026c83e.b368c8","name":"status/multimedia/audio/enable/high","topic":"instar/local/status/multimedia/audio/enable/high","qos":"1","datatype":"auto","broker":"996228fe.ababc8","x":160,"y":320,"wires":[["2b0f2fa0.c0d32"]]},{"id":"fc32aaac.edce58","type":"function","z":"5026c83e.b368c8","name":"attributeId/targetValue","func":"msg.payload = {'id':101, 'value': Number(msg.payload.val)}\n\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":320,"wires":[["fd87a90.65ebe58"]]},{"id":"2b0f2fa0.c0d32","type":"json","z":"5026c83e.b368c8","name":"","property":"payload","action":"","pretty":false,"x":385,"y":320,"wires":[["fc32aaac.edce58"]]},{"id":"40c78b19.acda34","type":"mqtt out","z":"5026c83e.b368c8","name":"multimedia/audio/enable/mid","topic":"instar/local/multimedia/audio/enable/mid/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":654,"y":409,"wires":[]},{"id":"6342ae78.ee176","type":"mqtt out","z":"5026c83e.b368c8","name":"multimedia/audio/enable/low","topic":"instar/local/multimedia/audio/enable/low/raw","qos":"1","retain":"false","broker":"996228fe.ababc8","x":654,"y":442,"wires":[]},{"id":"296264ec.9473bc","type":"mqtt in","z":"5026c83e.b368c8","name":"status/multimedia/audio/enable/mid","topic":"instar/local/status/multimedia/audio/enable/mid","qos":"1","datatype":"auto","broker":"996228fe.ababc8","x":160,"y":353,"wires":[["2b0f2fa0.c0d32"]]},{"id":"1e5b6840.5de388","type":"mqtt in","z":"5026c83e.b368c8","name":"status/multimedia/audio/enable/low","topic":"instar/local/status/multimedia/audio/enable/low","qos":"1","datatype":"auto","broker":"996228fe.ababc8","x":160,"y":386,"wires":[["2b0f2fa0.c0d32"]]},{"id":"996228fe.ababc8","type":"mqtt-broker","z":"","name":"INSTAR MQTT","broker":"192.168.2.117","port":"1883","clientid":"iored","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]