Entity - switch - button - sensor - creating in node-red

Hello, here’s a weird question. I search on all forums and internet but not finding an answer. maybe I am searching in the wrong direction or the wrong way… but what I would like to do.

So I have node-red and I can see l my entities and control them etc. But now I would like to do “the other way around”… I would like node-red to be the client for home assistant.

What do I mean. Ik would like to make e.g. a switch/sensor/light etc. in node-red to control it’s state there and/or fill output with a value (e.g. temperature or lux) and when it is, there is a corresponding device in home assistant updating accordingly. And the other way around. I can switch off the device in home assistant and node-red picks it up.

What I do not mean is to start from a home assistant perspective, thus with creating a virtual switch there and then manually add in to node-red (that works and I know how to do).

But I would like to be able to create a device in node-red and home-assistant pick it up like any other integration would…

got it :-).

Hope someone can point me in the right direction.

there is an ‘entity’ node. you need to install node-red custom integration from HACS as well and after that it creates a sensor/binary sensor or switch in home assistant.

Thank you! exactly seems what I need!

I was excited to see the custom integration that is providing for entity nodes in Node-Red and corresponding entities in Home Assistant.

I installed the custom integration and created a switch in Node-Red that I can see from Home Assistant’s Entities. I have also been able to call it via Developer Tools in Home Assistant. The status of the switch updates in Node-Red when I do this but I think I’m missing something obvious as I’m not able to turn on or off lights using this new entity. Any suggestions?


[{"id":"2f002ed7.d3e4d2","type":"ha-entity","z":"96d4130b.6677e","name":"","server":"51a30dc2.5c61a4","version":1,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":"switch.roof"},{"property":"device_class","value":""},{"property":"icon","value":"mdi:palette"},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":130,"y":760,"wires":[["2ae19147.8d814e"],["2125f2cd.8281ee"]]},{"id":"2125f2cd.8281ee","type":"api-call-service","z":"96d4130b.6677e","name":"","server":"51a30dc2.5c61a4","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.roof_lights_zha_group_0x0002","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":800,"wires":[[]]},{"id":"2ae19147.8d814e","type":"api-call-service","z":"96d4130b.6677e","name":"","server":"51a30dc2.5c61a4","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.roof_lights_zha_group_0x0002","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":720,"wires":[[]]},{"id":"51a30dc2.5c61a4","type":"server","z":"","name":"Home Assistant","addon":true}]

Hi! I had a similar issue. The HA entity node should be alone. You need to add something like an event state node that will listen to your switch and turn on or off your light.

Just connect your call service nodes to the event state output.

2 Likes

Hi, I’ve managed to get a switch working as described above which works well. I have perhaps a noob question regarding the state of the switch. My switches are controlled using modbus, which allows me to read back the status of the switches. I’m wondering how I should go about implementing this feedback of the switch states using node-red. Ideally I’d like to have the toggle buttons in home assistant reflect the true state of the switches by polling the switch registers. I can read the state of the switches in node red and can have that as a sensor entity, but how would I tie that to the switch?

As soon as the switch is created in node red it is “existing” as an entity in homeassistant and you can do whatever you want with it. Also from a node red perspective. Just think of it a “an entity” in home assistant and handle in node red like that.

Same issue on my side, I’ using an Ikea Zigbee switch to open/close a gate node in Node Red, would like to be able to do the same from Lovelace, have added a virtual switch, I can controll it, but state is not reflected if I’m trigering it from the Ikea switch. Did you find a solution for your problem?

Thanks,

1 Like

When I use virtual devices created using the HA helper as an input or trigger for a flow and I also want to trigger the flow using a physical device I use the device to trigger a call service node to set the virtual devices.

This keeps everything in sync and I can see the state and control it in Lovelace as well. Mine are usually buttons.

Thanks Stanman, can you share your code? Thanks,

Here are the pieces of the flows and a Lovelace screenshoot where I can trigger my Goodnight flow either by the Lovelace dashboard, a NFC tag or as an output from a Zigbee switch.

Screenshot from 2022-12-03 14-23-24

1 Like

I know things have changed and time has passed, but… Stanman do you still have the code example for this flow and the lovelace dashboard. I am sure we could learn alot from it.
Thanks

What part(s) are you interested in? As you stated, things change.
We moved and I do not have as many devices at the moment.
That stated, I have similar button flows as well as use a goodnight input boolean similar to my original setup.

I am not using NFC tags at the moment although I plan to add some for a few specific automations.