Command_line switch remember state


Does anybody have a clue on how to get a command_line switch to remember it’s state after for example a HA reboot?

platform: command_line switches: poolbelysning: command_on: echo "PL1" | nc -u -w1 23 command_off: echo "PL0" | nc -u -w1 23 friendly_name: poolbelysning

Here’s the switch I would like to keep the state for, even after rebooting HA.

You would need to specify a command_state.

Hey Tom,

Thank you for your reply.
I’ve been trying to, but can’t get it to work. I cannot get any UDP state, how can I update the command_state so that it reflects the switch actual status?

If you have no way of obtaining the state, then you can not reliably reflect the switch state in home assistant.

I would really appreciate if you can show me and example on how to get that working!?


I have no idea what your device is or how it works.

It’s a switch to turn on and off a device with UDP commands. I need the state to be stored. If you don’t know I would appreciate if anyone else has a clue on how to keep the state of my switch even after reboot.

Storing the state is not sufficient. What happens if the switch state changes while home assistant is offline because it is restarting?

Are you sure there is no way to interrogate the switch state?

What sort of switch is it, make & model?

The switch will not change state other then by these UDP commands. The commands turn a DMX lighting fixture on/off, and unfortunately it doesn’t send any state feedbacks.

So i managed to create a boolean which that copies the state of the switch, how can i get the switch to update according to the boolean value?