I currently have a motion script to turn on a light in my bathroom when motion is detected and goes off after 4 minutes. I would like to keep it on though all the time motion is detected and then turn off 4 minutes after the last motion detected. Is that possible?
This is my current script’s:
bathroom_motion.yaml
` # This automation detects movement from my sensor and turn’s on my under bath light’s if the luminace is below 10.
alias: “Turn on Under Bath Lights with Motion”
trigger:
platform: state
entity_id: binary_sensor.aeotec_zw100_multisensor_6_sensor_12
state: ‘on’
condition:
To help you a bit more, my complete config: kitchen_lights.yaml:
alias: 001 - Turn on kitchen lights when there is movement
trigger:
- platform: state
entity_id: binary_sensor.fibaro_system_fgms001_motion_sensor_sensor_14
to: 'on'
condition:
condition: and
conditions:
- condition: numeric_state
entity_id: sensor.fibaro_system_fgms001_motion_sensor_luminance_14
below: 25
- condition: state
entity_id: input_boolean.motion_actief
state: 'on'
action:
service: homeassistant.turn_on
entity_id: script.timed_lamp
sensors.yaml:
timed_lamp:
alias: "Turn on lamp and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off
- service: light.turn_on
data:
entity_id: light.keuken
brightness: 125
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: "Turn off keukenverlichting na 2 min. geen beweging"
sequence:
- delay:
minutes: 2
- service: light.turn_off
data:
entity_id: light.keuken
This should work i guess. Although i have some issues with the light turning off when i am in the kitchen. But i think it is due to a parameter of my Fibaro sensor, have to look at it when i have some more time.
P.S. For syntax highlighting large blocks of code, type 3 backticks and then yaml, paste your code and close with three backticks, like this:
‘’‘yaml
blablablacodeblabla
‘’’
For a single word or line just use one backtick in front and at the end like this: ‘fakecode123’.
@Tyfoon I just have a trigger for on and a timer for off and it works for me. After the 4 mins is up since last detection on the sensor side and it switches to off, the lights go out. Gen 5 aeotech Z wave multisensor - timer settings for sensor are from OZWCP. I copied it the automations from here somewhere - or maybe the cookbooks.
Unfortunately not, and as my gf got annoyed of it, i made the light ‘dumb’ again with a button she has to press herself. I’m not sure what went wrong, as it turned on by the sensor fine. But the ‘keep on during motion’ part wasn’t working good.
My automation code all under automation.yaml and point from configuration.yaml with !include automation.yaml:
## AUTOMATION ##
### Turn on recording when group.family is "not_home" ###
- alias: Turn on iSpy when family is not home
trigger:
- platform: state
entity_id: group.family
from: 'home'
to: 'not home'
action:
service: homeassistant.turn_on
entity_id: script.recording
recording:
alias: "Turn on recording and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
data:
entity_id: script.timer_off
- service: switch.recording_living_room
data:
entity_id: switch.recording_living_room
# Set new timer
- service: script.turn_on
data:
entity_id: script.timer_off
timer_off:
alias: "Turn off recording after 5 minutes"
sequence:
- delay:
minutes: 5
- service: switch.recording_living_room_off
data:
entity_id: switch.recording_living_room
A few questions:
-its no currently working and I believe its because I need a separate file with “timer_off.yaml” + “recording.yaml” + “tun_on”?
-my actual goal is to use the variables “home” and “not_home” as the trigger? but I have to get it to record before I mess with this part…any advise?
Your second bit of code needs to be split as it has both 1 automation and 2 scripts. So your automation.yaml file should look like this:
## AUTOMATION ##
### Turn on recording when group.family is "not_home" ###
- alias: Turn on iSpy when family is not home
trigger:
- platform: state
entity_id: group.family
from: 'home'
to: 'not_home'
action:
service: script.turn_on
entity_id: script.recording
And your scripts.yaml file (don’t forget to include it in configuration.yaml) should look like this:
recording:
alias: "Turn on recording and set timer"
sequence:
# Cancel ev. old timers
- service: script.turn_off
entity_id: script.timer_off
- service: switch.turn_on
entity_id: switch.recording_living_room
# Set new timer
- service: script.turn_on
entity_id: script.timer_off
timer_off:
alias: "Turn off recording after 5 minutes"
sequence:
- delay:
minutes: 5
- service: switch.turn_off
entity_id: switch.recording_living_room
Turn off light after 4 minutes the last motion detected. Is’t possible in Automation Editor also. Do i create condition type > time ? (Hassbian 0.60.0)