Thanks a lot for this genius hack! Rather than distributing the supply charge throughout the day, I tried to keep it simple and create a spike when the time transitions to the next day. Also I can use the supply charge cost from my energy retailer as is.
Hi @aksvenk, this approach is fine, except you must remember by doing it this way you are adding 1kW to your power consumption every day, which may be significant in your overall consumption. My average daily usage is about 15kW so this would introduce a margin of error of about 6-7% every day.
Thatās why I divided it by 1000, so Iām only adding 1w per hour which is negligible and an error margin of about 0.1%. I chose 1w because it seems to be the lowest unit of power HA will allow.
In your case if you mutliply the charge by 1000 and divide the sensor by 1000, it would only be 1w per day which would be even better.
Good point @muzzak. The supply charge shows up as a separate line item so Iām not too fussed.
But I see what you mean especially when we are tracking monthly / yearly totals.
As per your suggestion, Iāll change the above unit to Wh and then multiply the supply charge by 1000.
Hi Michael,
Yes thatās correct, as per the yaml standards one heading with utilities as subentries beneath indented or a reference (as I have done) to a separate file for your multiple utility entries.
Thanks,
Sean
I find all the solutions above a bit more complicated than they need to be. Hereās what I did:
template:
- trigger: # rate-limit the template a bit, which would otherwise re-calculate every minute
- platform: time_pattern
hours: "*" # calculate hourly should be fine
sensor:
# Increases every day by 1W to fake a daily supply charge in energy dashboard.
- state: >-
{{ 0.001 * (now() - "2022-09-26" | as_datetime | as_local).days }}
unit_of_measurement: kWh
state_class: total_increasing
device_class: energy
unique_id: CHANGE_ME_TO_ANYTHING_JUST_MAKE_IT_UNIQUE
name: "Daily supply charge"
Just set the date "2022-09-26" to the day or day before whenever you add this, so it doesnāt have a big jump on the first entry.
Then I just added it directly as a type of grid consumption with a fixed price set to 1000x my real daily supply charge:
With total_increasing, I think it could even work to just have a sensor which toggled between 0 and 1 every 12 hours as the 0 will be interpreted as a start of new cycle, but I havenāt tested that.
thanks for sharing your solution. i went with yours, however my daily supply charge does not increase by the hour. It froze on 0,001 kWh. Besides changing the ID and the date, i did not change your code. Date & Time sensors are added to the config. No errors in the log.
Any idea whats wrong here? thanks
edit. sorry maybe i am confused. This counter should be increased each day or each hour? i thought it would be each hour but then it wouldnāt show due to decimal numbers i guess.
I thought that this was the issue but i think 0,001 kWh is indeed correct as only one day has passed. Though, my energy meter neither shows cosumption nor price for that entity.
Somethings strange here
hm itās kinda strange. I now checked on it again. it jumped from 0,001 to 0,002 at 2 PM local time. Though i have to admit i fiddled around with it and set the starting date to 2022-09-28. I initially deployed it however around 12 AM, at least thats when it started to tick to 0,001.
So as for now, it seems that it started ticking on its first regular basis on 2 PM. It produces a single bar in the engergy meter and i am not sure if thats now for the whole day, or only for 1 hour. If itās meant to be for the whole day, then the costs would be incorrect.
oh damn. I miscalculated my total supply charge when recalculating the other way around. Itās works out perfectly for me!
So two questions remain for me:
is it possible to have it calculated on an hourly basis. I think not, as i read that the factors in the energygrid would not allow that many decimal numbers. is that true? more granular distribution would be nice
any idea how i can shift that supply charge at least to hour 0, or hour 1 of the day ? i know itās mostly cosmetics but i am a sucker for stuff like that.
generally, i think this should be implemented by the hass team natively by now. i have not heard of a single energy bill which has no basic charge, supply charge, service charge or network fees.
Hi all. In theory, you could have calculate the number of hours instead of days between now and the starting date, but then youāll have to make sure the price you give the entity also adjusts it by a factor of 24.
Personally, I donāt think this makes sense to do as itās not what the energy retailer does (at least not the ones Iām familiar with).
I also had mine update around 2pm and I donāt know why that is. It might be something to do with when the HA energy dashboard does statistics calculations or it might be something to do with time zones perhaps. I havenāt looked into it because all I really cared about is that it increments by my supply charge once within a 24 hour window and that I have the statistics over the longer term.
In the morning, this will register 1W and in the afternoon 0W. This should work because of state_class: total_increasing which, according to these docs carry the semantics of:
A decreasing value is interpreted as the start of a new meter cycle or the replacement of the meter.
If this works, then it will mean there is no need to customise the template for each time it is set-up by a new person.
What price did you give the entity when you added it to the energy dashboard? Did you multiply it by 1000 as per my instructions?
If your daily supply charge were Ā£1/kWh, then this would only be 0.2p so far. Youād have to add this entity at Ā£1000/kWh, since we are only incrementing a single watt per day with this approach.