I’m fairly new to HA and happy that I have all my devices working. But I ran into a problem which I cannot solve. I’m using a contact sensor for my toilet. So, open door, light on, but when closing the door, the light obviously turns off. So somebody hinted about a boolean toggle, which should keep the light on while the toilet is occupied and turn off the light when the door is opened and closed again.
So how do I use this toggle and where to call it in my automation? Thanks for your help!
I know, you should be done in 10 minutes, but you know kids and Youtube, right?
And I’d like to practice with this so I can use it in other automations. Still in learning mode.
Be careful on using only the door sensor to define if someome are inside or not, as one can open the door and then close it without entering the room or even use the room with the doors opened, and then when he/she leaves the light will say on until the door is opened again, inverting the desired behaviour and increasing your electricity bill.
With that said, you can do what you say in a much simpler way by using only the “door opening” to trigger a light.toggle, don’t use the “door closed”. It will be super simple, but the light will turn off right away when you open the door to leave (which might not be desired), so perhaps you can add a couple of seconds as delay before turning off the lights.
description: ""
mode: single
trigger:
- platform: state
entity_id:
- binary_sensor.bathroom_door
from: "off"
to: "on"
condition: []
action:
- if:
- condition: state
entity_id: light.bathroom_ceiling_lights
state: "on"
then:
- wait_for_trigger:
- platform: state
entity_id:
- binary_sensor.bathroom_door
from: "on"
to: "off"
timeout:
hours: 0
minutes: 0
seconds: 5
milliseconds: 0
- service: light.toggle
data: {}
target:
entity_id: light.bathroom_ceiling_lights
But if you really want to use a bool toggle, you can create one under Settings > Devices & Services > Helpers (tab), then in your automation you select to call a service and use the service input_boolean.toggle.
actually it’s completely wrong approach (you figure it ou later on your own).
The opening or closing a toiled door cannot be used to decide someone is in or out.
It works for small rooms you cannot be closed in (small storages, pantry etc).
Toilets, if you expect automatic lights turn on/off must be supported with motion sensors (better if they recognize the presence rather than movement).
This advise is valid for all automations you will think of:
don’t automate for sake of automation alone
automation has to help you, without adding unwanted corner cases
Personally because I have no motion sensor, I left toggling to power switch. the only think I added is timer the light turns off after reasonable amount of some time)
I fully agree with @maxym, a door sensor only is not ideal for a room where you stay inside. Your automation will work, but you will easily have unexpected behaviour (or the reasons I mentioned before) and you will get frustrated…
Think about adding a motion sensor to your set. If a motion happens after the door is closed, you have someone inside, so the light should be on until the door opens, regardless is no more movement is detected.
If you only ever have the door closed when occupied you could invert the logic (door open->light off, door closed → light on).
otherwise there is no way you can be sure to keep everything in synch with just the door sensor as already noted.
you could add a motion sensor inside to add another data point to keep the lights on when there is movement. But even then if you are still longer than the time setting the lights might still turn off but if the time setting is reasonable then that is less likely an issue than just relying on the door sensor only.
I use this automation:
Door opens, light on
Door closes within 10 seconds, light stays on
Door opens, light stays on
Door closes, light off
or
Door opens, light on
Door close after 10 seconds, light off.
- alias: WC licht
description: 'Licht aan als de deur open gaat, licht uit als de deur sluit'
mode: restart
trigger:
- platform: state
entity_id: binary_sensor.toiletdeur_contact
to: # a null 'to' only triggers on all state changes, not attribute changes
- platform: time
at: input_datetime.delayed_off
action:
- variables:
light: light.wc_lamp
is_day: '{{ is_state("sun.sun", "above_horizon") or is_state("switch.gang_1", "on") }}'
- choose:
# Turn off the light when 25 minutes have passed, or the door is closed after 10 seconds
- conditions:
- or:
- '{{ trigger.platform == "time" }}'
- and:
- '{{ trigger.to_state.state == "off" }}'
- condition: state
entity_id: light.wc_lamp
state: 'on'
for: 10
sequence:
- service: light.turn_off
target:
entity_id: '{{ light }}'
# Turn on the light when the door is opened and the light is off
- conditions:
- '{{ trigger.to_state.state == "on" }}'
- '{{ is_state(light, "off") }}'
sequence:
- service: light.turn_on
data:
brightness_pct: '{{ 70 if is_day else 10 }}'
target:
entity_id: '{{ light }}'
# Set the timer for 25 minutes after the door is closed and the light is on
default:
- condition:
- '{{ trigger.to_state.state == "off" }}'
- '{{ is_state(light, "on") }}'
- service: input_datetime.set_datetime
target:
entity_id: input_datetime.delayed_off
data:
timestamp: '{{ (now() + timedelta(minutes=25)) | as_timestamp }}'
I have been trying to program this for a while but couldn’t this exact solution. I have a Kasa motion sensor with dimmer and aqara door sensors. The light always turns off after no motion is detected even when the door is closed.
I imported the blueprint but my bathroom door sensor and light dropdowns, both were empty. So I went to edit the code in YAML and just pasted the entity ID on each manually. FYI, I have a Kasa Motion Sensor with Dimmer installed and the Aqara door sensors. Almost all the time, the bathroom door is open and obviously only close when in use.
I am not sure if you have used Kasa products or sensors before. But on the Kasa app, I have the default smart control setting on it for now, which comes preprogrammed. Which are 12 am to 12 am and triggers light on when motion & dark and when no motion is detected for 15 seconds, it turns off the light.
Giving you details, so you can help! Cause My light still turns off after 15 seconds of closing the door and no motion.
You have to disable the automation on Kasa app, so your lights will only be controlled by Home Assistant. If you have two automations it could be conflicting.