Maybe that is a solved question already, but I couldn’t find it…
When creating a template from a group of entities, in this case four different solar panels to get a sum of what they produce in power, the graph I am getting is getting holes in it, whenever HA is restarted or the yaml reloaded. I tried the following code, which already helped to not ‘zero’ return in those momets, but now the graph has many holes in it. I
Is it possible to code, that the template returns (and stores for graph display) the last value used until it is available again. I tried ‘availability’ also, but that didn’t work (for me…)
An help appreciated.
here is my template, and an image of the returned graph. I tried two versions, one with ‘is number only’ and one with an if-then logic. both don’t fill the holes…
After a restart your template sensor will not have a value until at least one of the sensors it contains updates.
It’s actually nothing to worry about and will not mess anything up. If you want you could create a triggered template sensor. These are restored after a restart.
Thankyou! The code works. I understand, that it’s not necessary, but no holes looks better.
I do get a nag message in Studio Code Server for - platform: state saying 'String does not match the pattern of “LEGACY_SYNTAX” which seems to be new in version 10.24 and couldn’t correct it (I tried ‘trigger’ instead of 'platform as suggested here: 2024.10: Heading in the right direction - Home Assistant , but somehow it did not compute for me) But, anyways, legacy code does still work and my trigger triggers. So thanks for solving my problem!
If I understand right, ‘condition: template’ would only pull information, if entity ‘|is_number’, instead of allways pulling (if-else) and defaulting to the last given state?
So, if an entitity is not available (restart of HA inavailabilty of my tasmota gas sensor.), ‘condition: template’ would just not ask for information, right?
But what, if e.g. my PV on roof is just not spreading news of how much watts it’s producing (at night) and becomes inavailable. I used ‘0’ instead of ‘this.state’, so it’s not showing the last produced power ((e.g. 8 watts) the whole night. Would ‘condition’ work here, too?
It will only generate the template for the state if the condition returns true, if not, it will just keep the old state (trigger based template sensors restore their state, also after a restart)
For your PV question, don’t check on that state in the condition, and use float(0) to default it to 0 in case it’s unavailable.