I’m currently setting up some parameters for my automations, this way I don’t have to go through all my automations if I want to change the times!
So I’ve set up a couple of helps
Turn on lights if motion after X time (X time = when it gets dark, e.g.18:30pm
Don’t turn on lights if motion after X Time (X Time = when it gets light, e.g 09:00am
Turn off lights after X minutes of no motion (X Minutes = a ‘Number’ helper)
Master Switch - I’ll turn this on when I turn off the automations on my apps.
I know I could use sunrise/sunset, but this doesn’t work for me.
The light on automations (first two) work, however, I can’t get the third working.
I’m trying to turn off the ‘Hallway Light’ if there’s been no motion for ‘X Minutes’
So where I have “for 9 minutes” - I need that 9 minutes to pull from “input_boolean.lights_automation_master_lights_off_after_x_minutes”
Any idea’s?
- id: '1608050360435'
alias: '[Light Auto Off With No Motion] [Hallway] Off after X minutes without motion'
description: ''
trigger:
- type: no_motion
platform: device
device_id: 776700f719bc11eb826a9d2d697ddbce
entity_id: binary_sensor.hallway_motion_sensor_motion
domain: binary_sensor
for:
hours: 0
minutes: 9
seconds: 0
condition:
- condition: state
entity_id: input_boolean.lights_automation_master_lights_off_after_x_minutes
state: 'on'
- condition: device
type: is_on
device_id: 435f297112fe11eb86b841e1770ee5b8
entity_id: light.hallway_light
domain: light
action:
- type: turn_off
device_id: 435f297112fe11eb86b841e1770ee5b8
entity_id: light.hallway_light
domain: light
mode: single
So digging a little further, I found the logs were reporting something about float
Invalid config for [automation]: expected float for dictionary value @ data[‘for’][‘minutes’]. Got None. (See /config/configuration.yaml, line 11).
I altered the code a little and got this working.
The issue I see here, is that when the motion stops, the timer starts… So if it detects motion again, the lights will still turn off.
I need it so if the motion hasn’t been detected for X Minutes it’ll turn off the light.
- id: '1608050360435'
alias: '[Light Auto Off With No Motion] [Hallway] Off after X minutes without motion'
description: ''
trigger:
- type: no_motion
platform: device
device_id: 776700f719bc11eb826a9d2d697ddbce
entity_id: binary_sensor.hallway_motion_sensor_motion
domain: binary_sensor
for:
hours: 0
minutes: 3
seconds: 0
condition:
- condition: state
entity_id: input_boolean.lights_automation_master_lights_off_after_x_minutes
state: 'on'
- condition: device
type: is_on
device_id: 435f297112fe11eb86b841e1770ee5b8
entity_id: light.hallway_light
domain: light
action:
- delay: "00:{{ states('input_number.lights_automation_lights_off_after') |float |int}}:00"
mode: single
I’m trying to replace this
for:
hours: 0
minutes: 3
seconds: 0
with this - delay: "00:{{ states('input_number.lights_automation_lights_off_after') |float |int}}:00"
Only issue I have now, is the Number doesn’t use two digits (01, 09, 33, 59 - Mins)
So I’ve had to go upto 9 minutes only, hardcoding the first zero.
It works though, next step is counting how many times this triggers.
- id: '1608068903614'
alias: '[Light Auto Off With No Motion] [Landing] Off after X minutes without motion'
description: ''
trigger:
- platform: state
entity_id: binary_sensor.landing_motion_sensor_motion
to: 'off'
for: 00:0{{ states('input_number.lights_automation_lights_off_after') |int}}:00
condition:
- condition: state
entity_id: input_boolean.lights_automation_master_lights_off_after_x_minutes
state: 'on'
- condition: state
entity_id: light.landing
state: 'on'
action:
- service: light.turn_off
data: {}
entity_id: light.landing
mode: single
Tried this same method with a notification, doesn’t work…
Any ideas?
- id: '1607270083692'
alias: '[Light on notification - OFFICE] - Office for x mins'
description: Pushes notification to turn off light if it's been on more than 30
mins
trigger:
- platform: state
entity_id: light.office
to: 'on'
for: 00:{{ states('input_number.lights_on_notify_lights_on_for_x_minutes')|float
|int }}:00
condition:
- condition: state
entity_id: input_boolean.lights_automation_master_notify
state: 'on'
action:
- service: notify.mobile_app_sm_g965f
data:
title: Office Light is on!
message: '{% if is_state("light.office", "on") -%} The Office Light has been
ON for - {{ relative_time(states.light.office.last_changed) }}. {%- else -%} The
Office Light has been OFF for - {{ relative_time(states.light.office.last_changed)
}}. {%- endif %}'
data:
actions:
- action: O_LIGHT_ON
title: Turn On
- action: O_LIGHT_OFF
title: Turn Off
mode: single