Add "Solar Cost Saving" option to native Energy Dashboard

I have a bit of complexity as my electricity buy/ sell prices changes every five minute.

I calculate this as follows:

Benefit/ saving in $/hr.

    - name: Solar Benefit
      unit_of_measurement: $/h
      state: >
       {{states('sensor.apf_solar2house')|float(0) * states('sensor.amber_general_price')|float(0)/1000
       + states('sensor.apf_solar2batt')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000
       + states('sensor.apf_solar2grid')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000}}

    - name: Battery Benefit
      unit_of_measurement: $/h
      state: >
        {{states('sensor.apf_batt2grid')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000
        - states('sensor.apf_grid2batt')|float(0) * states('sensor.amber_general_price')|float(0)/1000
        - states('sensor.apf_solar2batt')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000
        + states('sensor.apf_batt2house')|float(0) * states('sensor.amber_general_price')|float(0)/1000}}

    - name: battery+solar benefit
      unit_of_measurement: $/h
      state: >
        {{states('sensor.battery_benefit')|float(0) + states('sensor.solar_benefit')|float(0)}}

Then a Riemann Sum integration to calculate total $ savings:

Then a utility meter to calcuclate savings as $/ day $/month…

Same for the battery savings $/ day

Then add them together to get a savings for battery+solar $/ month

Pretty up results with ApexCharts
image

14 Likes

Thank you for your work, markpurcell,
but I don’t understand your Configuration.
I mean, I get the idea, but I am wondering what value is in the sensor apf_solar2house: Current Watt, kWh in total? Why does it get divided by 1000?
And I was wondering, how is your Solar Benefit Integral configured (settings)?

Thanks for helping me out :grinning:

apf_solar2house is in W, but amber_general_price is in $/ kWh so I need to divide by 1000 to get $/ Wh

1 Like

Ah okay, that makes sense. Thank you for the explanation :ok_hand:.
So, for the Riemann-Summenintegral, it would be Left Riemann sum, no Metric Prefix and Time h (hours)?

Yes, but give it a go and see if the data is making sense for you.

Isn’t this a duplicate of
Calculate/Display cost savings from self consumed solar energy?

However, I have voted for both of them…

Thanks for sharing this @markpurcell, I’ve been able to use this to help me put together some stats :+1:

1 Like

I think this is an excellent idea for the native energy dashboard to include.

Hi @markpurcell , thanks for the excellent guide!
I was able to follow it and create the sensors & helpers, but struggle with the Apex Chart.
I don’t suppose you’d be willing to share the code for that?

I have extended the charts a little so here is the update:

FB_IMG_1676406289102

type: custom:apexcharts-card
graph_span: 11d
span:
  end: day
stacked: true
header:
  show: true
  title: Battery & Solar Savings
  show_states: true
  colorize_states: true
series:
  - entity: sensor.solar_savings_daily
    type: column
    group_by:
      func: max
      duration: 1d
    show:
      in_header: false
      legend_value: false
  - entity: sensor.battery_savings_daily
    type: column
    group_by:
      func: max
      duration: 1d
    show:
      in_header: false
      legend_value: false
  - entity: sensor.amber_vs_dmo_savings_daily
    type: column
    group_by:
      func: max
      duration: 1d
    show:
      in_header: false
      legend_value: false
  - entity: sensor.abs_savings_daily
    name: Amber+Battery+Solar Savings
    type: line
    stroke_width: 0
    unit: $
    show:
      extremas: true
      in_header: false
      legend_value: false
    group_by:
      func: max
      duration: 1d
  - entity: sensor.abs_savings_monthly
    unit: $
    name: month todate Amber+Battery+Solar
    show:
      legend_value: false
      in_chart: false
  - entity: sensor.battery_savings_monthly
    unit: $
    name: month todate Battery
    show:
      legend_value: false
      in_chart: false
  - entity: sensor.solar_savings_monthly
    unit: $
    name: month todate solar
    show:
      legend_value: false
      in_chart: false
yaxis:
  - id: first
    decimals: 1
    max: 50
    min: 0
    apex_config:
      tickAmount: 2
      logarithmic: false
1 Like

This looks exactly like what i’m looking for.

However, i live in Denmark, where the cost of electricty changes for every hour. How would this be done with that?
I have a two sensors, one that always is the current cost, and one that is the current sales price of electricty.

My prices change every five minutes.

Were you able to follow my logic above?

1 Like

No sorry.
I’m very new to templates, which i’m guessing it is, your solution?

I have these sensors available

