Use HA REST API to get device state in command_line sensor

Hi all,

I have a HA install both my house and a off-site location. I am trying to integrate a switch on the off-site location into my main instance.

I first thought of using Automation Webhooks to handle the switching, but then the state would be incorrect of the device was switched by a Automation on the off-site location. I also can’t use the ‘Remote Homeassistant’ HACS add-on because only the main instance can reach the off-site location, not the other way arround.

Therefore, I am trying to set up a command_line sensor to both switch and retrieve the state from the remote instance. I already succeeded in switching the device, but I can’t get the command_state and value_template to work.

This is the output when calling the API with curl:

{"entity_id":"switch.switch","state":"off","attributes":{"assumed_state":true,"friendly_name":"Switch"},"last_changed":"2023-08-20T11:12:39.298462+00:00","last_updated":"2023-08-20T11:12:39.298462+00:00","context":{"id":"01H89AB8C10QFN2SWGQR1F6AEE","parent_id":null,"user_id":"98d0f6866b944938a3c106997494a2cf"}}

Can someone help me getting the ‘on’ and ‘off’ state workign with the command_state and value_template so I can view the actual status?