Using the context
variable, start a timer when the switch is turned on manually. Just FYI, if you are using a helper to change device type of a switch
to light
, it is best to use the switch
entity in the first automation.
alias: Kitchen Lights Manual Timer
description: ""
trigger:
- platform: state
entity_id: light.kitchen_lights
to: "on"
variables:
id: "{{trigger.to_state.context.id}}"
parent: "{{ trigger.to_state.context.parent_id }}"
user: "{{ trigger.to_state.context.user_id }}"
condition:
- alias: Test if triggered by physical device
condition: template
value_template: "{{ (id!=None, parent, user) == (true, None, None) }}"
action:
- service: timer.start
target:
entity_id: timer.kitchen_lights
Modify your original automation to not turn the lights off when the timer is running and to trigger when the timer finishes.
alias: Autolights - Kitchen + Ut
description: ""
trigger:
- type: present
platform: device
device_id: e1ad7b06f6483100fdc1ded7bea6659e
entity_id: 2875b2fff8b63f52cfc657cefa2ca682
domain: binary_sensor
id: Motion detected
- type: not_present
platform: device
device_id: e1ad7b06f6483100fdc1ded7bea6659e
entity_id: 2875b2fff8b63f52cfc657cefa2ca682
domain: binary_sensor
id: Room empty
- platform: state
entity_id: timer.kitchen_lights
to: idle
from: active
id: Timer finished
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: Motion detected
- or:
- condition: sun
after: sunset
after_offset: "-02:00:00"
- condition: time
before: "00:30:00"
sequence:
- service: light.turn_on
target:
entity_id:
- light.kitchen_lights
- light.utility_room_light
- conditions:
- condition: trigger
id:
- Room empty
- Timer finished
- not:
- condition: state
state: active
entity_id: timer.kitchen_lights
sequence:
- service: light.turn_off
target:
entity_id:
- light.kitchen_lights
- light.utility_room_light
mode: single