Create new entity for Hassio in Node Red?

Hi,
First of all I am not a coder but still trying to connect all my IoT to Hassio. I am having one Z-wave controller I would like to pull sensor data off and create entities in Hassio. I cannot access this data directly as there are no components provided for Home Assistant. There are on the other hand a node pallette in Node red for the unit, and I hope there is a way to feed the data from Future Home to Home Assistant as sensors/entities via Node Red?

This is an example I get from “Get State” node from Future Home in Node Red. Any help of how to set up template etc. in Node Red to create a new entity in Hassoi would be very appreciated :slight_smile:

{“payload”:{“zwaveConfigParameters”:[],“temperature”:19.2,“presence”:false,“illuminance”:77,“batteryPercentage”:100,“batteryLevel”:“ok”,“room”:8,“name”:“Motion Living room”,“model”:“FGMS_001”,“id”:1,“functionality”:null,"_links":{“stream”:{“href”:"/sites/xxxxx/devices/1/stream"},“self”:{“href”:"/sites/xxxxx/devices/1"}},"_actions":[]},"_msgid":“xxxxxxxx.bfc34”}

Something like this might work for you.

[{"id":"82bd9549.5f8058","type":"ha-api","z":"5eb3594f.d294b8","name":"","protocol":"http","method":"post","path":"/api/states/{{entity_id}}","data":"","location":"payload","locationType":"msg","responseType":"json","x":546,"y":1152,"wires":[[]]},{"id":"d9aa7829.314e78","type":"inject","z":"5eb3594f.d294b8","name":"test","topic":"","payload":"{\"zwaveConfigParameters\":[],\"temperature\":19.2,\"presence\":false,\"illuminance\":77,\"batteryPercentage\":100,\"batteryLevel\":\"ok\",\"room\":8,\"name\":\"Motion Living room\",\"model\":\"FGMS_001\",\"id\":1,\"functionality\":null,\"_links\":{\"stream\":{\"href\":\"/sites/xxxxx/devices/1/stream\"},\"self\":{\"href\":\"/sites/xxxxx/devices/1\"}},\"_actions\":[]}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":1152,"wires":[["790eda44.b92654"]]},{"id":"790eda44.b92654","type":"function","z":"5eb3594f.d294b8","name":"format entity","func":"msg.entity_id = `sensor.sh_${msg.payload.name.toLowerCase().replace(/\\s/g, \"_\").replace(/[\\W]+/g,\"\")}`;\n\nmsg.payload = {\n    data: {\n        state: msg.payload.presence ? \"on\" : \"off\",\n        attributes: {\n            friendly_name: msg.payload.name,\n            temperature: msg.payload.temperature,\n            illuminance: msg.payload.illuminance,\n            batteryPercentage: msg.payload.batteryPercentage,\n            batteryLevel: msg.payload.batteryLevel\n        }\n    }\n};\nreturn msg;","outputs":1,"noerr":0,"x":374,"y":1152,"wires":[["82bd9549.5f8058"]]}]

Thanks! That helped a lot :slight_smile:
Now my other things are connected to HA. Do you have any idea how to refresh HA with new values?
In Node-Red I trigger the flow every 60 seconds in addition to state changes of the sensors to trigger the flows. But these updates are not captured by the last HA node (API) Any idea what I’m doing wrong? :wink:

Update: HA entities are updated on state changes, but not from the interval inject nodes I have set to trigger readings from the FH sensor status.

Are they returning different formats of JSON?

All three sensors are the same, and my inject node triggers the same output from the “get sensor state” node. The “format entity” node you made will get the same input, except that the state value is not different/changed when the flow is triggered by the interval. So I think API node ignores flow inputs unless the entity state is different from last time it was triggered?

Is it an idea to create separate entities nodes in Node-Red from temperature and lux attributes to trigger when there are changes in these values to be able to read these data in HA?

Here’s a test showing that the attributes of the sensor update in HA even though the state never changes.

[{"id":"941beec9.a80e6","type":"ha-api","z":"5eb3594f.d294b8","name":"","protocol":"http","method":"post","path":"/api/states/sensor.test","data":"{\"state\":\"staythesame\",\"attributes\":{\"timestamp\":\"{{payload}}\"}}","location":"payload","locationType":"msg","responseType":"json","x":451,"y":1513,"wires":[[]]},{"id":"7037140.15793ec","type":"inject","z":"5eb3594f.d294b8","name":"test","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":307,"y":1513,"wires":[["941beec9.a80e6"]]}]

Since Dec 2019 Node Red for HA comes with an additional node called “Sensor” which allows to directly register sensors and binary sensors in HA and push states changes from Node Red to these sensors. To get this to work, you currently still need to install a websocket custom component in HA. It all works beautifully for me. See:

1 Like