Calculating PV saving using house consumption and Nordpool last hour price

HI, I’ve tried googling this but come up with nothing.

I have solar panels installed (PV), Huawei VR + battery and run Home Assistant.
I’ve successfully integrated Huawei VR into HA and I’ve built a sensor measuring how much energy the house is consuming from the PV and Battery installed.

What I want to achieve is to calculate how much the power I save would have cost me if I had bought it. Currently I only see the money I get for what I sell, and the money I pay for energy bought.
But none of these really reflect what I saved using my own created power.

My plan was to create one sensor looking at Nordpool last hour rate.
Something like “sensor.nordpool_previous_hour”.

Then run a utility meter on my house solar consumption.

5 min after each hour, I multiply the last hour consumption and the nordpool_previous_hour cost and add this to a “saved today” sensor.
This bit I can probably do in the “helper section”.

But I’m stuck trying to get the previous hour value out of Nordpool.
The discussions I found are all about finding the cheapest hour. I don’t want that, I just want the previous hour rate.

Someone? Please?

Hi, I don’t use Nordpool, but I found this in the information page for the integration:

Other

One sensor per hour

By default, one sensor is created with the current energy price. The prices for other hours are stored in the attributes of this sensor. Most example code you will find uses the default one sensor option, but you can run the create_template script to create separate sensors for every hour. See the help options with python create_template --help. You can run the script on any system where Python is installed (install the required packages pyyaml and click using pip install pyyaml click)

So - perhaps you could look at the attributes of your existing Nordpool sensor* and see if one of the attributes is the previous hour’s price. If it’s there, you should be able to create a template sensor that has its state equal to the value of the attribute in question. There are plenty of online resources for learning templating and many in this community who could assist if needed. (I’m a novice at this…) There is also a very nice template editor in Developer Tools. :upside_down_face:

*in Developer Tools>States

Best wishes.

thank you, but I’m not sure I understand where to begin.
I’ve made a little more progress… I think. see below

I’ve created an “input_number” via the GUI helper section called “nordpool_previous_hour”.

I’ve also created an automation via the GUI that 1min to each whole hour write the current nordpool price to this input_number.nordppol_previous_hour.

1min past the whole hour I intend to use the “last_period” attribute value of my house solar consumption meter and multiply it with the input_number above.
The result I will store/add in another input_number.house_solar_saving_last hour.
This value will also be added on to a “saving_today”.
By doing this 1min past each hour, the input_number.house_solar_saving_today increases.

I can then add another automation that store/add each day to a monthly counter.

Not sure if this is an elegant solution or not, but it may be something I at least stand a change of understanding :slight_smile:

My problem right now to move forward:
I have a problem where the last hour price is multiplied with the last hour energy consumption. But I’m not sure what the issue is? I’m partly creating this in “helper section” but switching to YAML for modify the input_value.set_value sections as this can only be a number in the “helper GUI”.
I get this error:

please see code below

Thank you for any assistance, anyone :slight_smile:

alias: Besparing Solel - varje timme
description: ""
trigger:
  - platform: time_pattern
    minutes: "1"
condition:
  - condition: numeric_state
    entity_id: sensor.house_consumption_solarenergy_test_hourly
    above: 0
action:
  - service: input_number.set_value
    data: >-
      { states('input_number.nordpool_previous_hour')  | float(3) *
      state_attr('sensor.house_consumption_solarenergy_test_hourly',
      'last_period') | float(3)}
    target:
      entity_id: input_number.house_solar_saving_last_hour
  - service: input_number.set_value
    data: >-
      {states('input_number.house_solar_saving_last_hour') | float(3) +
      states('input_number.house_solar_saving_today') | float(3)}
    target:
      entity_id: input_number.house_solar_saving_today
mode: single

Edit:
When trialing this in the developers section, it seems to calculate the hourly cost saving correct.

I’m a bit over my head here, but I think this may be primarily a formatting issue. I’m more familiar with using value: “{{ xxx }}” rather than data: { xxx }. Hopefully someone more knowledgeable will be able to help.

Here is a guess at what might work. Note that I’m unable to test the template since I don’t have the integration/sensors. Be careful with nesting of double and single quotes - it has caused me problems before. Best wishes!

action:
  - service: input_number.set_value
    data_template:
      entity_id: input_number.house_solar_saving_last_hour
      value: "{{ states('input_number.nordpool_previous_hour') | float * state_attr('sensor.house_consumption_solarenergy_test_hourly', 'last_period') | float }}"
  - service: input_number.set_value
    data_template:
      entity_id: input_number.house_solar_saving_today
      value: "{{ states('input_number.house_solar_saving_last_hour') | float + states('input_number.house_solar_saving_today') | float }}"
mode: single

How was this resolved? I’m working on a similar counter, but I’m stuck with setting the last hour price value to input_number with automation. Could you possibly share a screenshot of your automation.yaml?