I’m quite new to this, but I tried to configure the energy consumption using my own “pulse counter” and mqtt. I get kWh reading from mqtt at 30s interwall. It is working OK.
Now I tried to add this to HA Home Energy Management.
In my configuration YAML I have this:
----------------------------------------------------------------cut-----------------------------------------------------------
No more complaining about anything, but the sensor.saarnitie_sahkon_kulutus will not get any value.
The state: >
{{ states(“sensor.mains_consumed_energy”) | float | round(2) }}
must be wrong, but how to fix?
It is hard to tell with the code pasted in the message directly and not inside a code block. Can paste the code inside a </> block?
Also you should check the unique id of the first sensor. It is missing the right prefix, so it may have gotten a different unique_id alltogether. I’m guessing sensor.sahkon_kulutus
It was missing the “sensor.” prefix. But I’ve also seen the entry in yaml being ignored and the unique_id being generated from the name. Hence my guess. That can also have been the case here. In that case you can always change it in the gui if you do not like what was autogenerated.
Yes, both sensors (sensor.mqtt_sahkon_kulutus and sensor.saarnitie_sahkon_kulutus) have the same value. I will try the total_increasing and lets see how it goes.
With total_increasing I have this in log:
Entity sensor.mqtt_sahkon_kulutus from integration mqtt has state class total_increasing, but its state is not strictly increasing. Triggered by state 2.52 (2.64) with last_updated set to 2022-05-30T15:35:11.987589+00:00.
Still not working. I have made small changes to configuration.yaml, but I do not think they matter.
I also deleted file .storage\energy, then restarted HA and reconfigured the energy management.
Blockquote
I have no idea what it’s like with an MQTT sensor, but what I have Shelly, Esphome (api) sensors have all the attributes state_class: total_increating
I tried that earlier, but it did not help.
This topic however had the solution:
I changed the last_reset to a random value, but not the c-language “zero”, that it used to be:
First of all, I’ll say that I don’t really know what the answer is but wanted to share some pieces of information.
I recall there were changes made sometime last year regarding the last_reset so that post you referenced may or may not work.
Here is a web page that might help (or may confuse you even more), and at this particular place on the page it says that state_class: measurement can’t be used with device_class: energy. Again, I don’t know if this is accurate, and others have somehow gotten this to work with Energy Management, but that’s what it says.
Also check your log as they made a change to the code to print out a log warning if last_reset was also used with state_class: measurement.
OK, now i’m getting values. But these setting are not right for my energy sensor. I’m counting led blinks from energy meter and then calculating what the measured number of pulses means as kWh. The calculated value is sent through mqtt to HA sensor every 60 seconds. So the state_class: total is not right.
If I change my mqtt sensor and sensor.saarnitie_sahkon_kulutus state_class back to measurement,
then I get error on my energy dashboard settings page, that sensor is missing last_reset.
This I do not understand, since measurement state_class is current value. Why should that have last_reset???
With state_class: measurement I do not get any values to energy management page??
So, experimenting continues, or does anyone have solution to my problem?
I have solved this another way. Now I get the number of pulses (led blinks) from my energy meter to a mqtt sensor in HA. Then add these pulses to ( 1 pulse is 1 Wh so I divide by 1000 to change unit to kWh) utility meter and use that as energy management source.