Any good ideas are welcome. Nordpool Energy Price per hour

You have to make one input number helper where you can choose how many hours you need. helper

The preferred way to configure an input number is via the user interface at Settings > Devices & Services > Helpers . Click the add button and then choose the Number option.

OK i am sorry i am kinda new to this and still learning
this is what i got do you have an example what to put there


1 Like

Thank you very much

1 Like

Hi arva, any luck in getting this to work? Looking for exactly the same thing with one addition. I also want a ticker showing total earning (self used Solar + sold Solar) deducted from the total investment of the solar plant.

Yes i did.

Screenshot 2023-11-29 at 12.06.40

Probably took too complex route, but got the result. As i have 3phase system and in Estonia our grid will count every phase separately, meaning that if i export 1kw and 1kw on 2 phases and import 2kw on 1 phase, I still have to pay the tariff on the 2kw. It’s quite unique approach in our country. Usually grid will sum phases.

What you need:

  1. Inverter production power (in my case power for each phase). My huawei is not giving this information and i needed to calculate it from the phases currents:
  - platform: template
    sensors:
      inverter_phase_1_power:
        friendly_name: "Inverter Phase 1 Power"
        unit_of_measurement: "W"
        value_template: >-
          {{ (states('sensor.inverter_phase_a_current') | float * 
              states('sensor.inverter_phase_a_voltage') | float *
              states('sensor.inverter_power_factor') | float) }}

  - platform: template
    sensors:
      inverter_phase_2_power:
        friendly_name: "Inverter Phase 2 Power"
        unit_of_measurement: "W"
        value_template: >-
          {{ (states('sensor.inverter_phase_b_current') | float * 
              states('sensor.inverter_phase_b_voltage') | float *
              states('sensor.inverter_power_factor') | float) }}

  - platform: template
    sensors:
      inverter_phase_3_power:
        friendly_name: "Inverter Phase 3 Power"
        unit_of_measurement: "W"
        value_template: >-
          {{ (states('sensor.inverter_phase_c_current') | float * 
              states('sensor.inverter_phase_c_voltage') | float *
              states('sensor.inverter_power_factor') | float) }}
  1. Power back to grid. I have Shelly EM3 and it gives a power entities for each phase. Negative result means power is going back to grid. I made template sensor that will show value when it’s negative and show it as as a positive number (Note: absolute value would be better than -1)
  - platform: template
    sensors:
      phase_1_power_back_to_grid:
        friendly_name: "Phase 1 Power Back to Grid"
        unit_of_measurement: "W"
        value_template: >-
          {% set power = states('sensor.phase_1_power') | float %}
          {{ [0, power * -1] | max }}

      phase_2_power_back_to_grid:
        friendly_name: "Phase 2 Power Back to Grid"
        unit_of_measurement: "W"
        value_template: >-
          {% set power = states('sensor.phase_2_power') | float %}
          {{ [0, power * -1] | max }}

      phase_3_power_back_to_grid:
        friendly_name: "Phase 3 Power Back to Grid"
        unit_of_measurement: "W"
        value_template: >-
          {% set power = states('sensor.phase_3_power') | float %}
          {{ [0, power * -1] | max }}
  1. Total back to grid power
  - platform: template
    sensors:
       total_power_back_to_grid:
        friendly_name: "Total Power Back to Grid"
        unit_of_measurement: "W"
        value_template: >
          {{ states('sensor.phase_1_power_back_to_grid') | float
          + states('sensor.phase_2_power_back_to_grid') | float
          + states('sensor.phase_3_power_back_to_grid') | float }}
  1. Total own used PV power
  - platform: template
    sensors:
      pv_own_usage_total_power:
        friendly_name: "Total PV Own Usage Power"
        unit_of_measurement: "W"
        value_template: >
          {% set phase_1_power = states('sensor.inverter_phase_1_power') | float %}
          {% set phase_1_back_to_grid = states('sensor.phase_1_power_back_to_grid') | float %}
          {% set phase_2_power = states('sensor.inverter_phase_2_power') | float %}
          {% set phase_2_back_to_grid = states('sensor.phase_2_power_back_to_grid') | float %}
          {% set phase_3_power = states('sensor.inverter_phase_3_power') | float %}
          {% set phase_3_back_to_grid = states('sensor.phase_3_power_back_to_grid') | float %}          
          {{ (phase_1_power - phase_1_back_to_grid) + (phase_2_power - phase_2_back_to_grid) + (phase_3_power - phase_3_back_to_grid)| round(2) }}

  1. Current benefit calculations. Needed for the Utility meter step to start counting. Back to grid I use Nordpool price without VAT. Own usage I use nordpool with VAT + networks tariffs.
  - platform: template
    sensors:
      pv_to_grid_benefit_now:
        friendly_name: 'PV to grid now'
        unit_of_measurement: "EUR"
        value_template: "{{ states('sensor.nordpool_kwh_ee_eur_3_10_0') | float * states('sensor.total_power_back_to_grid') | float / 1000 }}"

  - platform: template
    sensors:
      pv_own_usage_benefit_now:
        friendly_name: 'PV Own Usage Now'
        unit_of_measurement: "EUR"
        value_template: "{{ states('sensor.total_el_price') | float * states('sensor.pv_own_usage_total_power') | float / 1000 }}"
  1. Make Reiman Sum helpers to calculate cumulative benefit from the current benefit entities from last step. Settings > Devices & Services > Helpers > Create Helper > Integration - Reiman sum integral sensor
