Hi all, potentially noob question here but I’m stymied and cannot readily find an answer (maybe workarounds but I’d like to understand). I have an energy contract with hourly varying prices and I can retrieve these prices for a day, and at around 15:00 for the next day. To get these prices I have set up (with help from Google and Github (KlaasNicolaas)) 2 sensors. If I understand the syntax right these should trigger hourly, and once a day at 16:00. Here is the YAML:
I take the “prices” list from the response and plot them in an apexchart. All fine and dandy and this seemed to work. Triggering the action by hand with the developer tools works fine and gives me the expected price list. BUT… sometimes it takes hours for the tomorrow data to appear. Checking the activity log shows that the “energy prices-today” sensor gets updated erratically - sometimes hourly as it should, sometimes not at all for hours in a row?? The “energy prices-tomorrow” sensor is even worse. Occasionally it is updated at 15:59 (?), but often also at 19:00, 21:00 and other times.
Is my understanding of time patterns and templates this far off? How can these updates occur (or not) at such unpredictable times? I could maybe device workarounds but I’d like to know what’s happening here.
Many thanks in advance for any help and suggestions provided.
Maarten
On second thought, my preference for how the second Trigger-based Template Sensor should operate is to use a Time Pattern Trigger set for every hour combined with a Template Condition, in its conditions, to check if the hour is greater or equal to 16.
The reason is because this version’s Time Pattern Trigger triggers just once per hour (24 times a day). The previous version employs a Template Trigger containing the now() function. That means the template will be evaluated every minute (1440 times a day).
The use of the homeassisant trigger means both should update every time HA restarts. This may explain some of the “random/unpredictable” times.
Template triggers fire when their resolved value changes from false to true. Because of the use of > in the first clause and the now().minute == 0 in the second clause, the resolved value will switch to false at 1 minute after the hour, and switch back to true when the next hour starts at minute 0. So, the “Tomorrow” sensor should be expected to update at the top of every hour from 4pm - 11pm, explaining the 19:00 and 21:00 updates.
If that is not what you want, follow Taras’ instructions above to have it trigger at only 4pm.
If you continue to have issues with time-based triggers:
The most common causes of time-based triggers firing, seemingly, randomly in HA are:
NTP (network time protocol) issues, especially when you are using SBCs like raspberry pis that lack a real time clock device.
Virtualization-related issues. VM-Ware seems to be particularly prone to this, but there have be cases with pretty much every virtualization software out there.
If you do a search on this forum or any other HA-related fora you will find dozens of threads on the subject.
Hi both, thanks for your help. I changed the yamls as suggested (so hours: “/1”) and the tomorrow prices with the condition suggested by Taras. It’s only been a day since I made the edits in the YAMLs, but I still see the hourly update trigger occasionally gets skipped - in the Activity view I normally see energyzero “Energy prices - today” get updated every hour but, for example just now, it skips 12.00 and 13.00, and last night it skipped 03.00.
At these times there’s plenty of activity recorded in Activity, so it’s not that the whole system freezes briefly or something like that.
Yesterday it even skipped from 16.00 to 0.00 (might still have been the old "hours: “*” " time pattern. But even then!). I feel I’m missing something. Is an updated sensor only shown in “Activity” if any of its values (here in the Prices attribute) changes? Obviously its state is a timestamp here, which changes every time the action is triggered… Or would the energyzero_get_energy_prices action maybe not register as triggered if its response is the same? Seems very weird… So, I find myself still stymied. Any further suggestions what could be going wrong here?
Oh and didgeridrew, I have HA running on a dedicated I5 with plenty of memory, supervised installation. So possible NTP or virtualisation issues seem a bit unlikely?
If the action returns the same data, the sensor appears not to have updated. This is how Home Assistant attempts to keep the recorder database small. Aside from the trigger definitions being different from what you expected, I get the feeling the prices are not updated regularly server side. One way to check is to get the action results when you see the results in the sensor are stale for more than an hour. If the server is indeed not always giving new data, then I suggest you keep the trigger to fire not only at 16:00 but in the hours after also.
I would also try to see if offsetting the time of both sensors a bit helps. It is a bit of a stretch, but maybe the integration or the server does not like to be asked both todays and tomorrows data for the same customer at exactly the same time?