What I would like to achieve is to have an automation run every x minutes between y and z where x is the number of minutes defined in an input_number, y and z is the time range defined in two input_date_time
All these three entities are defined in a lovelace card.
Do you think the automation in first post can do this?
This will let the automation repeat every x minutes within the time defined in the condition and is triggered by the start time and the template sensor ?
Good point that I have to check what happens if HA is restarted
I was wrong about not being able to trigger off attribute changes with for: — you can (docs, and I ran my own test to check), and therefore don’t need the template sensor.
Correction, as long as the result is a minutely result. now() only updates on the minute inside templates, nothing else. Any more granularity and you’d need to use a time_pattern trigger with a condition.
So long as the integer conversion of the input_number doesn’t result in 0, I think this should always behave the same way as time_pattern? 27 would fire at x:00, x:27 and x:54; 69 would only fire at x:00.
Provided the interval is an integer factor of 60 (as I stated), it should even work as expected: 20 would fire at x:00, x:20 and x:40.
time_pattern and my template trigger won’t work with values greater than 60: they will only trigger on the hour. They work by seeing if the clock minute value divided by the frequency number (strictly, a period not a frequency) is an exact integer. That’s why they only work as expected if the number is an integer factor of 60 (1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60).
My trigger in post 4 will work with any value from 1 upwards, including values larger than 60.
I’m understanding is that my automation is more complicated than I think
My needs are
Within the give time in condition, if a temperature changes and is below a given one, the automation have to run and do what in it.
Probably I need also a boolean to set to on when the automation is already runnig to avoid to start again if the temperature changes but it’s still below the given one.
I can understand when to set the boolean to on, but how to set to off if the temperature goes above the given one?
alias: test avviso
description: test avviso
trigger:
- platform: numeric_state
entity_id: sensor.temperatura_netatmo
below: input_number.temperatura_minima_avvisi
- platform: time
at: input_datetime.ora_inizio_avviso_temp_bassa
- platform: state
entity_id: automation.test_avviso
attribute: last_triggered
for:
minutes: "{{ states('input_number.frequenza_avviso_temp_bassa') | int }}"
condition:
- condition: time
after: input_datetime.ora_inizio_avviso_temp_bassa
before: input_datetime.ora_fine_avviso_temp_bassa
- condition: numeric_state
entity_id: sensor.temperatura_netatmo
below: input_number.temperatura_minima_avvisi
action:
- service: light.toggle
metadata: {}
data: {}
target:
entity_id: light.studio
mode: single
Triggers at your start time (in case it’s already cold at that time), whenever the temperature drops below the threshold value, and x minutes since the last run; the conditions check that you’re both within your time range and cold.
Note that the badly-named last_triggered attribute only updates when the action section is reached.
Note that this could run twice in quick succession if the temperature drops very soon after the start time. You could add an additional condition to check how long it’s been since the last run if that matters to you.
Yes, that’s right although remove the surrounding quotes; and assuming all the entity IDs are correct. That checks if:
the current time as a UNIX timestamp (seconds since 1970-01-01)
minus
the last run of the automation also as a UNIX timestamp
is greater than or equal to
your input_number (in minutes) times 60 (to match the seconds)