Energy fixed costs

Maybe it would though cos it’s a cost per the total kWh. not per day.

e.g.

  • 25kVAx118/365x0,130€/kVA)+(1317kWhx0,00560€/kWh)
  • 25kVAx118/365x0,520€/kVA)+(1317kWhx0,02130€/kWh)
  • 1317kWh x 0,00690€/kWh)
  • 640kWh x 0,00690€/kWh)
  • 1957kWhx0,01700€/kWh
  • 1295kWhx0,00007€/kWh
  • 629kWhx0,00007€/kWh

I would just need to template in the day/nigh consumed energy and should count up no?

Absolutely. You can do that.

Same, UK has a ‘standing charge’ per day on top of usage.

2 Likes

+1 to this. I’m in Australia and this daily standing charge is common, it would be amazing to be able to easily just add it.

Vote here… UK standing charges are a thing… Just a fixed cost in pence per day.

1 Like

For gas I have three cost variables.

  1. Rate per Ccf (I have to convert to ft³ see post below)
  2. Daily Customer Charge
  3. Tax

For electricity we have a strange billing option which I’m sort of stuck using. They charge certain rates up to a threshold usage. Then after that they charge additional costs. Sadly Home Assistant doesn’t allow either. It also doesn’t allow me to change the billing period. I can’t get any entities from the Energy Dashboard or I could template a solution myself outside the dashboard.

You can emulate using template sensor and return a value depending of actual consumption.

template:
   - sensor:
      - name: "Energy aditional cost"
        unique_id: energy_aditional
        state: "{{ states('sensor.grid_consumption_period') | float(0) > threshold ? X else Y }}"
        unit_of_measurement: "kWh"
        state_class: total_increasing

1 Like

I don’t have sensor.grid_consumption_period and the Energy panel does not expose anything similar. I would have to recreate some functions of the Energy Panel to make that work.

Is a example name. You need create a sensor of you consuption of period. You can use utily meter and you energy meter to create it.

1 Like

That’s what I meant by the following statement.

When programming you try to never duplicate functions like that. This would be much simpler if the Energy panel exposed entities.

Hello Miguel Ángel,
What exactly does ‘sensor.grid_consumption’ and ‘sensor.grid_exported’ mean?
Right now in kW, monthly, daily, yearly, total since the beginning of time… :wink:

There are the sensors of my Solars Panels. Consumption is the kwh from grid to the house and export house to grid.

Possibility for fixed cost details - Yes please.
Readers, please vote for this (top left of this page). :point_up:

Fixed pricing based on time (month/year) is a thing here in Sweden as well.
I.e. the price is not at all connect to the amount of kWh used. The price is the same if you use 0 or, 10000 kWh.
These things are only connected to time (month/year…)
But, they show up on the electricity bill nevertheless. :face_with_raised_eyebrow:

Perhaps best if we add our fixed prices in cost/hour, so it mesh well with kWh.
But that is easily calculated.

2 Likes

Hello Miquel,

While we’re waiting for your excellent suggestion to be implemented, :smiley: could you share more details on how you set up the “dummy sensor with 0 fixed value and total cost entity”?

I created the template sensor, but when I add it I end up “multiplying by 0” since the sensor use 0 kWh. Resulting in fixed cost of 0, due to the multiply by 0. :roll_eyes:
In other words, could we ask you to show your zero-kWh-sensor-setup - end to end? And please show some code too, if possible.

Also, thanks for suggesting to Home Assistant to include this great feature “out of the box”.

/Richard, from Sweden.

1 Like

Hi!

I created two sensors. First, a dummy sensor that always return 0, for other hand, a sensor that every day sum all my fixed costs

