On/Off Automation

Hi guys,

I just wanted to have an on/off automation for my fan in the bathroom.

It should switched on after there is no movement and switched off automatically after 2 min.

This is what I have for now (as a screenshot because I’m already in bed and on mobile it’s not possible to copy the code to clipboard):

My problem is: The fan is switched on but not switched of. Also I need to implement that if the motion is triggered again during the time the Fan is on, the fan stops and the automation timer is starting again. Any suggestions what to do?

There might be someone who can advise on why the wait_template isn’t working, but for what it’s worth in a couple of automations, I use “delay” instead. Haven’t had any problems so far.

  - delay: '00:02:00'

Incorrect usage of a wait_template.

You are using it like delay which uses a time whereas wait_template evaluates a template. Refer to the documentation.

Ah ok. I used the Frontend to put the automation together. And “Wait” made more sense. I think it was just a language thing here :slight_smile: thanks a lot. Will try to edit it in yaml and replace “waiting_template” with “delay”

Just create another automation that turns the fan off if there is motion.

You might need to change the “mode:” of the original automation from “single” tho.

I’ve rarely used any of the different modes but I think the mode needs to be “restart” in case the motion starts and then stops within the 2 minute delay period.

Try this (you will need to enter the correct entity names):

alias: Motion Example
- platform: state
  entity_id: binary_sensor.bewegung
  from: 'on'
  to: 'off'
- platform: state
  entity_id: switch.lufter
  from: 'off'
  to: 'on'
  for: '00:02:00'  
- service: "switch.turn_{{ 'on' if trigger.to_state.state == 'off' else 'off' }}"
  entity_id: switch.lufter