Energy - How to account for daily standing charge?

Thanks Sean. Your instructions are spot on and I have all set up. I will now look at adding sensors that have been created to Energy platform. Thanks once again for your response.
All the best
Ian

1 Like

@sean.mcgee - thanks a great work around - just to note:

only one call to utility_meter can be made in the configuration files and only the last call to utility meter is used I therefore have all my utility meters in the utility_meter.yaml or the main configuration.yaml

1 Like

I always screw this up:

What should come before this?

Should it be

sensor:

  • platform: template
    sensors:

Can someone point me to a good source in understanding why I struggle with this?

@NieropT Hi Thijs, I know what you mean. It can be confusing so I’ll try to help.
Home Assistant has sensors which I think of as measuring things at the base level. eg Temperature, Voltage etc.
These are prefixed with

sensor:

Quite often however you need to convert the sensor data into something more meaningful and derive a new value from the sensor data. A simple example might be:
If the time is < noon then AM else PM
This is called a template and these are prefixed with

template:

For a template you then have to define what sort of template it is, eg sensor, binary_sensor.
In my example I want to use the template to create a new sensor so the whole thing will be

template:
  - sensor:
    - name: "Supply Charge"
      unit_of_measurement: "kWh"
      device_class: energy
      state_class: total_increasing
      state: >-
       {{ (((as_timestamp(states('sensor.date_time_iso')) / 3600)-454585) | int) / 1000}}
      attributes:         
        last_reset: '1970-01-01T00:00:00+00:00'

Hope this helps

1 Like

Legend. Thank you very much.

Thanks Sean. I made two changes to your setup - I set the step to 0.001 kWh instead of 1 kWh in the input number, and then set the charge in the Grid Consumption source to be 1000 x the daily charge. This works really well, I am now having the daily charge accrue but without the 1 kWh up/down spike appearing on the graphs and affecting the %s or amounts in the distribution diagrams.

2 Likes

Thank you for the instructions. I just followed them but the sensor.daily_correction_hs_count has no device_class: energy (like on your screenshot) . That is why I can’t add it to the Homeassistant energy config.
Did I miss something?

EDIT: Nevermind it worked after the first increment this night. THANK you

alias: Increment kWh
description: ''
trigger:
  - platform: time
    at: '00:01'
1 Like

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.

template:
  - sensor:
      - name: "Supply Charge"
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: >
          {{ (as_timestamp(states('sensor.date_time_iso')) / 86400) | int }}

Will this come and bite me in later on somehow?

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

Thank you @muzzak for this. I was stumped at first with an error but that was soon resolved with the addition of:

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

Cheers
Simon

1 Like

Yes @simonranson, good point. I should have mentioned you need the Time and Date integration as well Time & Date - Home Assistant

Hi @muzzak @aksvenk I’m trying to get this code working but the daily cost is zero.

Please are you able to share to final code for the once off daily “spike” - i prefer this option than the cost calculation over the entire day.

Also what “static price” do you use in the Supply Charge for the Grid Consumption dashboard using this approach?

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:

This only adds 1W of “fake” usage and will update daily without any automation or need for a utility meter entity.

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.

9 Likes

Just wanted to say thanks for this, been trying unsuccessfully to use other methods but this is quick, easy and reliable. Cheers!

1 Like

Hi Bo,

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 :frowning:

1 Like

Same here, but I assumed that it would stay at 0.001kWh every day and multiply by the fixed cost * 1000
But I get zero in my cost

1 Like

Same issue here:
zero cost showing in the energy sources page
Daily supply charge 0 kWh €0.00

And the entity has got a value of 0.001
Daily supply charge - 18 hours ago - 0.001 kWh

Any ideas?

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.

I am a bit confused to be perfectly honest.