Yes, I understand that particular approach works for the simple reason that it complies with the intended purpose of last_reset_topic.
My comment was targeted at the other approach you appear to have attempted in the past where you hard-coded the Unix Epoch into last_reset_value_template. The assumption is you did that to avoid having to explicitly publish that value. However, it fails because the template is not evaluated until a payload (any payload) is received via last_reset_topic.
correct. I did try that, because Frenck insisted ‘it’ should work. He didnt however say we need the last_rest_topic first…
Ive asked in Discord #devs_energy now, so hope we can get confirmation our conclusion is in fact correct
It’s also more specific than the description for plain old value_template
Defines a template to extract the value
That’s why I was puzzled by the lack of the last_reset_topic option in the first post. The combination of topic and corresponding value_template is fairly common (json_attributes_topic and json_attributes_template) so seeing last_reset_value_template used alone seemed anomalous to me.
with that knowledge Frencks answer makes sense now. At the time of that post, some of us were in the effort trying to make that stand alone template work, not thinking past our own mind lock…
It uses the same topic for state_topic, json_attributes_topic, andlast_reset_topic.
Because state_topic will regularly receive payloads, it will cause last_reset_value_template to be evaluated the moment a payload is received via the shared topic.
The actual content of the payload is irrelevant for last_reset_value_template because it doesn’t use it and is hard-coded with the Unix Epoch.
Applying this simple principle to Marius’ example, we get this:
but just didnt think of that. also because state_class: measurement isn’t supported on those legacy template sensors.
however, and this is HUGE news, with 2021.8.2 we can now use the template: in packages, and that is enough reason to spend the rest of my holidays rebuilding the template sensors in my config
I’m very new to MQTT and frankly almost all of this has gone entirely over my head…
I’m installing a Shelly EM tomorrow and was hoping to use it with MQTT (this was my plan before 2021.8 so it’s a really well timed update for me)!
Not a damn clue how to set it all up… why are there two sensors and more importantly are they both template sensors or what? I get the MQTT sensor but what the heck is the bit that Taras named ZP Import?
Like francisp explained, that’s in the example posted by Mariusthvdb. When I posted a revised version of his example, I purposely excluded the YAML anchor to simplify it and avoid confusion.
A YAML anchor let’s you duplicate a section of YAML elsewhere simply by referring to it by name. I provided an example for someone else in this thread.
The complaint comes from VS Code Config Helper. It works with VS Code to identify potential errors in your YAML code. It probably hasn’t been updated yet so it falsely identifies those two options as being “not allowed”.
still nothing… (Had to put a close “)” on that to make it work)… I’ve even tried hardcoding the date in the right format but never got HA to recognize it.
I know this topic is old and you may know why this happened now but for anyone arriving here as I did I believe it’s because of the state_class being set to measurement in your case.
I used the state_class: total and the value I put in to last_reset_value_template is then populated.