template:  

  - sensor:
     - name: "Potencia y cuota"
       unique_id: Potencia y cuota
       state: 0
       unit_of_measurement: kWh
       device_class: energy
       state_class: total_increasing
  
  - trigger:
      - platform: time_pattern
        minutes: 5
        seconds: 0
        hours: 0
    sensor:  
      name: "Costes fijos"
      unique_id: "costes_fijos"
      unit_of_measurement: "€"
      state_class: total_increasing
      state: | 
        {{ states('sensor.costes_fijos') | float(0) 
          + states('input_number.potencia_valle') | float(0) * states('input_number.precio_potencia_valle') |float(0)
          + states('input_number.potencia_punta') | float(0) * states('input_number.precio_potencia_punta') | float(0)
          + states('input_number.cuota_lidera') | float(0) / 30.0
          + states('input_number.bono_social') | float(0) / 30.0 }}


You must use “total cost entity” so HA don’t multiply, only save the diff.

You only need change the formula for you use (and change the names)

2 Likes

Thank you very much! :+1:

Just a follow-up question. The prices in your

"Costes fijos"

Do you state them as cost per day, or cost per hour, or…?
Just trying to figure out what multiple to use.
For example, 0.16947 (per hour) or 4.067 (per day) (016947 * 24)…

Is cost by day.

If you look the time_pattern, only update one time each day (at 00:05).

And one question for you… 4€ fixed by day?!! My fixed cost by day are 0.42€.

1 Like

Hahaha, very valid question. :smiley:
The “4” in my example is in SEK (Swedish Krona). It is roughly = 0.4€.
So pretty much the same as you.

Thanks again for the crystal clear instructions.
Have a nice day.

1 Like

This workaround won’t be suitable for everyone, but as I have my energy data in influxdb, I use the integration and a flux query to create a sensor that accounts for the standing charge.

- platform: influxdb
  api_version: 2
  ...
  queries_flux:
  - name: import_cost_today
    range_start: "today()"
    unit_of_measurement: "GBP"
    imports:
      - date
    query: |
        filter(fn: (r) => r["_measurement"] == "mqtt_consumer" and r["topic"] == "emon/power/import")
        |> integral(unit: 1h)
        |> map(fn: (r) => ({
            _value: r._value * 0.001 * {{ sensor.daily_rate }} + {{ sensor.standing_charge }},
            _time: r._stop})
         )

Or for a time-of -day tariff:

- platform: influxdb
  api_version: 2
  ...
  queries_flux:
  - name: import_cost_today
    range_start: "today()"
    unit_of_measurement: "GBP"
    imports:
      - date
    query: |
        filter(fn: (r) => r["_measurement"] == "mqtt_consumer" and r["topic"] == "emon/power/import")
        |> window(every: 30m)
        |> integral(unit: 1h)
        |> map(fn: (r) => ({
          _value: if r._stop > date.add(to: today(), d: 5h30m) and r._stop <= date.add(to: today(), d: 23h30m) then 
                    r._value * {{ sensor.peak_rate }}
                  else 
                    r._value * {{ sensor.off_peak_rate }}, 
          _time: r._stop}))
        |> sum()
        |> map(fn: (r) => ({_value: r._value * 0.001 + {{ sensor.standing_charge }}, _time: now()}))

Thanks for the great solution to include fixed costs in the energy dashboard. It works great!

Just to help others, I share a slightly modified approach for the second sensor that is triggered at 00:05.

I update the sensor every hour and changed the calculation from relative (add daily cost at 00:05) to an absolute calculation (hours*hourly_costs)
Reason: If HA is not running during the trigger time (at 00:05), it will miss the daily cost for that day.
For the value, I therefore calculate the hours passed since I started to track fixed cost and multiply that with the costs per hour. So if HA is down, it will catch up later adding the missing hours:

- trigger:
  - platform: time_pattern
    hours: "/1"
  sensor:  
  - unique_id: vastrecht_elektra_per_uur
    name: "vastrecht elektra"
    unit_of_measurement: "€"
    state_class: total_increasing
    state: |
      {% set hours=((as_timestamp(now())-as_timestamp(as_datetime('2023-09-06'))) / 3600)  %}
      {{ (hours+1) * 0.046 }}

Note1: just enter the date of the day you create this sensor
Note2: 0.046 is the total fixed cost per hour for my provider. Of course you can look them up from input helpers, as done in the original. But this is a little more readable.

1 Like