Comand_line switch with not working value_template

Hi!

I have the following command_line switch:

    computer_tablet_screen:
      value_template: "{{ states('variable.computer_tablet_screen') }}"
      command_on: curl http://192.168.0.141:8765/?action=screen_on
      command_off: curl http://192.168.0.141:8765/?action=screen_off

If I turn off/on the switch, everything is working good, but when the variable’s value change, the switch it is not changing… Anyone knows how can I achieve this to work?

Thank you!

What’s the state of the variable?

On/Off, depends of the tablet’s screen. If the tablet will turn off, the variable will be off. If the tablet turn on, the variable will be on.
The problem is that the switch it is not acting like the tamplate’s value is telling…

value_template will only report the state, it will not execute command_on / command_off based on the value, if that’s what you’re trying to achieve.

Exactly, value_template SHOULD report the state of what I put in the value_template, right?

So… when value_template: “{{ states(‘variable.computer_tablet_screen’) }}” is changing, the switch does not…

I can achieve all these with an automation, but I want to make it simple, from the switch itself…

If specified […] the template evaluating to true will indicate the switch is on.

Your template doesn’t evaluate to true, it evaluates to the state of “variable.computer_tablet_screen”, whatever it is.
You’re likely looking for

value_template: "{{ is_state('variable.computer_tablet_screen', 'on') }}"

or something

So… what do you say is that the template for command_line will evaluate to “true” not to “on” as well? I ask this because I have some other custom template swtiches where everything is ok, with the same code…

Edit: Still not working, even with “{{ is_state(‘variable.computer_tablet_screen’, ‘on’) }}”

Yes.

But, checking the source, it seems “value_template” is actually ignored if “command_state” is not provided, whatever it is.

So you probably want (“echo 0” is just a dummy command):

command_state: "echo 0"
value_template: "{{ is_state('variable.computer_tablet_screen', 'on') }}"

Is the state On or on? Check the exact state under Developer Tools → States

on / off , lowercase

I try to play more with the informations I got till now :slight_smile: I will test more

{{ is_state(‘variable.computer_tablet_screen’, ‘on’) }} - False

{{states(‘variable.computer_tablet_screen’)}} - off


I have even tried:

{% if is_state('variable.computer_tablet_screen', 'on') %}
true
{% elif is_state('variable.computer_tablet_screen', 'off') %}
false
{% endif %}

But not working :frowning: