Using a switch with PLC

Below is a picture of my two PLCs (x410 and x310). I can read the coil (relays) states no problem but when I create a switch, how do I get the initial state? I created a switch called X410Relay1 switch, but how can I get it to keep state?

After viewing some other examples online, I am trying to get the output state of relay 1 and run it through change to mimic a toggle switch when x410_relay_switch is pressed…

change has 2 rules…

but debug1 and 2 never turn true as they remain always false. Am I missing something here?

Basically, I would like to create a switch for the UI lovelace that has the initial state of the PLC relays correct and as the state changes it updates the value as well. I have tried SNMP, XML, and now giving Modbus a try.

Your change node will make a mess, because each of the changes are done in sequence, so first you change all to one value and then you change all those that were changed and all those that had the value from the beginning back to the first value.
You need an extra step.

  • Change true to false1
  • Change false to true
  • Change false1 to false

Regarding storing your states, then either create helpers in HA, make a dynamic sensor or store them in context data in HA.
Dynamic sensor: How do I create an entity from node-red and read all updates? - #3 by WallyR
Context Data: Extract an attribute - #2 by WallyR and Working with context : Node-RED

Wally, thanks for your tip. I thought the change node changes were done similarly to an IF statement. Now it works exactly as the toggle switch I had wanted.

At this point, how do I incorporate this to an actual switch. When I run this I get an infinite loop of the relay turning on and off.

The other idea was to feed the data from the buffer parser into the current state of switch.furnace_reset and then take it from there.

No idea, if that wo is, but have a go at it and see. :slight_smile: