Problem in automation: value_template: comparisson don´t work

Hey there,
i´am trying my first automation in HA.
A fan should be controlled depending on the absolute humidity.
I would like to compare two sensor values, but this does not work.
Anyone know what I did wrong?
Here is the complete code.
(I used the Automation Editor.)

alias: Ventilator_Auto
description: Steuerung Garagenventilator
trigger:
  - platform: state
    entity_id:
      - sensor.absolute_luftfeuchte_aussen
      - sensor.absolute_luftfeuchte_garage
      - input_number.garageventilatorabsfeuchteschwellwert
      - timer.garageventilatorlaufzeitintervall
      - timer.garageventilatorpausenintervall
      - switch.ventilator
condition: []
action:
  - if:
      - condition: state
        state: "on"
        entity_id: input_boolean.garageventilatordauerluften
    then:
      - type: turn_on
        device_id: 163377eb8ab786af0d7fdde5097a026f
        entity_id: switch.ventilator
        domain: switch
      - service: timer.cancel
        data: {}
        target:
          entity_id:
            - timer.garageventilatorlaufzeitintervall
            - timer.garageventilatorpausenintervall
    else:
      - if:
          - condition: template
            value_template: >-
              "{{states('sensor.absolute_luftfeuchte_aussen')| float >
              states('sensor.absolute_luftfeuchte_garage')| float}}"
          - condition: state
            entity_id: input_boolean.garageventilatordauerluften
            state: "off"
        then:
          - type: turn_off
            device_id: 163377eb8ab786af0d7fdde5097a026f
            entity_id: switch.ventilator
            domain: switch
          - service: timer.cancel
            data: {}
            target:
              entity_id:
                - timer.garageventilatorlaufzeitintervall
                - timer.garageventilatorpausenintervall
        else:
          - if:
              - condition: template
                value_template: >-
                  "{{ states('sensor.absolute_luftfeuchte_aussen') | float <=
                  (states('sensor.absolute_luftfeuchte_garage') | float +
                  states('input_number.garageventilatorabsfeuchteschwellwert') |
                  float) }}"                 
              - condition: state
                entity_id: timer.garageventilatorlaufzeitintervall
                state: idle
              - condition: state
                entity_id: timer.garageventilatorpausenintervall
                state: idle
            then:
              - type: turn_on
                device_id: 163377eb8ab786af0d7fdde5097a026f
                entity_id: switch.ventilator
                domain: switch
              - service: timer.start
                data: {}
                target:
                  entity_id: timer.garageventilatorlaufzeitintervall
              - type: turn_off
                device_id: 163377eb8ab786af0d7fdde5097a026f
                entity_id: switch.ventilator
                domain: switch
              - service: timer.start
                data: {}
                target:
                  entity_id: timer.garageventilatorpausenintervall
            else:
              - if:
                  - condition: state
                    entity_id: timer.garageventilatorlaufzeitintervall
                    state: idle
                  - condition: state
                    entity_id: timer.garageventilatorpausenintervall
                    state: idle
                then:
                  - type: turn_off
                    device_id: 163377eb8ab786af0d7fdde5097a026f
                    entity_id: switch.ventilator
                    domain: switch
mode: single

The problematic areas are:

      - if:
          - condition: template
            value_template: >-
              "{{states('sensor.absolute_luftfeuchte_aussen')| float >
              states('sensor.absolute_luftfeuchte_garage')| float}}"

and

          - if:
              - condition: template
                value_template: >-
                  "{{ states('sensor.absolute_luftfeuchte_aussen') | float <=
                  (states('sensor.absolute_luftfeuchte_garage') | float +
                  states('input_number.garageventilatorabsfeuchteschwellwert') |
                  float) }}"

You need to assign defaults for your float filters…

      - if:
        - condition: template
          value_template: >-
            {{ states('sensor.absolute_luftfeuchte_aussen')| float(0) >
            states('sensor.absolute_luftfeuchte_garage')| float(0) }}
      - if:
        - condition: template
          value_template: >
            {{ states('sensor.absolute_luftfeuchte_aussen') | float(0)
            <= states('sensor.absolute_luftfeuchte_garage') | float(0) + 
            states('input_number.garageventilatorabsfeuchteschwellwert') | float(0) }}

Thanks, the problem is solved. The main reason, however, was the quotation marks.

..."{{...

But I still have another problem:

then:
              - type: turn_on
                device_id: 163377eb8ab786af0d7fdde5097a026f
                entity_id: switch.ventilator
                domain: switch
              - service: timer.start
                data: {}
                target:
                  entity_id: timer.garageventilatorlaufzeitintervall
              - condition: state
                entity_id: input_boolean.luftungspause_erledigt
                state: "on"

In the last entry, I don’t want to query the status. I want to set it to a new value.
The entity is boolean - a helper switch that can be on or off.
But I don’t know the syntax to set the value…

If I understand what you are asking correctly, you need to call the input_boolean.turn_on service.

then:
  - type: turn_on
    device_id: 163377eb8ab786af0d7fdde5097a026f
    entity_id: switch.ventilator
    domain: switch
  - service: timer.start
    data: {}
    target:
      entity_id: timer.garageventilatorlaufzeitintervall
  - service: input_boolean.turn_on
    target:
      entity_id: input_boolean.luftungspause_erledigt

You´re right and my automation works. Thanks!!

1 Like