time_pattern:
minutes: /90
Apparently wrong, see post 6 below.
time_pattern:
minutes: /90
Apparently wrong, see post 6 below.
Giving this further thought, I am not sure when the first match will be for minutes: /90
. Probably it will run when the automation is turned on (eg when HA is started, or someone turns the automation on), and then every 90 minutes. This means that the triggering won’t necessarily be "at dawn ten every 90 mins). There could be up to 89 minutes after dawn for the first watering.
If I am right and that the trigger will be when the automation is turned, you could turn it off then on at dawn. That’s easy.
Random thoughts anyway…
So I would try the new ‘while’ loop that tests a state and repeats if true. Combine that with a sunrise trigger and a 90 min delay on the loop and I think you are done.
trigger:
- platform: sun
event: sunrise
action:
- repeat:
while:
- condition: state
entity_id: sun.sun
state: 'above_horizon'
sequence:
- sprinkler.run (or whatever)
- delay:
minutes: 90
now this automation will be on all day, and maybe that could be problematic. Something throws it off, a reboot or something.
It’s more complicated but you could also do it with a automation that fires a script for the watering. You create a sensor that tracks how long it’s been since the script was fired. That automation is triggered by sunrise or passing above 90 mins since last fire. This option is better because even if HA lost track, it would start counting the 90 mins from scratch and would continue to water through the day.
The sensor might look like
sensor:
- platform: time_date
display_options:
- 'time'
- platform: template
sensors:
sprinklers_last_run:
friendly_name: 'Last Run'
entity_id: sensor.time
device_class: timestamp
value_template: '{{ (now().timestamp() - as_timestamp(states.script.start_sprinkler.last_changed))|int / 60 }}'
So the Automation would look like
( also you need a rain_delay boolean )
trigger:
- platform: sun
event: sunrise
- platform: numeric_state
entity_id: sensor.sprinklers_last_run
above: 90
condition:
condition: or
conditions:
- condition: template
value_template: >
{{ trigger.event == 'sunrise' }}
- condition: state
entity_id: sun.sun
state: 'above_horizon'
action:
- condition: template
value_template: >
{{ is_state('input_boolean.rain_delay', 'off') }}
- service: script.turn_on
entity_id: script.start_sprinkler
That will not work. The /90 here applies only to the minutes part of any time of day, going from 0 to 59. So this will match every hour on the hour.
I proposed PR #38282 which will make the above configuration invalid. Things can still get confusing though as e.g. minutes: /25
will match xx:00, xx:25 and xx:50 … so it waits for 25 minutes two times and then for 10 minutes.
(I don’t know of a simple way to fire every 90 minutes.)
Thanks for the clarification!
Still think it would be a benefit to have a cron
platform. Then you could trigger every 90 minutes using this expression:
trigger:
- platform: cron
value: '30 1/3 * * *'
See Crontab Guru
What it doesn’t do, and which I think the OP wants, is to run at dawn, and then every 90 minutes. Mind you, neither did mine, even if it could work.
apologies for raising an old thread, but has anyone any idea how to trigger automations every 90 minutes?
please check: Automation Trigger - Home Assistant
Can you please try this? You need to setup an automation which has trigger type Template
. Please adjust timeout_in_minutes variable and let me know.
Information: this will check when specific automation had run last time and if X minutes had passed. If the automation has never run yet, it will take last updated time instead of last triggered. So, it is not going to be in 3:00 - 4:30 - 6:00, it will try to execute in every 90 minutes from a starting point.
{% set timeout_in_minutes = 90 %}
{% if state_attr("automation.server_is_on_low_battery_notify", "last_triggered") == None %}
{{
(
(
as_timestamp(now()) -
as_timestamp(states.automation.server_is_on_low_battery_notify.last_updated)
)
/ 60.0 ) > timeout_in_minutes
}}
{% else %}
{{
(
(
as_timestamp(now()) -
as_timestamp(state_attr("automation.server_is_on_low_battery_notify", "last_triggered"))
)
/ 60.0 ) > timeout_in_minutes
}}
{% endif %}
PS: if you are looking for guaranteed solution, this cannot be the one please discard this possible solution, other way around, this is best intention and good will. Feel free to discard or give it a try!
You have posted a link to the Time Pattern Trigger. Did you see amelchio’s post (above) explaining why a Time Pattern Trigger cannot be used for a 90-minute interval?
trigger:
- platform: template
value_template: "{{ (now().hour*60+now().minute)%90==0 }}"
Checks if the number of minutes since the start of the day is exactly divisible by 90. Might do odd things on daylight savings adjustment days.
no, I did not get it why it is not possible? it looks like we can use a time pattern as below, would not it work?
“You can prefix the value with a /
to match whenever the value is divisible by that number.”
Your trigger will fire every 30 minutes, if that description is correct.
Why are you asking if it will work? Didn’t you test it before you proposed it?
This is a community platform, not a customer service, we are doing our best to help. So, I am sharing my personal experience and my thought, so, if it works perfect, if not, i will learn something new. I do not have any obligation to be sure 100% correct/valid/tested other than good intentions. If you are looking for answers which are tested/validated, I will not be able to share them and you are free to discard my messages.
thanks for explanation, I see that it will not sum the values, rather use individuals one. I will experiment locally.
Your reply only needed to be “No, didn’t test it.” However, that was evident from the fact you proposed using the Time Pattern Trigger when amelchio, one of Home Assistant’s developers, already explained it couldn’t be used to repeat every 90 minutes. Yet you proposed it anyway (10 months later).
Nowhere in the documentation does it suggest the options are additive.
i checked the code pointers, bear with me;
so, you are right, it will be triggered in next 30 minutes or next 1 hour, it will not use all parameters as a bundle.
please safely discard my messages, you are free to do, nothing enforces other way around.
The “danger” is that people will stumble across your recommendations and waste time trying to get them to work. If I ever suggest something that turns out to be wrong (not unknown ) I go back and edit the post to clarify my error (recent example).