Node-red and a plc(S7) connector btw. create an entity (switch) with a state

Hi there,

I got the PLC from node red and the home assistant integration. I have a problem or better I’m confused. For example I have an Output on my SPS to a light, Name it output A1.0. The output in Node-red has the name light_1.

I get the status from the PLC if it is turned on via physical switch in my house. everything is fine. But now I want to have an entity in my Lovelace UI to toggle the light on and off and to get the current state.

I thought it works like this:


But I do not get the current state in the Lovelace UI. I can turn it on and off but no state is available. What I’m doing wrong?

When you pass a msg object with the property enable set to either true or false the state of the switch in HA should change. The switch entity should be your current state of the light.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/entity.html#msg-enable

you mean something like this:


This does not work

I’m assuming the left node outputs true/false to msg.payload depending on the state of the light.

[{"id":"7dd19c1ae6b3a809","type":"inject","z":"91a80f99.6180e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":226,"y":2176,"wires":[["c73eb5f6f4b2702d"]]},{"id":"8d79b218c1d33eed","type":"debug","z":"91a80f99.6180e","name":"on","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":754,"y":2144,"wires":[]},{"id":"6f625894a0e58ada","type":"ha-entity","z":"91a80f99.6180e","name":"","server":"","version":2,"debugenabled":false,"outputs":2,"entityType":"switch","config":[{"property":"name","value":""},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""},{"property":"state_class","value":""},{"property":"last_reset","value":""}],"state":"payload","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"msg","inputOverride":"allow","outputOnStateChange":true,"outputPayload":"$entity().state = \"on\" ? true : false","outputPayloadType":"jsonata","x":582,"y":2144,"wires":[["8d79b218c1d33eed"],["f2e1bda048b7e95f"]]},{"id":"03d092d287a898a3","type":"inject","z":"91a80f99.6180e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":228,"y":2144,"wires":[["c73eb5f6f4b2702d"]]},{"id":"c73eb5f6f4b2702d","type":"change","z":"91a80f99.6180e","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"enabled","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":394,"y":2144,"wires":[["6f625894a0e58ada"]]},{"id":"f2e1bda048b7e95f","type":"debug","z":"91a80f99.6180e","name":"off","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":754,"y":2192,"wires":[]}]

edit: the change node should be moving payload to enable not enabled

nearly working:

if I press the physical button, the Lovelace ui now shows the correct state. fine so far. But when I now press the button in the Lovelace ui, to toggle the state it does just disabling the lamp, not enabling

What type of import is far-right expecting to set the light state?

Put debug nodes on each output of the entity node. Are you seeing what you expect to see?

Sorry for the delayed reply. On the far right I expect true and false.

In general it is a light. On the left side “licht_eg_ez_tisch” it is a read mechanism for the SPS (S7) and on the right side “licht_eg_ez_tisch” it is a write mechanism for the SPS. The light could be set from a physical button anywhere in the house or from home assistant Lovelace UI via the entity “Licht EG EZ TISCH”

I tried several things with the output but did not come behind what’s the problem. I will send you the log

@Kermit got it to work with the debug node. Thanks a lot for your help

For all the other souls which struggle with their SPS. It should look like this:

The input from the sps:

The move:

The entity:

the output to the spa: