good morning,
I would like to create a timer with input by input number and input select minutes and the light that must have the timer active, can you help me? because I do not understand how to input input select and input number
When you say “it does not work”, it’s very helpful if you elaborate on what that means. E.g., did you can an error, and if so, what? Etc.
But my guess is you can’t use a template with for: minutes:.
If I understand, you want to turn a selected light (selected by an input_select) off a certain amount of time (controlled by an input_number) after light.luce_letto is turned on, if light.luce_letto has been on continuously for that time period. Is that correct?
If so, then you could do it with a timer and a few automations:
timer:
luce_letto_on:
name: Time light.luce_letto needs to be on
automation:
- alias: light.luce_letto turned on
trigger:
platform: state
entity_id: light.luce_letto
to: 'on'
action:
service: timer.start
entity_id: timer.luce_letto_on
data_template:
duration: "{{ (states('input_number.minuti_luci')|int(2) * 60)|timestamp_custom('%H:%M:%S',false) }}"
- alias: light.luce_letto turned off
trigger:
platform: state
entity_id: light.luce_letto
to: 'off'
action:
service: timer.cancel
- alias: light.luce_letto on for desired time
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.luce_letto_on
action:
service: light.turn_off
data_template:
entity_id: "light.{{ states('input_select.luci_timer')|lower }}"
I can’t really test this, but if this doesn’t work as-is, it should be close and at least a start.
Of course, there may be an easier way to do this. If so, maybe someone else will jump in.
I would like to be able to select any light via input select and through the input number to select the minutes, the light that I have selected must be turned off in the specified time when I turn it on.
This works only light.luce_letto
Ok. The easy way to do that is to add all the light entities that might be selected by the input_select to the trigger, then add a condition that makes sure the light that turned on was the selected one. So:
timer:
light_on:
name: Amount of time light should stay on before being turned off
automation:
- alias: Light turned on, start the timer
trigger:
platform: state
entity_id:
- light.luce_letto
- light.lampadario
- light.striscia_led_rgb
to: 'on'
condition:
- condition: template
value_template: >
{{ trigger.entity_id == 'light.' + states('input_select.luci_timer')|lower }}
action:
service: timer.start
entity_id: timer.light_on
data_template:
duration: "{{ (states('input_number.minuti_luci')|int(2) * 60)|timestamp_custom('%H:%M:%S',false) }}"
- alias: Light turned off, cancel the timer
trigger:
platform: state
entity_id:
- light.luce_letto
- light.lampadario
- light.striscia_led_rgb
to: 'off'
condition:
- condition: template
value_template: >
{{ trigger.entity_id == 'light.' + states('input_select.luci_timer')|lower }}
action:
service: timer.cancel
entity_id: timer.light_on
- alias: Light on long enough, turn it off
trigger:
platform: event
event_type: timer.finished
event_data:
entity_id: timer.light_on
action:
service: light.turn_off
data_template:
entity_id: "light.{{ states('input_select.luci_timer')|lower }}"