Unable to set entity state using automation

I’ve got a light that I can control with HASS. However if the light is switched outside of HA the state in HASS is out of synch. I’ve tried to create a webhook that will change the HASS state but it isn’t working.
Using Dev Tools >States I can set the state to any value, but ‘on’ and ‘off’ change the UI to a lamp on /off icon.
I am using curl to trigger this at the moment and getting 200 OK message returned, but I cannot see anything in the logs to hep debug.
… any pointers please.
TIA

- alias: set light state
  description: "update status on webhook message"
  trigger:
    - platform: webhook
      webhook_id: familyrm-light-star
  condition: []
  action:
    entity_id: light.familyrm_light_star
    state: "{{ trigger.json.state }}"

and the curl with response following

curl --header "Content-Type: application/json" -i   --request POST --data  '{"state":"on"}'   http://192.168.0.60:8123/api/webhook/familyrm-light-star
HTTP/1.1 200 OK
Content-Length: 0
Content-Type: application/octet-stream
Date: Fri, 19 Aug 2022 13:11:07 GMT
Server: Python/3.10 aiohttp/3.8.1
1 Like

If the state is out of sync, it sounds like an integration problem. I’d open a ticket with the integration.

It is a DIY / Rest command integration… so this automation is my attempt to keep things in synch!

Your action needs an action type… like service:, device:, event:, etc

action:
  - service: light.turn_{{ trigger.json.state }}
    target:
      entity_id: light.familyrm_light_star

There is also the option of the Hass Entities python script to just write the state.

Ok thanks will look at action types…
I like the template for selecting the service, neat!
I don’t want to trigger the service light…on/off as that will send a rest command back to set the state, so could end up in a loop.

Hopefully there is something where I can just set the state of the entity as it doesn’t have a device as a parent… learning all these hass concepts as I go so that might not be true, it could have been allocated one…will look later
Thanks!

Found some new action types eg in automations here, but nothing for state.
My entities have a platform (light) but not a device, AFAICT
The Hass Entities python script looks like it does what I want, many thanks for the steer.

Found an hour to read up on Hass Entities python script and followed the automation example - worked perfectly, thanks @Didgeridrew

1 Like