It would be nice if we could use entities such as input_numbers in the for: section of a timed trigger.
ie:
input_number:
kitchen_light_auto_off_time:
name: Kitchen light auto off time
min: 1
max: 9
step: 1
icon: mdi:camera-timer
unit_of_measurement: min
automation:
- alias: 'Kitchen light OFF after x mins'
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.kitchen_multi_sensor_sensor
to: 'off'
for:
minutes: input_number.kitchen_light_auto_off_time
action:
- service: homeassistant.turn_off
entity_id: light.kitchen_light
The above is not allowed. Instead we have to call a script and have the timer in there which means more code. I just think it would be nice and clean to be able to run dynamic timers in the triggers directly.
I was just thinking this today. I want an adjustable delay for turning my lights off dynamically. The way it is now I have to trigger every minute and use a condition template. Trigger templates would be much more cpu resource friendly.
You can do it without a template, but I still feel it’s not as neat as it should be. I’ll post my work-around as soon as I can for you. Templates in the triggers would be so much better though
input_number:
kitchen_light_auto_off_time:
name: Kitchen light auto off time
min: 1
max: 9
step: 1
icon: mdi:camera-timer
unit_of_measurement: min
automation:
- alias: 'Kitchen light auto off'
initial_state: 'on'
trigger:
- platform: state
entity_id: binary_sensor.kitchen_multi_sensor_sensor
action:
- service: script.turn_on
entity_id: script.kitchen_light_auto_off_timer
script:
kitchen_light_auto_off_timer:
alias: Kitchen light off after preset time
sequence:
- delay: '00:0{{ states.input_number.kitchen_light_auto_off_time.state | int }}:00'
- service: homeassistant.turn_off
data:
entity_id: light.kitchen_light_level
There is a lot more to the kitchen light control, but that is the part that achieves the adjustable timer. For example, I stop the auto_off script if motion is re-triggered.
In order for that to happen the motion detector would have had to change to ‘motion detected’, then back to ‘no motion’. When motion is detected I stop the delay timer script, so once the change of state back to ‘no motion’ occurs, the script isn’t currently running. I’ll post the whole package to explain it.