Configuring REST command switch


I’m trying to turn on the switch via rest command,

    - platform: command_line
        seconds: 10
          command_on: "curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"amOn":"true"}}'"
          command_off: "curl -v -H "Accept: application/json" -H "Content-Type: application/json" -X PUT -d '{"DA":{"amOn":"false"}}'"
          friendly_name: 'Aircon On'

Now how do I setup the commend state and value template,

So if curl -s -k -H ‘Accept:application/json’ --digest ‘’ output


   {“result”:1,“error”:null,“id”:0,“data”:{“vid”:2,“did”:4,“device_type”:“airconditioner”,“default_name”:“Air Conditioner Settings”, “tags”:“aircon”, “is_sensor”:1, “is_actuator”:1, “is_silent”:0, “has_time_series”:0, “has_subdevice_count”:0, “has_state”:0, “gid”:“0”, “guid”:“xxx_0_2_4”, “node”:“xxx”, “meta”:{},“shortName”:"", “subDevices”:{}, “last_data”:{“DA”:{“amOn”:true,“tempTarget”:23,“mode”:1,“fanSpeed”:0,“enabledZones”:[1,1,0,0,0,0,0,0]},“timestamp”:1499413530689}}}

my command state would be curl -s -k -H ‘Accept:application/json’ --digest ‘’ ?
and what will be the value_template if status of the aircon is “DA”:{“amOn”:true , is on

Maybe try:

value_template: "{{ }}"

Thanks, that worked I think, so idea behind value template is to get the ON status from the device I assume?

The Command Line Switch will assume the state of the switch if the command_state option is not used. I.e., when you turn it on (command_on is sent) it will assume it is/stays on, and when you turn it off (command_off is sent) it will assume it is/stays off.

However, if you specify command_state, then it will send that command periodically to poll the current state of the switch. If you do not specify value_template, then it will use the returned result code of the command to determine the switch’s state – 0 means on, anything else means off. If, however, you do specify value_template, then the template will be evaluated after the command is sent, and if (after converting the result to lower case) it results in exactly the string true, the switch will be on, or off for anything else. The template I suggested interprets the response from the command as JSON, then extracts the specified element, which appears to be a boolean, and when converted to a string will become true or false, meaning on or off.