Command Line Command state Tasmota

I use the command line switch for my tasmota.

Switch:
 platform: command_line
 switches:
   BEDSWITCHBACKUP:
     command_on: "/usr/bin/curl -X POST http://10.0.0.10/cm?cmnd=Power%20Toggle"
     command_off: "/usr/bin/curl -X POST http://10.0.0.10/cm?cmnd=Power%20Toggle"
     command_state: "/usr/bin/curl -X GET http://10.0.0.10/cm?cmnd=Power"
     value_template: '{{ value == "1" }}'
     friendly_name: BEDSWITCHBACKUP

The on and off commands work, but the command_state always reverts to OFF after toggling, I want it to assume the state of the switch (i.e blue for ON imageand gray for OFF image), which is either on or off, Toggle changes the state.

Using “http://10.0.0.10/cm?cmnd=Power” directly on the URL line will display { “POWER” : “ON” } of {“POWER” : “OFF”} depending on whether the switch is on or off. It seems command_state interprets them the same way.

How do I convert { “POWER” : “ON” } and {“POWER” : “OFF”} outputs into 1 and 0, which command_state in HA will understand and flag the switch appropriately, I have tried commenting out the value_template but the results are similar retaining the ON status after toggling .

This is json data, and you must tell HA how to decode it by the value_template.
See

I have never done it with a command line but

value_template: '{{value_json.POWER}}'

should work.

Edit:
I just noticed that the command_line wants the value_template to evaluate to true for on, so if that doesn’t work try

value_template: '{{value_json.POWER == "ON" }}'

Great, I used the latter json evaluation command and it worked wonders, just checked now when I got home, thanks amillion

1 Like