Turn light off no motion for 3 minutes

Hey, just wondering if anyone can give me some advice on an automation I’m doing. I have set up an automation with my hue sensor and hue bulb using the Lux entity so the bulb wont come on during the day where there is enough light already. The automation works perfectly, I am now trying to get it so when the light does turn on when there isn’t enough light Ie night or dull days the light will turn off after 3 minutes of no motion but I’m struggling with the no motion side of things, do I need to make a new automation for that or can I just use another trigger? This is my config file so far.
Thanks in advance.

- id: '1561406598184'
  alias: Motion Light Sensor On
  trigger:
  - entity_id: binary_sensor.dining_room_sensor_1_motion
    platform: state
    to: 'on'
  condition:
  - below: '70'
    condition: numeric_state
    entity_id: sensor.dining_room_sensor_1_light_level
  action:
  - alias: ''
    data:
      entity_id: light.dining_room
    service: homeassistant.turn_on
  - delay: '3'
  - data:
      entity_id: light.dining_room
    service: homeassistant.turn_off
- id: '1561408367485'
  alias: Motion Light Sensor Off
  trigger:
  - entity_id: binary_sensor.dining_room_sensor_1_motion
    platform: state
    to: 'off'
  condition:
  - above: '80'
    condition: numeric_state
    entity_id: sensor.dining_room_sensor_1_light_level
  action:
  - data:
      entity_id: light.dining_room
    service: homeassistant.turn_off

adding a delay : ‘3’ doesn’t seem to work…

Take a look at the examples Especially this one;

- alias: Turn off kitchen light 10 minutes after last movement
  trigger:
    platform: state
    entity_id: sensor.motion_sensor
    to: 'off'
    for:
      minutes: 10
  action:
    service: homeassistant.turn_off
    entity_id: light.kitchen_light

delays have to be defined in military time

for: '00:03:00'

or even like this

     platform: state
     to: 'off'
     for: 
       minutes: 3

Thank you @sjee, yeah I have seen that, so I need to create another automation? So I will have three automations 1 to only turn the light on when its dark, 2 for the light not to turn on at all when there is enough light, and a 3rd to say turn off light after 3 minutes?

thanks again

Thanks @Underknowledge does that also count for the example above? where it says for: 10 does it have to be 00:10:00?

Thanks

To keep things simple I would do it like that. Also easier to trouble shoot when things do not work the way you expect.

You can also specify a delay like this;

- delay:
    # Supports milliseconds, seconds, minutes, hours, days
    minutes: 1

Check the docks :wink:


both works - you just have to understand what you doing
for an delay I would always type
-delay: '00:00:00' that’s easy to remember
1 Like

That’s great @sjee @Underknowledge. I will create the 3rd automation when I get home, and see how I get on.
So it should look like this, with the 3 automation?

- id: '1561406598184'
  alias: Motion Light Sensor On
  trigger:
  - entity_id: binary_sensor.dining_room_sensor_1_motion
    platform: state
    to: 'on'
  condition:
  - below: '70'
    condition: numeric_state
    entity_id: sensor.dining_room_sensor_1_light_level
  action:
  - alias: ''
    data:
      entity_id: light.dining_room
    service: homeassistant.turn_on
- id: '1561408367485'
  alias: Motion Light Sensor Off
  trigger:
  - entity_id: binary_sensor.dining_room_sensor_1_motion
    platform: state
    to: 'off'
  condition:
  - above: '80'
    condition: numeric_state
    entity_id: sensor.dining_room_sensor_1_light_level
  action:
  - data:
      entity_id: light.dining_room
    service: homeassistant.turn_off
- id: '1561453677647'
  alias: LIghts Off After 3 Minutes
  trigger:
  - entity_id: binary_sensor.dining_room_sensor_1_motion
    for: 00:03:00
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - data:
      entity_id: light.dining_room
    service: homeassistant.turn_off

do you use the automation editor or an text editor?
but yea - looks good so far - youre only missing 2 ' around the for:

When you write the automations you can make them a little nicer to look at
like this

- id: '1561453677647'
  alias: LIghts Off After 3 Minutes
  trigger:
  - platform: state
    entity_id: binary_sensor.dining_room_sensor_1_motion
    from: 'on'
    to: 'off'
    for: 00:03:00
  condition: []
  action:
  - entity_id: light.dining_room
    service: light.turn_off

you see what I mean?

    to: 'off'
    for: '00:03:00' 

@Underknowledge I have been using the automation editor for now, to understand better how it all works… but starting to use just the text editor now.

Ahhhh that’s a good spot that, that’s using the automation editor that, that hasn’t put in the ’ ’ either side of the 00:03:00. or do you mean the for needs them?

yea I see what you mean with that other example… sorry I’m still learning :slight_smile: but really starting to get my head around it all now.

The automation editor is like training wheels.
I’m not 100% shure if it is realy really needed - but its a good habit

if you write it like this:

for: '00:10:00'

it’s necessary.

if you write it like this:

for:
  minutes: 10

it isn’t.

“minutes:” is expecting a number

for: is expecting a string. because the string includes the special character “:” that yaml uses in other areas (like after for:) to denote a key:value pair then it will get confused trying to figure out how to interpret that unless you explicitly declare it as a string by wrapping it in quotation marks.

It’s the same with ‘on’ & ‘off’. those require the quotation marks too since yaml treats a regular on or off as a boolean. And when you write “to:” then it is expecting a string not a boolean so you have to tell it you’re giving it a string by wrapping the ‘on’ in quotation marks.

And the sooner you can get away from using the automation editor the better off you will be.

2 Likes

Hi,
If the app turn on the light then the motion is not registered, then the light will not be turning off. How do you include that condition to turn off the light when google assistant turn on the light? Thanks

I actually dont - I use an time trigger as failover

initial_state: 'on'
trigger:
  - platform: state
    entity_id: binary_sensor.motion_bad
    to: 'off'
    for:
      minutes: "{{ states('input_number.bad_movement')|int }}"
  - platform: state
    entity_id: light.bad_ambiance
    to: 'on'
    for:
      minutes: 45
condition:
  - condition: state
    entity_id: sensor.bad_mode_state
    state: 'Bad normal'

Thanks for the reply. I am new to home assistant so I don’t know much to yet. Can you explain the above code? Where do you get these names define? x.motion_bad, x.bad_movement, x.bad_ambiance, x.bad_mode_state? Thank in advance.

Shure

Motion_bad is the actual motion sensor
Bath movement is an input_number (I can set the timeout dynamic) bad ambiance is the light to control and bath mode States is an template sensor. ( When you’re in the shower or taking a bath you don’t like to sit in the dark

The only intersting part for you atm is the second trigger for the automation.
When the light xy is on for x minutes run this Automation

and milliseconds?