Hello everybody,
I have set-up an automation that automatically turns off the bathroom fan if it has been on for more than 15 minutes:
- alias: Bathroom fan timer
initial_state: true
trigger:
platform: state
entity_id: fan.bathroom_ventilation
to: 'on'
for:
minutes: 15
condition:
condition: and
conditions:
- condition: state
entity_id: input_boolean.bathroom_ventilation_limit_15_min
state: 'on'
action:
service: homeassistant.turn_off
entity_id: fan.bathroom_ventilation
I would like now to make the 15 minutes a parameter that I can set through a slides in lovelace. Does anybody have a suggestion on how to approach the problem, in order to have a slider “feed” the minutes: 15 variable inside the code?
I’m working on a PR that will add templating support to the state & numeric_state triggers’ for option. I’ve already submitted one for the template trigger, and it has been accepted. (Actually, it was two: 24810 and a follow up, 24893.) Once these make it to a release this will be much simpler.
In the meantime it can be done with a timer and a couple more automations. But if you can wait for the release with templating support in the for options, like I said, it will be much easier.
UPDATE: 24912 submitted to add template support to state trigger’s for option.
UPDATE: 24955 submitted to add template support to numeric_state trigger’s for option.
So this will not work the same as using the trigger’s for option. If the switch is turned on, and then off, and then back on before the delay completes, it will not trigger the automation to start again. Rather, it will abort the delay and turn the switch off immediately.
However, if you use the trigger’s for option then it will not turn off the switch until the switch has been turned on and stays on for the specified amount of time. So in the scenario above, it will turn the switch off the specified amount of time after the second time it turns on instead of immediately after the second time it is turned on.
I think you want this:
- alias: Irrigazione balconi timer
initial_state: true
trigger:
- platform: state
entity_id: switch.irrigazione_balconi
to: 'on'
for:
minutes: "{{ states('input_number.irrigazione_balconi_limit_minutes') | int }}"
seconds: "{{ states('input_number.irrigazione_balconi_limit_seconds') | int }}"
condition:
- condition: state
entity_id: input_boolean.irrigazione_balconi_limit
state: 'on'
action:
- service: switch.turn_off
entity_id: switch.irrigazione_balconi
Is a solution which helped me with a similar problem. When you trigger a timer to start you also can set a duration. And if you use data_template, you can set the new duration from an input_number.