sensor.power_meter_consumption
sensor.inverter.daily_yield
sensor.power_meter_exported
sensor.energi_data_service - which is the current price of eletricity, updated every hour.
sensor.nettopower_salg - which is the current SALES price of eletricity, updated every hour.

Can your solution work with these sensors?
@markpurcell

Where do you create this

- name: Solar Benefit
      unit_of_measurement: $/h
      state: >
       {{states('sensor.apf_solar2house')|float(0) * states('sensor.amber_general_price')|float(0)/1000
       + states('sensor.apf_solar2batt')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000
       + states('sensor.apf_solar2grid')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000}}

    - name: Battery Benefit
      unit_of_measurement: $/h
      state: >
        {{states('sensor.apf_batt2grid')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000
        - states('sensor.apf_grid2batt')|float(0) * states('sensor.amber_general_price')|float(0)/1000
        - states('sensor.apf_solar2batt')|float(0) * states('sensor.amber_feed_in_price')|float(0)/1000
        + states('sensor.apf_batt2house')|float(0) * states('sensor.amber_general_price')|float(0)/1000}}

    - name: battery+solar benefit
      unit_of_measurement: $/h
      state: >
        {{states('sensor.battery_benefit')|float(0) + states('sensor.solar_benefit')|float(0)}}

EDIT:
I got something working.
I did this


  - platform: template
    sensors:
      solceller_besparelse:
        friendly_name: "Solcelle besparelse"    
        unit_of_measurement: DKK/h
        value_template: >
          {{states('sensor.solcelle_til_eget_brug')|float(0) * states('sensor.energi_data_service')|float(0)/1000
          + states('sensor.solar_grid_production')|float(0) * states('sensor.nettopower_salg')|float(0)/1000}}
        unique_id: solcelle_besparelse

But this is just a running sensor, it doesn’t calculate my total savings, just what i’m saving right now, this second.

image

EDIT2:
Think i got it, i didn’t know that rieman and utilty meter was helpers xD Never used them
If it doesn’t work, ill get back to you, thanks for the help!

1 Like

Sounds like you should be able to get something working.

Can you post the graphs for each sensor?

Sounds like you want meter_consumption * energi

1 Like

It looks like it’s working now.
There was just alot of new terms i didn’t know about, so i got confused.


I haven’t tried with the apex charts yet, but that’s just gui. As long as the data is there, i’ll manage :smiley:

I am also missing exactly what OP writes. Sad that this is still missing after 15 months. Wondering if there could be any reason not to have it? :thinking:

@severity8714 dane here. Looking for the exact same solution.

What is your nettopower_salg sensor?

Did you just use the Energi data service for price or hour? What about taxes and the above 7000 kr rule for taxation?

Super helpful If you are able to post/explain your solution

I haven’t done anything about the 7000 kr tax rule, since i really don’t expect me to have that amount of payback for my exported power.

My Nettopower_salg sensor is a template i created, using the nordpool integration to calculate the price.
This shows the current sales price to Nettopower, and also the sales price for the next 48 hours, as long as the nordpool sensor also has the next 48 hours (which it usually has)

  - platform: template
    sensors:
      nettopower_salg:
        value_template: '{{ (states("sensor.nordpool_kwh_dk2_dkk_5_10_0")|float - 0.00375 - 0.000875 - 0.04)|round(3, floor) }}'
        friendly_name: "Nettopower salgspris"
        unit_of_measurement: "DKK/kWh"
        unique_id: nettopower_salg
        attribute_templates:
          today: >
            {% if state_attr('sensor.nordpool_kwh_dk2_dkk_5_10_0', 'today') %}
              {% set ns = namespace(prices=[]) %}
              {% for h in range(24) %}
                {% set ns.prices = ns.prices + [(float(state_attr('sensor.nordpool_kwh_dk2_dkk_5_10_0', 'today')[h]) - 0.00375 - 0.000875 - 0.04) | round(3, floor)] %}
              {% endfor %}
              {{ ns.prices }}
            {% endif %}
          tomorrow: >
            {% if state_attr('sensor.nordpool_kwh_dk2_dkk_5_10_0', 'tomorrow') %}
              {% set ns = namespace(prices=[]) %}
              {% for h in range(24) %}
                {% set ns.prices = ns.prices + [(float(state_attr('sensor.nordpool_kwh_dk2_dkk_5_10_0', 'tomorrow')[h]) - 0.00375 - 0.000875 - 0.04) | round(3, floor)] %}
              {% endfor %}
              {{ ns.prices }}
            {% endif %}

Hi @markpurcell

I am trying something like this to use for as long this is not a standard option in the energy dashboard.

I am not getting there completely, I think.
Can you share the settings for the Riemann Sum integration and the Utility meters please?