1.
Name: PV Own Usage Benefit Cumulative
Input Sensor: sensor.pv_own_usage_benefit_now
Integration method: Left
Precicion: 2
Time Unit: hours

2.  
Name: PV to grid cumulative Benefit
Input Sensor: sensor.pv_to_grid_benefit_now
Integration method: Left
Precicion: 2
Time Unit: hours
  1. (optional) Template sensor that will sum the cumulative own use and back to gid together
  - platform: template
    sensors:
      total_pv_all_time_benefit:
        friendly_name: "Total PV All Time Benefit"
        unit_of_measurement: '€' 
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_cumulative') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_cumulative_benefit') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}
  1. So now we have entities that will cumulative current own usage and back to grid benefits. Next step is to make utility meters. You can do it in UI, but i preferres configuration.yaml, as there are quite a few of them (daily, monthly, yearly or all time if you want). Daily and Monthly are needed in my setup to show the apex chart corectly.
utility_meter:
  pv_own_usage_benefit_daily:
    source: sensor.pv_own_usage_benefit_cumulative
    name: PV Own Usage Benefit Daily
    cycle: daily
  pv_to_grid_benefit_daily:
    source: sensor.pv_to_grid_cumulative_benefit
    name: PV to Grid Benefit Daily
    cycle: daily

  pv_own_usage_benefit_monthly:
    source: sensor.pv_own_usage_benefit_cumulative
    name: PV Own Usage Benefit Monthly
    cycle: monthly
  pv_to_grid_benefit_monthly:
    source: sensor.pv_to_grid_cumulative_benefit
    name: PV to Grid Benefit Monthly
    cycle: monthly

  pv_own_usage_benefit_yearly:
    source: sensor.pv_own_usage_benefit_cumulative
    name: PV Own Usage Benefit Yearly
    cycle: yearly
  pv_to_grid_benefit_yearly:
    source: sensor.pv_to_grid_cumulative_benefit
    name: PV to Grid Benefit Yearly
    cycle: yearly
  1. Template to calculate the totals of daily, monthly and yearly benefits
  - platform: template
    sensors:
      total_pv_daily_benefit:
        friendly_name: "Total PV Daily Benefit"
        unit_of_measurement: '€' 
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_daily') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_benefit_daily') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

  - platform: template
    sensors:
      total_pv_monthly_benefit:
        friendly_name: "Total PV Monthly Benefit"
        unit_of_measurement: '€' 
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_monthly') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_benefit_monthly') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

  - platform: template
    sensors:
      total_pv_yearly_benefit:
        friendly_name: "Total PV Yearly Benefit"
        unit_of_measurement: '€' 
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_yearly') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_benefit_yearly') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

  1. Apex chart code:
type: custom:apexcharts-card
graph_span: 31d
span:
  start: month
stacked: true
header:
  show: true
  title: PV Savings Current Month
  show_states: true
  colorize_states: true
series:
  - entity: sensor.pv_own_usage_benefit_daily
    name: Own usage
    yaxis_id: first
    type: column
    group_by:
      func: max
      duration: 1d
    show:
      in_header: false
      legend_value: false
  - entity: sensor.pv_to_grid_benefit_daily
    name: To Grid
    yaxis_id: first
    type: column
    group_by:
      func: max
      duration: 1d
    show:
      in_header: false
      legend_value: false
  - entity: sensor.total_pv_daily_benefit
    name: Total
    yaxis_id: first
    type: line
    stroke_width: 0
    unit: €
    show:
      extremas: true
      in_header: false
      legend_value: false
    group_by:
      func: max
      duration: 1d
  - entity: sensor.total_pv_monthly_benefit
    unit: €
    yaxis_id: second
    name: Total
    show:
      legend_value: false
      in_chart: false
  - entity: sensor.pv_own_usage_benefit_monthly
    unit: €
    yaxis_id: second
    name: Own Usage
    show:
      legend_value: false
      in_chart: false
  - entity: sensor.pv_to_grid_benefit_monthly
    unit: €
    yaxis_id: second
    name: PV to Grid
    show:
      legend_value: false
      in_chart: false
