Create energy sensor for Energy-Dashboard from Node-Red?

As I have a Smartmeter provided by Discovergy I use the Node Red integration to read the actual numbers from the Discovergy API to create a sensor in Home Assistant with this configuration:

state_class: measurement
last_reset: '2021-01-07T08:08:02+00:00'
unit_of_measurement: kwh
friendly_name: Stromverbrauch
device_class: energy

Works fine in general but the sensor does not show up in the Energy Dashboard. I do have some Smart plugs (Gosu) with the same config and these are available. What do I miss here?

I had a similar problem, just check that the number coming back from your discovery API is not a string…if its a string you need to convert it to a number in node red before you send it to the HA device node.

I’m trying to solve the same problem. How did you configure the node to get and set the last_reset value?

Maybe you could be so kind to share the flow json?

Thanks for the suggestion. Checked the output and it is a number. For test purposes I’ve injected a fixed number, unfortunately the sensor still does not show up in the Energy Dashboard.

Some additional Info. This is the debug output in Node Red.

12.8.2021, 12:34:54[node: Stromverbrauch](http://ha.derfisch.zuhause:8123/api/hassio_ingress/wQNuZ-q3lFUYZkg3eicz0Im-LpYH4gfZbh-N1btx4ZU/#)
msg :
object
type: "nodered/entity"
server_id: "5d97109.d1423f"
node_id: "26f534a3.dbe4a4"
state: 561
attributes: object
state_class: "measurement"
last_reset: "2021-01-07T08:08:02+00:00"
id: 21

And this is the flow:

[{"id":"a1099869.4fa8","type":"tab","label":"Discovergy","disabled":false,"info":""},{"id":"f179085a.a97cb","type":"inject","z":"a1099869.4fa8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":80,"wires":[["d6489de8.e17808"]]},{"id":"d6489de8.e17808","type":"Discovergy Meter","z":"a1099869.4fa8","name":"Discovergy","account":"XXXXX","meterId":"XXXXXX","firstReading":0,"firstReadingOut":0,"firstReadingDate":"","isProduction":false,"revenue":0,"amortization":0,"prodMeterId":"XXXXX","firstReadingProd":0,"x":370,"y":80,"wires":[["26f534a3.dbe4a4"]]},{"id":"26f534a3.dbe4a4","type":"ha-entity","z":"a1099869.4fa8","name":"Stromverbrauch","server":"5d97109.d1423f","version":1,"debugenabled":true,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Stromverbrauch"},{"property":"device_class","value":"energy"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"kwh"}],"state":"payload.latest.power_w","stateType":"msg","attributes":[{"property":"state_class","value":"measurement","valueType":"str"},{"property":"last_reset","value":"2021-01-07T08:08:02+00:00","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":680,"y":80,"wires":[[]]},{"id":"78286c6c.3d2c84","type":"discovergy-config","name":"Disco1"},{"id":"5d97109.d1423f","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
1 Like

Hm…
I’ve added the last_reset and state_class not via the Attribute Key section. I’ve added them via the Home Assistant Config (optional). Don’t know if this is different on the HA side, but mine isn’t working too, so don’t copy that :smiley:

I’m pretty sure you need to add device_class: energy

I’ve added device_class on my entry, but didn’t help. But I found a solution for this:

Oh and I used payload.latest.energyOut_wh for the result and divided by 1000 to get the kilo result

[{"id":"6b89c0fb.f435e","type":"ha-entity","z":"33c02913.f31f46","name":"KW gesamt","server":"44b2605f.5d41","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Stromzähler"},{"property":"device_class","value":"energy"},{"property":"icon","value":"mdi:counter"},{"property":"unit_of_measurement","value":"kWh"}],"state":"payload","stateType":"msg","attributes":[{"property":"state_class","value":"measurement","valueType":"str"},{"property":"last_reset","value":"1970-01-01T00:00:00+00:00","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"","outputPayloadType":"str","x":1230,"y":60,"wires":[[]]},{"id":"44b2605f.5d41","type":"server","name":"Home Assistant","version":1,"legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"on","connectionDelay":false,"cacheJson":false}]

This node works for me.
The only difference I can see is that you wrote kwh and not kWh

1 Like

And that, Ladies and Gentleman, did the trick. After changing the Unit of Measurement to kWh the sensor was available and could be used in the energy dashboard. Thanks for pointing this out.

2 Likes

Hey,

how must I setup the Node ‘entity’ in graphical mode in Node-RED? My entity look like this, but the Energy-Dashboard can’t find this entity.


Thanks for your help.

Ok, I found the solution myself.
‘state_class’, ‘device_class’, ‘unit_of_measurement’ and ‘last_reset’ should be set as attribut and not in the Home Assistant Config.

2 Likes