Call service when condition is False

Hi,

I want to call a service when my condition is false.
I am trying to make 1 button that execute a script. The script need to turn on a group of lights. When i press the same button when the lights are on I want them to turn off. But they only need to turn of when they are the color temp set in the script. When they aren’t that color temp i want to change them to it using the script.

{% if is_state_attr(‘light.lamp_1’, ‘color_temp’, 439) %}
true
{% else %}
false
{% endif%}

I want to execute the script when false.

How can i do that?

if not is_state...

With if not is_state
I only can set a true or false. But i want to call a service when my lamp is on and an other service when it is not in the same script (Or within the same button)

like so
{% if is_state_attr(‘light.lamp_1’, ‘color_temp’, 439) %}
true (script 1)
{% else %}
false (script 2)
{% endif%}

service_template: >
   {% if is_state_attr(‘light.lamp_1’, ‘color_temp’, 439) %}
    script.one
    {% else %}
     script.two
   {% endif%}
'1516129802980':
  alias: Woonkamer State
  sequence:
  - condition: template
    value_template: >
      {% if is_state_attr('light.hanglamp_1', 'color_temp', 439) %}
        script.woonkameruit
        {% else %}
         script.relax
      {% endif%}

Is not working for me. I don’t know what i am doing wrong. i firstly did it like this but it does nothing.

Possibly because I’ve clearly put service_template in my example, but you’ve put a condition: template in instead?

'1516129802980':
  alias: Woonkamer State
  sequence:
    - service_template: >
      {% if is_state_attr('light.hanglamp_1', 'color_temp', 439) %}
        script.woonkameruit
        {% else %}
         script.relax
      {% endif%}

O wow completely missed that…

Thanks it works!

1 Like