Command line switch - 'value_json' is undefined

Hello.
The switch stopped working. Returns an error ‘value_json’ is undefined.

Request:
curl -X GET -u 'login:password' http://hitepro.local/rest/devices/65/

Answer:
{"id":"65","status":false}

YAML:

- platform: command_line
  switches:
    light_on_kitchen:
      command_on: >
      /usr/bin/curl -X PUT -u 'login:password' http://hitepro.local/rest/devices/65/1
      command_off: >
      /usr/bin/curl -X PUT -u 'login:password' http://hitepro.local/rest/devices/65/2
      command_state: >
      /usr/bin/curl -X GET -u 'login:password' http://hitepro.local/rest/devices/65/
      value_template: >
      {{value_json.status}}
      command_timeout: 20
      icon_template: >
        {% if  value_json.status  == true %} mdi:toggle-switch-variant
        {% else %} mdi:toggle-switch-variant-off
        {% endif %}
      friendly_name: Light on kitchen

Perhaps this is due to the lack of quotes for the status “state”: true, but I can’t affect a third-party device.
How to solve the problem?

value_template: '{{ value|regex_findall("\"status\":(\w*)}")|first == "true" }}'

or:

value_template: '{{ (value|from_json).status }}'

I think you can then use {% if bool(this.state) %} in the icon_template instead.

Thank you.
I solved the problem.

The house has 2 wi-fi. The third-party device was connected to another wi-fi network and was not available at hitepro.local.

That was the only problem.

1 Like