Turn Fan off when light off, but wait until humidity is lower than threshold

Hello together,

I am trying to get an automation for our bathroom working. The scene ist the following:

I measure the humidity in the bathroom. When somebody turns on the light, the fan turns on.

The fan should turn off after 5 minutes when the light is turned off, but only when the humidity is under 65%. The automation should wait more than the 5 minutes if the humidity is still over 65%.

Ive tried some things in the automation GUI, but I wasn’t successful yet.

Here’s how my automation in yaml looks like right now., maybe someone can help me. I’m new to HA and don’t know the Syntax so good yet, sorry.

Channel 1 is the light, channel 2 is the Fan.

alias: Badezimmer Lüfter ausschalten
description: ''
trigger:
  - platform: device
    type: turned_off
    device_id: 2c629dead3dc5f73597d92a6fbe700cc
    entity_id: switch.lampe_und_lufter_badezimmer_channel_1
    domain: switch
    for:
      hours: 0
      minutes: 5
      seconds: 0
      milliseconds: 0
condition: []
action:
  - type: turn_off
    device_id: 2c629dead3dc5f73597d92a6fbe700cc
    entity_id: switch.lampe_und_lufter_badezimmer_channel_2
    domain: switch
mode: restart

You didn’t mention the name of the sensor that reports humidity so I invented one (change the name to whatever you have).

alias: Badezimmer Lüfter ausschalten
description: ''
trigger:
  - platform: state
    target:
      entity_id: switch.lampe_und_lufter_badezimmer_channel_1
    to: 'off'
    for: '00:05:00'
condition: []
action:
  - wait_template: "{{ states('sensor.feuchtigkeit') | float < 65 }}"
    timeout: '00:05:00'
  - service: switch.turn_off
    target:
      entity_id: switch.lampe_und_lufter_badezimmer_channel_2
mode: restart

How it works

  • The automation triggers when the light switch is turned off for a minimum of 5 minutes.
  • It waits for the humidity sensor to report a value less than 65. However, it doesn’t wait forever, only a maximum of 5 minutes.
  • After the humidity falls below 65 or 5 minutes have elapsed (whichever comes first), the fan switch is turned off.

Documentation for wait_template

2 Likes

Thanks mate,

OK this is one way I thought to do. Looks like the easiest way to do it.

I just tried to wait for the humidity without a timeout, but waiting for a max amount of time is also OK for me.

Thanks.

One question: What happens if I set continue_on_timeout to true? My understanding is, if it’s set to false and the timeout triggers instead of the value, it stops executing the automation.

Edit: NVM, continue is always set to true by default in yaml, the GUI is not

Glad to hear it works for you.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information refer to guideline 21 in the FAQ.