In my bedroom I have 4 IKEA TRÅDFRI Bulps connected with one remote, and one TRÅDFRI motion sensor (HA entity: sensor.underseng_motionsensor) which is connected to gateway only but no bulps yet … and I need this motion sensor to turn on 1 of the bulps (HA entity: light.under_seng) under the following conditions:
If the bulp is already on then it should leave it as it is = do nothing!
If the bulp is off, and motion is detected it should turn it on for 2 minutes and then off again, but only between sunset minus 30 minutes and sunrise.
If possible define in the automation which color that bulp should have.
Can someone help me get this working? … I am really new to this automation stuff in HA so please bear with me.
(Running HassOS 2.12, HASS.IO Supervisor 164, HA 0.93.2)
I have now made the following automation, which should give me what I need, except for the part where I need at condition that only trigger the on and off from motion sensor if the light is not already turned on … Can someone please help me on this, I am totally clueless how to make this work.
- alias: Turn on Underseng light when there is movement
trigger:
platform: state
entity_id: sensor.underseng_motionsensor
to: 'on'
action:
service: light.turn_on
entity_id: light.under_seng
data:
transition: 1
brightness: 255
color_name: purple
- alias: Turn Underseng light 2 minutes after last movement
trigger:
platform: state
entity_id: sensor.underseng_motionsensor
to: 'off'
for:
minutes: 2
action:
service: light.turn_off
entity_id: light.under_seng
data:
transition : 5
Add a condition to the first automation requiring that the light.under_seng is off to allow the action to be executed. If it is already on then the action will not be executed.
- alias: Turn on Underseng light when there is movement
trigger:
platform: state
entity_id: sensor.underseng_motionsensor
to: 'on'
condition:
condition: state
entity_id: light.under_seng
state: 'off'
action:
service: light.turn_on
entity_id: light.under_seng
data:
transition: 1
brightness: 255
color_name: purple
Case : The bulp is already on … a person gets in front of the motion sensor … what will then happen to the “Turn Underseng light 2 minutes after last movement” when no condition on that part is set? … will it then
turn the light off after 2 min or will it let it be turned on as it should?
@LukasQ
Hmm … so you think the IKEA Motion Sensor will not work? … what about a Philips Hue motion sensor then? … I am not at home at the moment so I am not able to see if the automation is working or not, but your statement worries me.
The second automation works exactly the way you wrote it. It will always turn off the light if there is no motion detected for at least 2 minutes.
If you turn on the light and then walk out of the room, if the motion sensor detects no motion for 2 minutes, the second automation will turn off the light.
If this is not the way you want it to work, then the second automation will have to be modified.
OK, that means the second automation needs a condition that checks if the light was turned on by the motion sensor (or by someone/something else). It will turn off the light only if the light was turned on by the motion sensor, otherwise it will leave the light on.
One simple way to do this is by using an input_boolean to serve as an indicator.
I’ll likely be using something similar to this for my motion lighting implementation, but I have one question. If I walk into a room and the light is triggered by motion, and I want to stay in that room with the light on, but I am sitting without enough motion to retrigger, what would keep the light from turning off with these automations? I would assume nothing as I couldn’t turn the light on manually once it’s already triggered and on by the motion.
The answer to your question is precisely what you’ve already guessed it is: nothing will prevent it.
There are a few very sensitive occupancy detectors available, able to detect even subtle movements, but they’re usually not battery-powered (a sensitive motion sensor would be reporting frequently and drain its battery quickly).
The natural solution is to indicate to Home Assistant that it should not automatically turn off the light because you’ll do that manually. In other words, you want to temporarily disable auto-off.
This is easier said than done. How does one easily indicate auto-off should be disabled but only temporarily?
The simplest way would be to manually turn the light off and then back on. The fact it is now manually turned on is an indication to Home Assistant that the “automatic light” function should be temporarily suspended. However, the awkward aspect of this approach is that you first have to turn the light off (which was originally turned on automatically due to detected motion) before turning it back on.
I solved this dilemma for myself a while ago in HomeSeer using a virtual device with 4 settings and have just ported everything over into HA. Rather than a boolean, I used a drop down helper called XYZ Motion Control. I have one for bedroom lighting and one for fireplace lighting. The contents of the drop downs are Disabled, Enabled, Manual and Motion. If I set the drop down to Disabled, motion control of the lights is disabled which I frequently use for the bedroom lights. To override No Motion from turning the light off after motion has turned it on (i.e. while you are sitting quietly reading a book or meditating) just manually turn the light off and back on either via the physical switch, Alexa/Google or in HA, to change the helper status to Manual mode. Here are my automations:
@Stkol76@123
Im trying to do the same thing but with a door sensor. But the condition that it will only trigger if the light is off is not working, the light is turned off when I close the door even if I turn the light on manually before I opened the door.
- alias: Turn on light
trigger:
platform: state
entity_id: binary_sensor.porta_cozinha
to: 'on'
condition:
condition: state
entity_id: light.hall
state: 'off'
action:
- service: input_boolean.turn_on
entity_id: input_boolean.motion_detected
- service: light.turn_on
entity_id: light.hall
- alias: Turn off light after 1 minute
trigger:
platform: state
entity_id: binary_sensor.porta_cozinha
to: 'off'
for:
minutes: 1
condition:
condition: state
entity_id: input_boolean.motion_detected
state: 'on'
action:
- service: input_boolean.turn_off
entity_id: input_boolean.motion_detected
- service: light.turn_off
entity_id: light.hall
In the second automation, the word action is indented incorrectly. Move it two spaces to the left.
If you are using a text editor to create your automations, after making changes, execute Configuration > Server Controls > Check Configuration, if there are no errors, execute Configuration > Server Controls > Reload Automations.
I’m not sure what you are expecting it to do because, given the way the automations are written, the light will always be turned off as long as the input_boolean is on.
The input_boolean is turned on whenever the door is opened. So whenever the door is closed (for 1 minute), and the input_boolean is on (which it will be because it was turned on when the door was opened) the light is turned off. In other words, opening/closing the door turns on/off the light. It’s working exactly as its written.