Value Template 'if not'

I’m trying to have a check a state wether it’s not a value. Pretty hard to manage.

The code should trigger on the group.alarmgroup not being ‘not_home’ for ten minutes. When this occurs I would like to have the thermostat up a notch.

    trigger:
    - platform: state
      entity_id: group.alarmgroup
      to: 'home'
      for:
        minutes: 10
  condition:
    - condition: template
      value_template: "{% is_state('alarm_control_panel.ha_alarm','disarmed') %}"
  action:
    - service: climate.set_temperature
      data:
        entity_id: climate.badkamer, climate.kleedkamerthermostaat_heating_1
        temperature: 15
        operation_mode: Heat
    - service: climate.set_temperature
      data:
        entity_id: climate_woonkamer
        temperature: 20
        operation_mode: Heat
    - service: climate.set_temperature
      data:
        entity_id: climate_gang
        temperature: 17
        operation_mode: Heat

Maybe I’m not understanding the question, but. what are the available states of group.alarmgroup?

Replacing the ‘to: home’ with ‘to: away’ or ‘to: not_home’ should do the trick.

Using the appropriate state away/not_home would trigger when the group is not home for 10 minutes.

{% if not is_state …

1 Like

It breaks:

Error in log

2018-01-25 17:41:49 ERROR (Thread-2) [homeassistant.util.yaml] while parsing a block mapping
  in "/home/homeassistant/.homeassistant/automations/autoclimate.yaml", line 96, column 7
expected <block end>, but found '<scalar>'

Code:

value_template: '{{ if not is_state('alarm_control_panel.ha_alarm','armed_home')}}'

Double quotes around the value_template, not single.

value_template: "{{ if not is_state('alarm_control_panel.ha_alarm','armed_home')}}"

Your single quotes inside will conflict with single on the outside. So you need either double inside and single outside or double outside and single inside. I usually do the latter.

3 Likes

Hi Petro,

this has always been a mistery to me. I feel enlightened in a way.

Is there a manual on these syntax rules, I cannot find anything particularly helpful.

Thx!

Still breaks:

Error Log:

2018-01-25 18:02:04 ERROR (MainThread) [homeassistant.config] Invalid config for [automation]: invalid template (TemplateSyntaxError: expected token 'end of print stat$
not a valid value for dictionary value @ data['condition'][0]['condition']. Got None
required key not provided @ data['condition'][0]['entity_id']. Got None. (See /home/homeassistant/.homeassistant/configuration.yaml, line 379). Please check the docs a$

Code:

 value_template: "{{ if not is_state('alarm_control_panel.ha_alarm','armed_home')}}"

It’s just a nuance of coding. Your string will always be a string that is inside quotes. So if you use the same quote for a string inside a string, the code doesn’t know that:

“I said “hello”” would parse as a string “I said” and “” with hello between it that is interpreted as a object or funcition.

remove the if:

value_template: “{{ not is_state(‘alarm_control_panel.ha_alarm’,‘armed_home’)}}”

2 Likes

It seems, that does the trick!
Thx!

Yeah, you either need to add true / else false to the template, or remove the if. My post was more of a general pointer than the answer, sorry :+1:

1 Like