Hi everybory. I’m posting this because I have an automation that turns a light off after a time and I want to set this time from an input_number. The automation is the following:
trigger:
- entity_id: binary_sensor.Wemos04PIR
platform: state
to: ‘off’
for:
minutes: ‘{{ states.input_number.luz_cocina_tiempo.state | int }}’
But it doesn’t pass the config check…
Can anybody help me?
Have you found a solution yet?
If not, this is possible, but it gets a little involved. Basically you use a timer whose duration is set according to the input_number. You start the timer when binary_sensor.Wemos04PIR changes to ‘off’, and you cancel the timer when binary_sensor.Wemos04PIR changes to ‘on’. If/when the timer finishes you turn the light off.
Hi, I still haven’t found the solution. I don’t know how to use timers, maybe you can help me with tins…
Sure. FYI, you can read about timers here.
timer:
wemos04pir_off:
name: Amount of time binary_sensor.Wemos04PIR has been off
automation:
- alias: No motion - start timer
trigger:
platform: state
entity_id: binary_sensor.Wemos04PIR
to: 'off'
action:
service: timer.start
entity_id: timer.wemos04pir_off
data_template:
duration: >
{{ (states('input_number.luz_cocina_tiempo')|int * 60)
|timestamp_custom('%H:%M:%S',false) }}
- alias: Motion - cancel timer
trigger:
platform: state
entity_id: binary_sensor.Wemos04PIR
to: 'on'
action:
service: timer.cancel
entity_id: timer.wemos04pir_off
- alias: Timer finished - turn off light
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.wemos04pir_off
action:
service: light.turn_off
entity_id: light.my_light
If you want motion to turn on the light, too, then you can change the second automation to:
- alias: Motion - turn on light and cancel timer
trigger:
platform: state
entity_id: binary_sensor.Wemos04PIR
to: 'on'
action:
- service: light.turn_on
entity_id: light.my_light
- service: timer.cancel
entity_id: timer.wemos04pir_off
Thank you very much!!!
I will try this as soon as I can!!!
1 Like
Hi pnbruckner, you’re a genious, I tryed your automations and now it works perfect!!!
THANK YOU VERY MUCH!!!
1 Like