#simplifying 5m on/10m off time based automation
1 messages · Page 1 of 1 (latest)
trigger:
- platform: time_pattern
minutes: "0"
id: "on"
- platform: time_pattern
minutes: "15"
id: "on"
- platform: time_pattern
minutes: "30"
id: "on"
- platform: time_pattern
minutes: "45"
id: "on"
- platform: time_pattern
minutes: "5"
id: "off"
- platform: time_pattern
minutes: "20"
id: "off"
- platform: time_pattern
minutes: "35"
id: "off"
- platform: time_pattern
minutes: "50"
id: "off"
condition: []
action:
- if:
- condition: trigger
id:
- "on"
then:
- service: homeassistant.turn_on
data: {}
target:
entity_id: switch.aquarium_lights_plug_aquarium_lights_relay
- if:
- condition: trigger
id:
- "off"
then:
- service: homeassistant.turn_off
data: {}
target:
entity_id: switch.aquarium_lights_plug_aquarium_lights_relay
mode: single
action:
- service: "switch.turn_{{ trigger.id }}"
data: {}
target:
entity_id: switch.aquarium_lights_plug_aquarium_lights_relay
I think all the on triggers could be replaced by:
- platform: time_pattern
minutes: "/15"
id: "on"
Guess can't do the same with off though.
Could probably just do it with:
- platform: state
entity_id: switch.aquarium_lights_plug_aquarium_lights_relay
to: "on"
for: "00:05:00"
id: "off"
this is just a service?
That's just a trigger
oh ok, so its saying once the entity has been on for 5m, trigger with the id of off.
Yes
trigger:
- platform: time_pattern
minutes: "/15"
id: "on"
- platform: state
entity_id: switch.aquarium_lights_plug_aquarium_lights_relay
to: "on"
for: "00:05:00"
id: "off"
action:
- service: "switch.turn_{{ trigger.id }}"
data: {}
target:
entity_id: switch.aquarium_lights_plug_aquarium_lights_relay
so none of my automations have an importance resolution of < 1m, is there a way to harden them by checking that they are in a proper state every 1m to get around unavailability of entities or ha downtime? like once everyone is back online, check the proper state and set to what they should be if not type of thing.
You'd need a startup trigger, and #templates-archived logic to handle whether it should be on or off
There is a difference between triggering at minutes: "0", minutes: "15" etc and minutes: "/15"
I think the last one will be based on the startup time of HA
Nah
You can prefix the value with a
/to match whenever the value is divisible by that number
does the state trigger youre using have the same downside as a time delay being interrupted 🤔
Well, yes but no, but yes... hence #1151550383953559664 message
Well that's what I thought first as well, but according to Petro it is based on the number of minutes from a certain base point (so HA start, or 1970-1-1 00:00)
So minutes: "/37" should trigger every 37 minutes then, and not at XX:00 and XX:37
at XX:00 and XX:37
I'm pretty sure that's what you get
trigger:
- platform: time_pattern
seconds: /42
condition: []
action:
- service: system_log.write
data:
message: The trigger fired
level: warning
2023-09-13 09:55:00.503 WARNING (MainThread) [homeassistant.components.system_log.external] The trigger fired
2023-09-13 09:55:42.502 WARNING (MainThread) [homeassistant.components.system_log.external] The trigger fired
2023-09-13 09:56:00.502 WARNING (MainThread) [homeassistant.components.system_log.external] The trigger fired
Then it was what I thought it did and @drifting swallow misinformed me
what
Hehe, the time pattern trigger doesn't work as you explained, but it works as I templated it 😅
not sure what you mean
it should trigger every x minutes from startup unless someone changed it
or x seconds
it is sort of odd, you would think it would only fire at 09:55:42
The example above from @boreal kernel shows otherwise
that would be just seconds: 42
No it does 0 as well, as that's devisable by 42 as well
seconds: 42 will just fire on the 42nd second
/42 should be every 42 seconds from startup
does not do that
if it's not doing that, it's a bug
what do you think about this then:
minutes: /3
seconds: /42
I would assume that wouldn't work
it's possible this all changed
but when I first started using HA, it was based on startup
I do vaguely remember something changing to use modulo
there are threads to get every hour and a half that was a breaking change
so it's possible it changed
I guess so
I personally avoid time_patterns as they are not useful (to me)
and just for the record
minutes: /3
seconds: /42
Triggers at 00:00, 00:42, 03:00, 03:42, ...
the visual editor says: "Trigger every 42 seconds of every 3 minutes of every hour"
i totally understand
good luck to all you translators out there hehe
Yes, it's completely different now
took me a bit to track down the code
but it's all been unified under the event helper
it was completely different code back in the day. They must have redone it when it went full async
it's not even in the change history, meaning it was prior to the great migration
circa 2018
The Great Migration
Yes
it was a folder structure change
but I dont' remember what the old structure looked like
but it affected the way integrations were loaded
it basically kills the history prior to that change too
specifically a folder structure change for integrations
Ah okay
either wya, I can't find the original time_pattern trigger
I 100% remember it used modulo and didn't schedule the next trigger. Now it schedules the next trigger and mimics modulo
Ah I remember now
This was the old structure
so, if you wanted to look for an blink light, you'd go to the light folder and look for blink.py
now you go to the blink folder and look for light.py
e.g.
light
- hue
- zwave
- zigbee
sensor
- hue
- zwave
- zigbee
switch
- hue
- zwave
- zigbee
vs
hue:
- light
- sensor
- switch
zwave:
- light
- sensor
- switch
zigbee:
- light
- sensor
- switch
new way is 100% better
It's similar to the move away from platform in the configuration
yes
well, that's what it was built around initially
as those were the platforms
now there's a function that registers the platform
instead of assuming platforms based on py files
it was a big todo
as you can imagine
Anyways, back to the time_pattern crap, it probably changed, disregard what I said before. It definitely mimics modulo
IMO it makes it good but also bad. Seems like we should add back the old functionality. Or make a new trigger type.
or just use templates, but you won't get second granularity
Trigger on every second using the time pattern trigger and check on the seconds in a condition