Yes i understand what you mean regarding the calender events although i could not get any documentation on the calender trigger, would the times be changeable on the fly i.e from lovelace.
The reason the automation is ran every 1 minute is to allow for a scenraio were the automation could not run at the start time or at the off time or if home assistant was not running or i have been making changes at the time. It also gives us the ability to stop it easily by switching a toggle or changing the times so it has immediate effect.
There are better ways to do that than with a Time Pattern Trigger. All of my scheduled automations are designed to survive restarts and outages without using a Time Pattern Trigger.
Not a direct benefit of a Time Pattern Trigger.
As mentioned, a Time Pattern Trigger is often misused; the vast majority of examples employing it are often inappropriate. It has a very limited range of justifiable applications.
If you are interested, here’s a brief tutorial on the subject of composing a “resilient” automation:
Not sure when you checked but 2022.5 literally just came out and so now the doc for it is visible. The doc on the calendar trigger can now be found here
Yes. I mean not necessarily from lovelace but no restart required. Like what I would do here is this:
Use the new calendar trigger in your automation to turn the hvac on when any event starts on the hvac calendar and turn the hvac off when any event ends on the hvac calendar
Make events in that calendar according to your hvac schedule. Like “HVAC on” with start time set to day and time it should turn on and end set to when hvac should turn off. Make the event repeat indefinitely. Keep adding events this way until your entire weekly schedule is in this calendar.
You can modify this calendar at any time in google this way. You can also add new events to it from HA if you want by using google.add_event service although you can only modify or delete existing events from the google calendar UI.
You can also do this with any other calendar HA integrates with, google is just the only one OOTB. But if you use HACS there are other options, like this one for Office 365.
FWIW, the one philosophical problem I have with using Google Calendar (or any cloud-based calendar) is that it makes something as fundamental as scheduling dependent on the cloud. Effectively, it makes a cornerstone of “local control” Home Assistant into “cloud-dependent” SmartThings.
I recognize its value but for basic scheduled tasks, my preference is to keep it local; to each their own.
I appreciate the advise, i agree and have thought about running them on start up as i do this for quite alot of other things.
The benefits i see with time pattern is it can read updated input timedate data should anyone in the house want to switch that rooms heating off or modify how long it will be on for.
In my example how could i incorporate the template into the script where it loops through the 10 input times.
Yea I know, its not ideal. There was discussion about a local calendar at one point. Like an option to simply make and manage calendars that are stored only in HA. I think this new trigger might bring that discussion back to prominence. I’m going to go see if there’s a feature request for it.
I could spend time re-engineering your automation but the disincentive is that, despite everyone’s advice, you still believe the Time Pattern Trigger has benefits for this application.
Thank you, again it probably comes down to personal preference the calender schedule does look though.
This was one my first goes at creating automations for our heating schedule although far from perfect it nearly is for us as the rest of the family understand it and a big part to that is the layout we have on lovelace its very easy to make adjustments and see when the schedule is active.
I understand it uses alot of helpers/variables but for me that was really easy to add hundreds in notepad.
I recall experimenting with the Caldav integration and a local instance of Radicale but the clumsy part was adding calendar events. It worked but I lost interest in it.
I would not expect that at all, i appreciate all the help you have given but i do not expect you to re-engineer it for me.
I do not see a big problem with it, it works as intended and yes it runs 1440 times a day but it does not affect the system and i could easily change that to run every 5 or 10 minutes.
If this solution you added above allowed for modifications in between the times i would totally agree with you it would be the way to go along with runs the automation on startup.
Now when any of the helpers change it immediately reruns the automation and sets it according to the new schedule. Instant response for updates, don’t even have to wait for the minute to be up.
The Time Trigger will trigger at whatever time specified by the Input Datetime even if you change its value (EDIT: However, a State Trigger is also needed to detect backdated times.) There’s simply no justification for employing a Time Pattern Trigger for your intended application.
Unnecessary; the Time Trigger takes into consideration any changes made to the Input Datetime’s value.EDIT Yes, it is needed to detect backdated times.
Like let’s say input_datetime.onwkday1 was set to 11:00:00 and the time is currently 10:30:00. And you realized you’re cold because its winter now and mornings are colder so you want to move the time up to 10:00:00. Well now you have an issue because that time is in the past. You missed that time trigger and now it won’t trigger at 11:00:00 anymore. Everything will be fine tomorrow but what about today?
That’s where the state trigger comes in. It fires because you changed one of the helpers and re-evaluates the schedule. This causes it to recognize that the hvac should be on right now and self-correct.
You’re absolutely correct; I had overlooked to consider the need to backdate the scheduled time; a Time Trigger certainly won’t trigger if its time is set to the past. Your suggestion to employ a State Trigger is definitely needed to detect the change in the input_datetime’s value. Then the Time Conditions in the choose come into play to determine which action to perform (if any).
So I have changed the triggers to time at and state changes of the input times and is all working as expected without the time pattern… so thanks for this improvement.
I will now work on for loop logic to reduce the code size I will post when I get something up and running.