Automation of fan based on two humidity sensors does not run

Hello,

I would like to start a fan, if humidy in one room is higher than values of normal room humidy in other areas.

It works nice, when I only trigger by value comp. (see below), but checking comparison of sensors every minutes does not work.

Should compare every minute, but nothing happens …

- alias: 'Turn fan on'
  trigger:
  - platform: time_pattern
    minutes: "/1"
  condition:
    condition: and
    conditions:
      - condition: template
        value_template: '{{ ( sensor.humidity_hwr3 ) > ( sensor.humindity1esp ) }}'
  action:
    service: switch.turn_on
    entity_id: switch.fan_dg

Following work fine:

- alias: 'Turn fan on'
  trigger:
    platform: numeric_state
    entity_id: sensor.humidity_hwr3
    above: 50
  action:
    service: switch.turn_on
    entity_id: switch.fan_dg

Update - seems I get also a error logs every minute:

Error during template condition: UndefinedError: ‘sensor’ is undefined

Your non working automation doesn’t do anything at all, you just added the sensor name in the template, but you need to get the state of the sensor, with states(...). Also conditions are and by default and you anyway have obly one condition, so your and condition is unnecessary.


- alias: 'Turn fan on'
  trigger:
  - platform: time_pattern
    minutes: "/1"
  condition:
    - condition: template
      value_template: "{{ states('sensor.humidity_hwr3') | float > states('sensor.humindity1esp') | float }}"
  action:
    service: switch.turn_on
    entity_id: switch.fan_dg

Edit:
It would be better to trigger only whrn the condition is true and not every minute:


- alias: 'Turn fan on'
  trigger:
    platform:  template
    value_template: "{{ states('sensor.humidity_hwr3') | float > states('sensor.humindity1esp') | float }}"
  action:
    service: switch.turn_on
    entity_id: switch.fan_dg

Your value template is wrong . Also it would be best to compare trigger the automation only when the sensor value changes. please try this

alias: New Automation
description: ''
mode: single
trigger:
  - platform: state
    entity_id: sensor.humindity1esp
  - platform: state
    entity_id: sensor.humidity_hwr3
condition:
  - condition: template
    value_template: "{{ states('sensor.humidity_hwr3') | float > states('sensor.humindity1esp') | float }}"
action:
    service: switch.turn_on
    entity_id: switch.fan_dg

Hallo,

works very well! Thanks a lot!