yaxis:
  - id: first
    decimals: 2
    apex_config:
      tickAmount: 2
      logarithmic: false
  - id: second
    show: false

And the result should be like this (Its’ winter in Estonia, so no sun):
Screenshot 2023-11-29 at 12.06.40

And to have investment VS benefit you should to utility meter that will not reset and then compare this number to your investment. Make some template sensor that will just subtract from the investment or does a presentage calculation or if you have bought the PV system with financing compare monthly and yearly cost vs benefit or whatever you can think of.

6 Likes

@arva you’re a ROCK STAR! Thanks for all the effort of writing everything down :100:

1 Like

Old topic, but I just needed the nordpool array prices with tariff. Template to add to the tariff field in UI when aading new nordpool device:

{% set d = {
          "operator_margin": 0.000, 
          "electricity_excise": 0.001,
          "renewable_tariff": 0.0113,
          "nw_fee_night": 0.021,
          "nw_fee_day": 0.0369
      } %}
      {% if now().weekday() in (5, 6) or now().hour < 7 or now().hour >= 22 %}
        {{ ((d.operator_margin + d.renewable_tariff + d.electricity_excise + d.nw_fee_night) * 1.2) | float | round(4) }}
      {% else %}
        {{ ((d.operator_margin + d.renewable_tariff + d.electricity_excise + d.nw_fee_day) * 1.2) | float | round(4) }}
      {% endif %}

@arva In your code / utility_meter you’re referencing to sensor.pv_own_usage_benefit_cumulative and sensor.pv_to_grid_cumulative_benefit, to a noob can you pls explain?

Is there a step between benefit.now and benefit.cumulative?

I added steps 6 and 7. Now should be complete

1 Like

One last question. There isn’t any problem using instant power multiplied with a price per energy? kW * Price/kWh = Price/h, not Price. Am I thinking wrong?

Correct you get current price/h and Reiman Sum will calculate the cumulative cost.

It’s like Reiman sum calculates energy (kWh) from power (w)

Stuff mostly makes sense in my head but I’m not that good explaining it :grinning:. Anyways result is what is expected.

2 Likes

Sorry for the blog being in Norwegian, but i still think it might be of interest.

Another take on the use of Nordpool with a Node-Red and apex chart angle.

Based on ideas from around different forums and www.powersaver.no

1 Like

@arva Fantastic! Thanks a lot

1 Like

Vattenfall Elnät calls it T4 so it is very much relevant but not if you have solar since they pays less for peak hours for feed in with that metering scheme.

I would be intersted this also if someone have solution for this? I would imagine only nordpool and energy consumption sensors are needed. The rest is unclear :smiley:
This would be helpful to see if electricity consumption optimizations have actually helped to save money.

Fantastic work Arva! I have made use of your code with some minor modifications. It all works well apart from the final step where there are no sensors available for the Apex chart. I’m not familiar with utility meters so perhaps I’ve misunderstood how to configure these? As far as I can see there are no sensors generated from the utility meter, e.g. sensor.pv_own_usage_benefit_daily and so forth which the Apex chart requires. Are you able to see what I’m missing or misconfigured please?

I have the following in my configuration.yaml :

utility_meter:
  pv_own_usage_benefit_daily:
    source: sensor.solpaneler_fortjanst_egen_konsumtion
    name: Förtjänst från användning av solpaneler
    cycle: daily
  pv_to_grid_benefit_daily:
    source: sensor.solpaneler_forsaljning
    name: Förtjänst från försäljning av solenergi
    cycle: daily
  pv_own_usage_benefit_monthly:
    source: sensor.solpaneler_fortjanst_egen_konsumtion
    name: Förtjänst från användning av solpaneler
    cycle: monthly
  pv_to_grid_benefit_monthly:
    source: sensor.solpaneler_forsaljning
    name: Förtjänst från försäljning av solenergi
    cycle: monthly
  pv_own_usage_benefit_yearly:
    source: sensor.solpaneler_fortjanst_egen_konsumtion
    name: Förtjänst från användning av solpaneler
    cycle: yearly
  pv_to_grid_benefit_yearly:
    source: sensor.solpaneler_forsaljning
    name: Förtjänst från försäljning av solenergi
    cycle: yearly
  - platform: template
    sensors:
      solpaneler_egen_konsumtion:
        friendly_name: "Egen konsumtion från solpaneler"
        unit_of_measurement: "kW"
        value_template: >
          {% set energy_produced = states('sensor.inverter_daily_yield') | float %}
          {% set energy_back_to_grid = states('sensor.electricity_meter_energiproduktion') | float %}      
          {{ (energy_produced - energy_back_to_grid)| round(2) }}

