I have a small room with just a shower, toilet, and a trashcan. The sink and vanity are outside of this room. It’s a private room inside the master bedroom, so shutting the door to pee is for squares. The light and fan are on the same switch. This room gets humid after a shower and takes a while to dehumidify. Sometimes I just pop in to toss something into the trash and don’t want the light/fan on. With contact sensors, a humidity sensor, and a motion sensor at my disposal, this is the ridiculous automation I have written so that neither I nor my partner should have to hit the light switch, and the cats cannot turn the light on:
alias: ⚙️💡💧Bathroom Light/Fan - NEW/EXPERIMENTAL
description: "Turn on only if the door is closed or the toilet lid is opened. Turn off when unoccupied, unless it's too humid compared to the adjacent room."
trigger:
- platform: state
entity_id:
- binary_sensor.bathroom_door
to: "off"
id: occupied
- platform: state
entity_id:
- binary_sensor.toilet_lid
to: "on"
id: occupied
- platform: state
entity_id:
- binary_sensor.4_in_1_motion_sensor_motion_detection
to: "off"
id: unoccupied
enabled: true
- platform: template
id: humidity_clear
value_template: >-
{{ states('sensor.4_in_1_motion_sensor_humidity') | float <=
states('sensor.mr_blue_sky_humidity') | float + 2}}
- platform: state
entity_id:
- binary_sensor.bathroom_door
to: "on"
id: unoccupied
- platform: state
entity_id:
- binary_sensor.toilet_lid
to: "off"
id: unoccupied
condition: []
action:
- choose:
- conditions:
- condition: trigger
id:
- occupied
- condition: time
before: "22:30:00"
after: "07:00:00"
sequence:
- service: light.turn_on
data: {}
target:
entity_id: light.red_series_dimmer_bathroom
- conditions:
- condition: trigger
id:
- unoccupied
- condition: state
entity_id: binary_sensor.bathroom_door
state: "on"
- condition: state
entity_id: binary_sensor.toilet_lid
state: "off"
- condition: state
entity_id: binary_sensor.4_in_1_motion_sensor_motion_detection
state: "off"
sequence:
- if:
- condition: template
value_template: >-
{{ states('sensor.4_in_1_motion_sensor_humidity') | float <=
states('sensor.mr_blue_sky_humidity') | float + 2}}
alias: Bathroom humidity <= Bedroom humidity + 2
then:
- service: light.turn_off
data: {}
target:
entity_id: light.red_series_dimmer_bathroom
else:
- delay:
hours: 0
minutes: 30
seconds: 0
milliseconds: 0
- if:
- condition: state
entity_id: binary_sensor.bathroom_door
state: "on"
- condition: state
entity_id: binary_sensor.toilet_lid
state: "off"
then:
- service: light.turn_off
data: {}
target:
entity_id: light.red_series_dimmer_bathroom
- conditions:
- condition: trigger
id: humidity_clear
- condition: state
state: "off"
entity_id: binary_sensor.4_in_1_motion_sensor_motion_detection
- condition: state
entity_id: binary_sensor.bathroom_door
state: "on"
- condition: state
entity_id: binary_sensor.toilet_lid
state: "off"
sequence:
- service: light.turn_off
data: {}
target:
entity_id: light.red_series_dimmer_bathroom
mode: single
This works, as far as I can tell. It just seems like bad code. I miss NodeRed. Anyway, please critique it. I’m open to suggestions to either simplify my yaml just so that it’s neater, or if there’s simpler logic I could be using that would simplify everything.