Skip to content

Instantly share code, notes, and snippets.

@dudo
Last active January 22, 2026 03:44
Show Gist options
  • Select an option

  • Save dudo/23126f898cc3da115d005d1d095ac201 to your computer and use it in GitHub Desktop.

Select an option

Save dudo/23126f898cc3da115d005d1d095ac201 to your computer and use it in GitHub Desktop.
blueprint:
name: Bathroom Fan Auto On/Off
description: >
Turns on a fan when humidity is high or a light turns on, and also auto-turns
off the fan after a delay even if it was turned on manually.
domain: automation
input:
fan_entity:
name: Fan (switch or fan entity)
selector:
entity:
domain:
- switch
- fan
humidity_sensor:
name: Humidity sensor
selector:
entity:
domain: sensor
device_class: humidity
humidity_above:
name: Humidity threshold (above)
default: 66
selector:
number:
min: 30
max: 100
step: 1
unit_of_measurement: "%"
humidity_for:
name: Humidity must be above threshold for
default:
minutes: 1
selector:
duration:
light_entity:
name: Light to trigger on
selector:
entity:
domain: light
run_for:
name: Keep fan on for
default:
minutes: 15
selector:
duration:
mode: restart
trigger:
- id: humidity_high
platform: numeric_state
entity_id: !input humidity_sensor
above: !input humidity_above
for: !input humidity_for
- id: light_on
platform: state
entity_id: !input light_entity
from: "off"
to: "on"
- id: fan_on
platform: state
entity_id: !input fan_entity
to: "on"
action:
# If humidity or light triggered, ensure the fan is ON.
- choose:
- conditions:
- condition: template
value_template: "{{ trigger.id in ['humidity_high', 'light_on'] }}"
sequence:
- service: homeassistant.turn_on
target:
entity_id: !input fan_entity
# Smart shutdown logic:
# - If light is off: wait run_for -> off
# - If light is on: wait until it turns off -> wait run_for -> off
- choose:
- conditions:
- condition: state
entity_id: !input light_entity
state: "on"
sequence:
- wait_for_trigger:
- platform: state
entity_id: !input light_entity
to: "off"
- delay: !input run_for
default:
- delay: !input run_for
- service: homeassistant.turn_off
target:
entity_id: !input fan_entity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment