I have a strange behatvior on my utility meter that, at some point, starts giving strange values on templated sensors.
For instance, I have a sensor called “total electricity consumption” which is the sum of day & night consumptions, where the utility meter jumps into millions.
Did the same with a simple rounding of my solar production:
Whenever the state of sensor.total_yield is unknown, like right after a home assistant restart, the |float filter returns 0 then the template jumps the the correct value when the state is available.
This effectively doubles the the value stored by the utility meter as it sees the increase from 0 to whatever the current state is.
This solution seems to be exactly what I need but I can’t seem to get it to work.
I am trying to avoid the problem whilst also calculating my energy usage to include a standard charge.
The latter bit works fine but I still fall victim to the underlying energy sensor periodically being in an unknown state, which is interpreted as zero and then causes a huge jump when the next reading comes in.
I have tried a couple of things:
Firstly, creating the utility meter based on the raw energy sensor then creating a template based on utility meter to calculate the costs and work around sensor availability:
Annoyingly both of these approaches have yet to yield any issues when calculating Gas costs (presumably because the sensor has never been unavailable/unknown as yet). Any help much appreciated. I’m fairly new to all this so hopefully someone will spot a schoolboy error in the above!
Hi, sorry for not noticing your reply until now. I haven’t been able to get it working the way I want, i.e. with utility meters. However, I have managed to get the energy panel showing me all the info I was trying to recreate with my own sensors. Its been working perfectly for the past 4 weeks. The reason I wasn’t using the energy dashboard in the first place was because:
I couldn’t incorporate the daily standing charges
My gas meter integration via Smartthings was causing errors
If either of those problems are relevant to you then…
I found a really helpful post here that I used as a basis for the standing charges and I’ll paste my config below in case that helps too. The Smartthings problems were multiple and included the use of kWh instead of M3 for the units and wrong device class. I managed to just work through these. Again, if this is relevant to you then see my code below.
No worries thanks for the reply.
I have managed to get something working by creating peak and off-peak utility sensors and created additional sensors to add them together and include the standing charge like this and repeated it to weekly and monthly.
But I like the way you’ve done that.
I noticed on your input boolean for electric you put the unit of measurement as kWh is that right ? As I thought that sensor was to calculate the standing charge which will be in GBP ?
I need to put more effort into the energy dashboard as I’ve been trying for days now to get some decent graphs for the utility sensors but can’t get any I like and the apex charts I’ve seen confuses me ha ha.
Hi, yes, its a bit of a workaround essentially treating the standing charge as if it was another source of kwh. This does mean that your totals will be out by 0.001kwh per day but i can live with that. I didn’t like it initially but after spending ages trying to do something better I gave up!
After 28 days of my energy setup working perfectly, I got a zero registered for Gas late on the last day of February which messed up that month and then messed up March when it started working again a couple of hours later.
Will try the approach mentioned here (to take the previous value if the current one is zero) to see if this helps. Here’s my updated config:
template:
- sensor:
- name: "Gas Meter m3"
unit_of_measurement: "m³"
device_class: gas
state_class: total
state: >-
{% set value = states('sensor.bulb_energy_meter_gas_meter') | float %}
{{ value * 0.08912153 if value else states('sensor.bulb_energy_meter_gas_meter') }}