YAML works as trigger but not as condition

Hello there,

I have trigger like this in some automation:

platform: numeric_state
entity_id: sensor.outdoor_temperature
value_template: '{{ state.state|float(0) + 3 }}'
below: sensor.oczyszczacz_powietrza_biuro_temperature
for:
  hours: 0
  minutes: 1
  seconds: 0

It works. However I tried to add same YAML as condition but it gives me such error:

Message malformed: Unexpected value for condition: 'None'. Expected and, device, not, numeric_state, or, state, sun, template, time, trigger, zone @ data['condition'][4]

So how do I achieve the same as in trigger but in condition?

Why not turn it into a full template condition?

What do you mean by that?

Something like this:

  - condition: template
    value_template: >-
      {{ (states('sensor.outdoor_temperature') | float(0) + 3) <
      (states('sensor.oczyszczacz_powietrza_biuro_temperatur') | float(0)) }}

You can do the same for triggers, if you put all the conditions in the trigger you do not even need the conditions.

1 Like

Will try that in a moment. However I need some checks both in trigger and condition because there are many factors to be checked. This automation turns on vent when: door are closed, window is open, outside temp is lower then inside temp, room temp is above desired temp (set by helper). Each of this condition have to be met and also each of those action has to trigger automation :slight_smile:

The point is, if you make one big trigger template, it only fires if the template is true. So it is both the trigger and the conditions in one. It will make one huge trigger template, but no duplication required. HA checks which entities affect the template trigger.

Doesnā€™t work.

Message malformed: Expected a dictionary @ data['condition'][4]

Have you checked the template in developer? I couldnā€™t myself as I do not have your sensors. Also check the indenting. Is this indeed condition nr 4? And is there something around it that could be wrong?

Developer says something like this:

UndefinedError: 'sensor' is undefined

Also in you YAML thereā€™s ā€œ(ā€ before first states but not before second states. I changed to this but still doesnā€™t work:

- condition: template
  value_template: >-
    {{ states(sensor.outdoor_temperature) | float(0) + 3 <
    states(sensor.oczyszczacz_powietrza_biuro_temperatura) | float(0) }}

The braces where there for the + 3. Not sure they are needed. But I forgot the quotes around the sensor names. Iā€™ll fix it above.

OK - now it became real wierd. Template in developer says itā€™s OK! Even shown TRUE or FALSE depending if condition is met. However when putted into automation it says:

Expected a dictionary

Maybe post the whole automation, I expect it is something in the vincinity.

Sure thing:

alias: >-
  Biuro vent [ON] <- Biuro temp > Outside temp OR Biuro temp [>BIURO SET TEMP]
  OR Biuro temp [CHANGED] OR Biuro door [CLOSED] OR Biuro window [OPEN] WHILE
  [ALL IN ABOVE] AND Heat pump {SUMMER MODE}
description: ''
trigger:
  - type: opened
    platform: device
    device_id: 19423dcee9267d9acf28689aea88d335
    entity_id: binary_sensor.office_window_ias_zone
    domain: binary_sensor
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - type: not_opened
    platform: device
    device_id: c2a6fbed0f1a870a4f152f3cf58f450c
    entity_id: binary_sensor.office_door_ias_zone
    domain: binary_sensor
  - platform: numeric_state
    entity_id: sensor.outdoor_temperature
    value_template: '{{ state.state|float(0) + 3 }}'
    below: sensor.oczyszczacz_powietrza_biuro_temperature
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: numeric_state
    entity_id: sensor.oczyszczacz_powietrza_biuro_temperature
    above: input_number.office_room_temp_during_summer
  - platform: numeric_state
    entity_id: input_number.office_room_temp_during_summer
    below: sensor.oczyszczacz_powietrza_biuro_temperature
condition:
  - type: is_open
    condition: device
    device_id: 19423dcee9267d9acf28689aea88d335
    entity_id: binary_sensor.office_window_ias_zone
    domain: binary_sensor
  - type: is_not_open
    condition: device
    device_id: c2a6fbed0f1a870a4f152f3cf58f450c
    entity_id: binary_sensor.office_door_ias_zone
    domain: binary_sensor
  - condition: numeric_state
    entity_id: sensor.oczyszczacz_powietrza_biuro_temperature
    above: input_number.office_room_temp_during_summer
  - condition: state
    entity_id: sensor.hc1_summer_winter_switchmode
    state: 'off'
  - condition: template
    value_template: >-
      {{ (states('sensor.outdoor_temperature') | float(0) + 3) <
      (states('sensor.oczyszczacz_powietrza_biuro_temperatura') | float(0)) }}
action:
  - type: turn_on
    device_id: beeb9968f1d162081bb300b40bdccd32
    entity_id: switch.tasmota_office_stereo
    domain: switch
mode: single

Missed an ā€˜eā€™ on temperature. just fyi. But yes the full automation would be helpful.

I know you missed it. I fixed it. Anyway donā€™t be confused by tasmota_office_stereo. Itā€™s actually a vent just this switch was used for something else before.

I simply forgot to change entities names and now Iā€™m too lazy to do it :wink:

is it temperatura or temperature? I donā€™t get an errors with your automation saving.

Mayby try to copy the entire script in another editor, abort the editor, open it again and paste the code again. Iā€™ve seen instances that the editor got,stuck in a broken editing session. or arentā€™t you editing in the GUI?

I do edit in GUI (for most part). I just switched to YAML to post automation here. Anyway I will try your suggestion.

I still got these error after pasting whole script into new automation. Strange thing is however that it ALLOWS me to save this automation without any error. It throwns error only when I click test here:

image