Light switch toggles not resetting correctly, using python_script.set_state

hello, I have a lighting server which controls about 50 lights.
This server sends and receives updates to HASS by cURL.

So for example if I use a wall switch to turn on the kitchen light, the lighting server will update HASS, so the toggle I created in HASS will change to “on”. This system is “optimistic” the tech has no inbuilt state reporting. So if I have a number of lights on, then turning them off one by one is fine, because HASS will receive each update individually.

The problem is that with each update HASS receives, the switch within HASS will also activate and send cURL back to the lighting server.

If I only used the HASS toggles to turn lights on and off it would be fine. But using wall switches, HASS will get the update and ALSO send the same command back to the lighting server.

So I decided to find a way to update the state in HASS without performing the action, ie send cURL.
python_script.set_state has helped me do that.

Here is the problem, even though I change the state of a toggle, the toggle will become “locked” and I have to cycle through a series of on-off actions to get it working again.

Any idea how I can fix this? thanks

My rookie mistake - the correct way to feedback state would be using command_state.
I am using command line switches to define my toggle switches.

What I should have been focusing on is defining where hass can get an update on each individual light’s current state.

I was able to create a http resource where hass can get the current state - as per the guidelines, 0 for on and 1 for off. But still no luck.

The command_on and command_off work, but it seems it can’t retrieve the state correctly.
My light switches look like this:

platform: command_line
        friendly_name: "Home office wall lights"
        command_on: /usr/bin/curl -X POST ''
        command_off: /usr/bin/curl -X POST ''
        command_state: /usr/bin/curl -X POST ''
        value_template: '{{ value == "1" }}'

I tried without value_template, then tried with value_template but still no luck.
It should be mentioned that, after turning the light on, the toggle stays “stuck” in the on position, even though the light is successfully turned off.

Can anyone suggest any ideas?
Is there a way to test the changes I make without editing the yaml and having to restart hass every time?

Sorry to bump the thread, really can’t get the syntax right for command_state.
Is there a way I can view what (if any) data is coming through?
I tried:

command_state: /usr/bin/curl -X POST ''
command_state: /usr/bin/curl POST ''
command_state: curl ''

Any ideas or suggestions would be appreciated!
thanks people :grin: