francisp
(Francis)
August 8, 2021, 8:50am
21
I only once find ZP Import on this page, and it is an example from marius using yaml anchors. You can ignore it.
The important message from this whole topic is: if you want to use your mqtt sensor in the energy tab, it needs at least 4 extra items :
device_class: energy
state_class: measurement
last_reset_topic: 'electricity1/tele/RESULT'
last_reset_value_template: '1970-01-01T00:00:00+00:00'
device_class, state_class, last_reset_value_template: always as shown
last_reset_topic: set it to your state topic
2 Likes
123
(Taras)
August 8, 2021, 11:36am
22
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.
Here’s how I use it. The following is a portion of my lights.yaml file.
The configuration of the first light includes the definition of a node anchor called dimmer. All subsequent light configurations refer to the dimmer anchor.
- name: "Foyer"
state_topic: "premise/foyerlight/powerstate"
command_topic: "premise/command/foyerlight/powerstate"
brightness_state_topic: "premise/foyerlight/brightness"
brightness_command_topic: "premise/command/foyerlight/brightness"
<<: &dimm…
1 Like
DJJo14
August 8, 2021, 12:06pm
23
navet:
sensor.*_Energy:
Tanks but for me it needs to be without a uppercase letter
sensor.*_energy:
I also have my power and engery readings via mqtt. But I couldn’t add these lines using VSCode as an editor. Well, I could! But it complaints.
state_class: measurement
last_reset_topic: 'electricity1/tele/RESULT'
last_reset_value_template: '1970-01-01T00:00:00+00:00'
Because it keeps complaining that “Property state_class is not allowed”. Same complaints for the other two lines of YAML.
Does anyone know a solution for this annoyance?
123
(Taras)
August 22, 2021, 6:43pm
25
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”.
The next update will probably correct it.
mwildrick
(Matt W)
April 29, 2022, 11:42pm
26
I know this is an older thread but I am really struggling with getting this to work.
I have a ZooZ z-wave power strip. The MQTT topic for power monitoring returns this json:
{
"value_id": "6-50-1-0",
"node_id": 6,
"class_id": 50,
"type": "decimal",
"genre": "user",
"instance": 1,
"index": 0,
"label": "Instance 1: Electric - kWh",
"units": "kWh",
"help": "",
"read_only": true,
"write_only": false,
"min": 0,
"max": 0,
"is_polled": false,
"value": 111.02,
"lastUpdate": 1651274701101
}
I believe the ‘lastUpdate’ element is what should be used for the last_reset_value_template:
Here’s what my Yaml Looks like:
### Power Monitoring ###
- platform: mqtt
name: Office_Power_Strip_Total_kwh
state_topic: "zwave2mqtt/6/50/1/0"
value_template: "{{value_json.value}}"
last_reset_topic: "zwave2mqtt/6/50/1/0"
last_reset_value_template: "{{value_json.lastUpdate}}"
unit_of_measurement: "kWh"
device_class: energy
state_class: measurement
But for the life of me, I cannot get this last reset value to populate.
Does anyone have any ideas on what i’m doing wrong?
francisp
(Francis)
April 30, 2022, 4:41am
27
That does not seem a date.
mwildrick
(Matt W)
April 30, 2022, 10:04am
28
Its an epoch / unix timestamp.
francisp
(Francis)
April 30, 2022, 10:18am
29
try this:
last_reset_value_template: "{{value_json.lastUpdate | int | timestamp_custom('%d.%m.%Y %H:%M'}}"
mwildrick
(Matt W)
April 30, 2022, 10:37am
30
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.
lwsrbrts
(Lewis Roberts)
December 6, 2022, 11:29pm
31
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.