blueprint: name: Bathroom Fan Manager description: > Turns fan on with bathroom lights (after optional delay), keeps it on while any light is on, and turns it off after all lights are off and a timeout. domain: automation input: fan: name: Fan Entity selector: entity: domain: fan lights: name: Bathroom Light Entities selector: entity: domain: light multiple: true delay_before_fan_on: name: Delay Before Turning Fan On description: Time to wait after any light turns on before turning on the fan. default: 0 selector: number: min: 0 max: 300 unit_of_measurement: seconds time_fan_stays_on_after_lights_off: name: Time Fan Stays On After All Lights Are Off description: Time to keep the fan running after all lights are off. default: 300 selector: number: min: 0 max: 3600 unit_of_measurement: seconds mode: restart trigger: - platform: state entity_id: !input lights to: - "on" - "off" variables: fan_entity: !input fan lights: !input lights action: - choose: - conditions: - condition: template value_template: > {{ expand(lights) | selectattr('state', 'eq', 'on') | list | count > 0 }} sequence: - delay: seconds: !input delay_before_fan_on - service: fan.turn_on target: entity_id: "{{ fan_entity }}" - conditions: - condition: template value_template: > {{ expand(lights) | selectattr('state', 'eq', 'on') | list | count == 0 }} sequence: - delay: seconds: !input time_fan_stays_on_after_lights_off - condition: template value_template: > {{ expand(lights) | selectattr('state', 'eq', 'on') | list | count == 0 }} - service: fan.turn_off target: entity_id: "{{ fan_entity }}"