Help needed for changing Device states via external Python program

So I have a Python program running externally for a voice assistant that I’m programming. And I’m able to get my device states via the Rest API. But when I tried to set a device state via the post method, it got set in the home assistant web interface, but quickly updated itself back to the current state of the device. So the device doesn’t receive a switch “on” command, but rather just the state on the server gets changed.
Am I missing something, or is there a python library to control devices?

Info:
I am trying to switch a Zigbee device via Zigbee2MQTT
The Python program is not running on the same device as the home assistant server.

Any help is greatly appreciated

Setting device state via the api does not control the device. You need to call the service that controls it. Ie.

/api/services/switch/turn_on

If switch or

/api/services/light/turn_on

If a light etc.

With payload of

{
    "entity_id": "light.Ceiling"
}
1 Like