Automation about value comparision doesn't work. Need help

I want to get notified when the absolute humidity outside is lower than inside in the basement, so I know when it makes sense to open the windows. Therefore, I found this solution and implemented it:

Unfortunatelly, it occurs the follwoing error message:
“Invalid config for [automation]: [minutes] is an invalid option for [automation]. Check: automation->minutes. (See /config/configuration.yaml, line 9).”

But I can’t find the error in my following code:

- id: 'keller_lueften_an'
  alias: Keller lüften an
  initial_state: 'off'
  trigger:
    - platform: time
      minutes: '/1'
      seconds: 01
  condition:
    - condition: template
      value_template: "{{ ( states.sensor.aussen_humidity_abs.state  )  + 2 < ( states.sensor.keller_humidity_abs.state ) }}"
  action:
   - service: input_boolean.turn_on
     entity_id: input_boolean.keller_luften
```

It’s not entirely clear when you actually want to trigger the automation. If every minute then you want the time_pattern platform, not the time platform. See the examples by following those links.

A more efficient way to do this would be to trigger on the state change rather than polling with a time pattern trigger. You can do this with a numeric_state trigger or a template trigger. The advantage of the template trigger is that it will trigger on change of state of either sensor, where as the numeric_state trigger only monitors one.

You are also not using the recommended method of retrieving your sensor state in the template see the warning here.

Also you need to convert your states to numbers (they are stored as strings).

Finally addition is performed before the comparison is made so you can remove some extraneous parentheses.

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  trigger:
  - platform: template
    value_template: "{{ states('sensor.aussen_humidity_abs')|float + 2 < states('sensor.keller_humidity_abs')|float }}"
  action:
   - service: switch.turn_on
      entity_id:
        - switch.lufter_keller

The addition of an extra trigger and condition ensures this automation runs if the template is already true when home assistant is started.

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  trigger:
  - platform: homeassistant
    event: start
  - platform: template
    value_template: "{{ states('sensor.aussen_humidity_abs')|float + 2 < states('sensor.keller_humidity_abs')|float }}"
  condition:
  - condition: template
    value_template: "{{ states('sensor.aussen_humidity_abs')|float + 2 < states('sensor.keller_humidity_abs')|float }}"
  action:
   - service: switch.turn_on
      entity_id:
        - switch.lufter_keller
1 Like

hello @tom_l,

thank you very much for you support! Quite a bunch of information, but I get it running.
Yes, the idea was to check the values every minute, but state change trigger is also ok.

One more question: Does this automation turn off the switch again when the condition does not apply any more, or do I habe to make a second automation for truning it off again? Is there a way to combine it with an if/else phrase?

Best Michael

No. There’s no switch.turn_off service call in the automation’s action.

If you want a single automation that turns the switch on/off then you need to do more than just add an if/else. The automation’s trigger and condition must be modified because now it is designed to detect only when the switch must be turned on and not when it must be turned off (I’ll let tom_I explain how to do it … or just create a separate automation dedicated to turning off the switch).

ok thanks, I’ll just make a second automation to turn it off.

If you’re interested, you can experiment with the following single automation:

- id: lueftersteuerung_keller_taupunktabhängig
  alias: Lüftersteuerung Keller Taupunktabängig
  trigger:
  - platform: homeassistant
    event: start
  - platform: state
    entity_id: 
    - sensor.aussen_humidity_abs
    - sensor.keller_humidity_abs
  action:
  - variables:
      aussen: "{{ states('sensor.aussen_humidity_abs')|float + 2 }}"
      keller: "{{ states('sensor.keller_humidity_abs')|float }}"
      entity: 'switch.lufter_keller'
  - choose:
    - conditions: "{{ aussen < keller and is_state(entity, 'off' }}"
      sequence:
      - service: switch.turn_on
        target:
          entity_id: '{{ entity }}'
    - conditions: "{{ aussen >= keller and is_state(entity, 'on' }}"
      sequence:
      - service: switch.turn_off
        target:
          entity_id: '{{ entity }}'
3 Likes

Thank you very much 123Taras, your approach worked out!

1 Like