sensor:
  - platform: template
    sensors:
      solpaneler_forsaljning:
        friendly_name: "Försäljning av el från solpaneler"
        unit_of_measurement: "SEK"
        value_template: "{{ states('sensor.nordpool') | float * states('sensor.electricity_meter_energiproduktion') | float / 1000 }}"

  - platform: template
    sensors:
      elpris_totalt:
        friendly_name: "Total energikostnad vid inköp"
        unit_of_measurement: "SEK"
        value_template: >
          {% set spotpris = states('sensor.nordpool') | float %}
          {% set energiskatt = 0.535 | float %}     
          {% set elbolagspaslag = 0.04 | float %}   
          {% set elnatsavgift = 0.289 | float %}     
          {{ (spotpris + energiskatt + elbolagspaslag + elnatsavgift)| round(2) }}

  - platform: template
    sensors:
      solpaneler_fortjanst_egen_konsumtion:
        friendly_name: "Förtjänst ur egen konsumtion från solpaneler"
        unit_of_measurement: "SEK"
        value_template: "{{ states('sensor.elpris_totalt') | float * states('sensor.solpaneler_egen_konsumtion') | float / 1000 }}"

  - platform: template
    sensors:
      solpaneler_total_fortjanst:
        friendly_name: "Total förtjänst från användning och försäljning från solpaneler"
        unit_of_measurement: "SEK"
        value_template: >
          {% set pv_own_usage = states('sensor.solpaneler_fortjanst_egen_konsumtion') %}
          {% set pv_to_grid = states('sensor.solpaneler_forsaljning') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

  - platform: template
    sensors:
      total_pv_daily_benefit:
        friendly_name: "Daglig förtjänst från solpaneler"
        unit_of_measurement: "SEK"
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_daily') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_benefit_daily') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

  - platform: template
    sensors:
      total_pv_monthly_benefit:
        friendly_name: "Månatlig förtjänst från solpaneler"
        unit_of_measurement: "SEK"
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_monthly') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_benefit_monthly') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

  - platform: template
    sensors:
      total_pv_yearly_benefit:
        friendly_name: "Årlig förtjänst från solpaneler"
        unit_of_measurement: "SEK"
        value_template: >
          {% set pv_own_usage = states('sensor.pv_own_usage_benefit_yearly') %}
          {% set pv_to_grid = states('sensor.pv_to_grid_benefit_yearly') %}
          {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %}
          {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %}
          {{ (pv_own_value + pv_to_grid_value) | round(2) }}

1 Like

Everything looks good. Did it pass the “check configuration” before restart?

  1. Check if the source sensors (like sensor.solpaneler_fortjanst_egen_konsumtion and sensor.solpaneler_forsaljning ) are available and providing data. I guess you are in sweden and maybe it’s just that there is no sun or panels under snow and therefore no solar production? Also it might be that it takes a little time for utility meter to start counting.
  2. Look at the Home Assistant logs for any errors related to your utility_meter configuration. This can provide clues if something is wrong with the setup.

Thanks for the quick reply!

Yep, it did pass the “check configuration” before restart. I checked the source sensors you’ve mentioned and for sensor.solpaneler_fortjanst_egen_konsumtion it did return a value (1,76). For the other, sensor.solpaneler_forsaljning, it only returned 0,00 (which ought to be correct as I had no power back to grid that day… The small amount power generated was consumed by my house. So your guess in terms of Sweden and snow are indeed correct :)).

The utility_meter has unfortunately still not created any sensors. I also had a look in the logs for this but did not find anything. However after a restart today I noticed below log entries which perhaps might be the issue? I’m not a programmer but I’m guessing it has to do with the invalid input ‘unavailable’ that appears for each of the entries?

TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{% set energy_produced = states('sensor.inverter_daily_yield') | float %} {% set energy_back_to_grid = states('sensor.electricity_meter_energiproduktion') | float %} {{ (energy_produced - energy_back_to_grid)| round(2) }}' but no default was specified') while processing template 'Template<template=({% set energy_produced = states('sensor.inverter_daily_yield') | float %} {% set energy_back_to_grid = states('sensor.electricity_meter_energiproduktion') | float %} {{ (energy_produced - energy_back_to_grid)| round(2) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.solpaneler_egen_konsumtion'
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ states('sensor.nordpool') | float * states('sensor.electricity_meter_energiproduktion') | float / 1000 }}' but no default was specified') while processing template 'Template<template=({{ states('sensor.nordpool') | float * states('sensor.electricity_meter_energiproduktion') | float / 1000 }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.solpaneler_forsaljning'
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{{ states('sensor.elpris_totalt') | float * states('sensor.solpaneler_egen_konsumtion') | float / 1000 }}' but no default was specified') while processing template 'Template<template=({{ states('sensor.elpris_totalt') | float * states('sensor.solpaneler_egen_konsumtion') | float / 1000 }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.solpaneler_fortjanst_egen_konsumtion'
TemplateError('ValueError: Template error: float got invalid input 'unavailable' when rendering template '{% set pv_own_usage = states('sensor.solpaneler_fortjanst_egen_konsumtion') %} {% set pv_to_grid = states('sensor.solpaneler_forsaljning') %} {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %} {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %} {{ (pv_own_value + pv_to_grid_value) | round(2) }}' but no default was specified') while processing template 'Template<template=({% set pv_own_usage = states('sensor.solpaneler_fortjanst_egen_konsumtion') %} {% set pv_to_grid = states('sensor.solpaneler_forsaljning') %} {% set pv_own_value = 0 if pv_own_usage == "unknown" else pv_own_usage | float %} {% set pv_to_grid_value = 0 if pv_to_grid == "unknown" else pv_to_grid | float %} {{ (pv_own_value + pv_to_grid_value) | round(2) }}) renders=4>' for attribute '_attr_native_value' in entity 'sensor.solpaneler_total_fortjanst'```

Hi. Sorry for being lazy and used ChatGPT but here is the aswer:

The error messages you’re encountering in your Home Assistant configuration are due to the float filter receiving ‘unavailable’ as input. When a sensor’s state is ‘unavailable’, ‘unknown’, or any non-numeric string, attempting to convert it directly to a float will result in a ValueError. To address this, you need to modify your template sensors to handle such cases gracefully.

Here’s how you can update your templates to handle ‘unavailable’ or ‘unknown’ states:

  1. For sensor.solpaneler_egen_konsumtion:
value_template: >
  {% set energy_produced = states('sensor.inverter_daily_yield') | float(default=0) %}
  {% set energy_back_to_grid = states('sensor.electricity_meter_energiproduktion') | float(default=0) %}      
  {{ (energy_produced - energy_back_to_grid) | round(2) }}

  1. or sensor.solpaneler_forsaljning:
value_template: >
  {% set nordpool_price = states('sensor.nordpool') | float(default=0) %}
  {% set energy_back_to_grid = states('sensor.electricity_meter_energiproduktion') | float(default=0) %}
  {{ nordpool_price * energy_back_to_grid / 1000 }}

  1. For sensor.solpaneler_fortjanst_egen_konsumtion:
value_template: >
  {% set total_price = states('sensor.elpris_totalt') | float(default=0) %}
  {% set own_consumption = states('sensor.solpaneler_egen_konsumtion') | float(default=0) %}
  {{ total_price * own_consumption / 1000 }}

  1. For sensor.solpaneler_total_fortjanst:
value_template: >
  {% set pv_own_usage = states('sensor.solpaneler_fortjanst_egen_konsumtion') | float(default=0) %}
  {% set pv_to_grid = states('sensor.solpaneler_forsaljning') | float(default=0) %}
  {{ (pv_own_usage + pv_to_grid) | round(2) }}

In these templates, I used | float(default=0) which converts the state to a float, but if the state is ‘unavailable’, ‘unknown’, or any non-numeric string, it defaults to 0. This way, your calculations won’t break if a sensor is temporarily unavailable or returns an unexpected value.

After making these changes, ensure to check the configuration and restart Home Assistant for the changes to take effect.

However this does not explain why Utility Meter entities are not created. Could it be that you have utility_meter: twice in your configuration.yaml? If you use utility_meter: twice or more in your configuration.yaml, it will take acocunt only the last one. Same apllies when you use sensor: