Howto: Fronius Integration with battery into Energy Dashboard

here my code which worked with Fronius Symo Hybrid 5.0.5 (not gen24)
Add this in configuration.yaml

#FroniusEnergyDashboard
template:

  • sensor:
    • name: “Battery Power Charging”
      unit_of_measurement: W
      device_class: power
      state: “{{ max(0, 0 - states(‘sensor.solarnet_power_battery’) | float(default=0)) }}”
    • name: “Battery Power Discharging”
      unit_of_measurement: W
      device_class: power
      state: “{{ max(0, states(‘sensor.solarnet_power_battery’) | float(default=0)) }}”
    • name: “Power Photovoltaics”
      unit_of_measurement: W
      device_class: power
      state: “{{ states(‘sensor.solarnet_power_photovoltaics’) | float(default=0) }}”

sensor:
- platform: integration
source: sensor.battery_power_charging
name: “Total Battery Energy Charged”
unit_prefix: k
method: left
- platform: integration
source: sensor.battery_power_discharging
name: “Total Battery Energy Discharged”
unit_prefix: k
method: left
- platform: integration
source: sensor.power_photovoltaics
name: “Total Photovoltaics Energy”
unit_prefix: k
method: left

Question.

how to add Car charging bubble ?

Hello,
I am totally newb and I am having big problem with this integration.

My system is composed by

Symo 5 (produce only)
GEN 24 (bidirectional)
BYD batteries
Smart Meter.

I am trying to understand how to implement these system but, the entities from the integration are with Italian names (I don’t know how to set them in english to match with yours) and am I having all different /wrong values from the sensors/helpers.
I am going crazy…

Could you help me?

The first thing I learned is that I need to create a template for the Symo production because at night the entity become unavailable instead of zero.
Is it so? or should I use a different data?

this is my template in located in:

homeassistant:
  packages: !include_dir_named packages

file: packages/fotovoltaico.yaml

template:
  - sensor:
      - name: "fotovoltaico_batteria_in_ricarica"
        unit_of_measurement: W
        device_class: power
        state: "{{ max(0, 0 - states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') | float(default=0)) }}"
      - name: "fotovoltaico_batteria_in_uso"
        unit_of_measurement: W
        device_class: power
        state: "{{ max(0, states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') | float(default=0)) }}"


sensor:
    - platform: integration
      source: sensor.fotovoltaico_batteria_in_ricarica
      name: "fotovoltaico_calc_batteria_in_ricarica"
      method: left
    - platform: integration
      source: sensor.fotovoltaico_batteria_in_uso
      name: "fotovoltaico_calc_batteria_in_uso"
      method: left

If I add these sensors to the battery in energy dashboard I have some system warning/error (wrong data and I think for the unknown state)
Also, I have mismatching between the data from the template and data from the test helper I created using the Riemann left integral sum, also the “battery in charge” is “unknown” and I don’t know why

These are the values from the 6 integrations:

GEN 24

SYMO 5

SmartMeter and BYD battery

Hello, finally I get it work!
the only issue I have is on the house power calculation.

I used the code below to create a custom sensor to create this part

      # consumo casa
      # --------------------
    - name: fotovoltaico_consumo_casa
      unique_id: c05adba4-18c0-11ee-be56-0242aca200aa
      device_class: power 
      unit_of_measurement: W 
      icon: mdi:home-lightning-bolt
      state: "{{ 
                (
                states('sensor.fotovoltaico_potenza_attuale_totale')|float(default=0)  
                +
                (
                states('sensor.fronius10kw_solarnet_batteria_di_alimentazione')|float(default=0)
                + 
                states('sensor.fronius10kw_solarnet_rete_elettrica')|float(default=0)
                )
                )|float(default=0)|float|round(1)
              }}"

It works but sometimes I have some negative spikes, how could I solve?

The issue is because I have 2 values from total solar production in short period and the system uses the first

Instead of use the second value 10.282,6 the system uses the first value 6276, so the calculation is:

6276 +      //  total solar production    
-2500,7 +   // sent to the main grid
-7548,87 +  // battery charging (even if I think it is too high)
= -3773,57  // house consumption (fake because it is negative)

instead of:

10282,6 +    //  total solar production 
-2500,7 +    // sent to the main grid
-7548,87 +   // battery charging (even if I think it is too high)
= 233,03     // house real consumption (fake.. bacause my base consumption is always around 500W)

Is there a way to calculate a mini mean to get values stable?

Maybe you can work only with sensors coming from the power_flow endpoint. Those should always be updated at the same time (and more often than inverter values).

It is not clear, what do you mean?
In my prev post there is all data I get from the 2 inverters the smart meter and the byd battery

In meantime I added some checks to all main sensor I am using for calculations etc to see if the sensor return a number or string like “undefined”, “unknown”, “”, etc
Something like this:

      # Batteria
      # --------------------
    - name: fotovoltaico_batteria
      unique_id: 5db8f06d-7f47-436c-92cd-a9be09099939
      unit_of_measurement: W
      device_class: power
      state: "{% set var_batteria = states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') %}{{ (var_batteria | float) | round(3) if is_number(var_batteria) else 0 }}"

I mean, use entities from the “SolarNet” device, not from the inverter device (if there are suitable - I’m not 100% sure).
Unfortunately since entity name translation it is hard to see which entities you are using or to suggest an entity name :grimacing:

Ah ok, thanks for the explanation.
I know, translations are even my problem because the inverters creates entity in Italian so it was hard to me to figure out (since I am not an electrician or an expert) the correct sensors to use.

I am already using the solarnet entities, all the fotovoltaico_* are my template from those sensors.

These are my updated (I have updated them an hour ago) template to calculate the house consumptions.

Do you have some template to calculate the consumption like in the fronius app?

      # Rete Elettrica
      # --------------------
    - name: fotovoltaico_rete_elettrica
      unique_id: f664274e-10e7-4a15-bcd3-3eb550ef0982
      unit_of_measurement: W
      device_class: power
      state: "{% set var_rete_elettrica = states('sensor.fronius10kw_solarnet_rete_elettrica') %}{{ (var_rete_elettrica | float) | round(3) if is_number(var_rete_elettrica) else 0 }}"

      # Batteria
      # --------------------
    - name: fotovoltaico_batteria
      unique_id: 5db8f06d-7f47-436c-92cd-a9be09099939
      unit_of_measurement: W
      device_class: power
      state: "{% set var_batteria = states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') %}{{ (var_batteria | float) | round(3) if is_number(var_batteria) else 0 }}"

      # produzione Fronius 5kWh
      # --------------------
    - name: fotovoltaico_produzione_symo_5
      unique_id: 75f867d4-7242-4198-96a2-e5b1e6410788
      device_class: power 
      unit_of_measurement: W 
      state: "{% set var_fronius5 = states('sensor.fronius5kw_solarnet_potenza_fotovoltaica') %}{{ (var_fronius5 | float) | round(1) if is_number(var_fronius5) else 0 }}"
      icon: mdi:solar-power-variant

      # produzione Fronius 10kWh
      # --------------------
    - name: fotovoltaico_produzione_gen_10
      unique_id: 00d76ab8-de31-450d-ae16-255ef961beab
      device_class: power 
      unit_of_measurement: "W"
      state: "{% set var_fronius10 = states('sensor.fronius10kw_solarnet_potenza_fotovoltaica') %}{{ (var_fronius10 | float) | round(1) if is_number(var_fronius10) else 0 }}"      
      icon: mdi:solar-power-variant


      # produzione totale
      # --------------------
    - name: fotovoltaico_potenza_attuale_totale
      unique_id: 40e8e3ff-de67-4528-89a2-57d44ab95733
      device_class: power 
      unit_of_measurement: W 
      icon: mdi:solar-power-variant
      state: "{{ 
                (
                states('sensor.fotovoltaico_produzione_gen_10')|float(default=0)
                +
                states('sensor.fotovoltaico_produzione_symo_5')|float(default=0)
                )|float(default=0)|float|round(1)
              }}"


      # consumo casa
      # --------------------
    - name: fotovoltaico_consumo_casa
      unique_id: c05adba4-18c0-11ee-be56-0242ac120002
      device_class: power 
      unit_of_measurement: W 
      icon: mdi:home-lightning-bolt
      state: "{{ 
                (
                states('sensor.fotovoltaico_potenza_attuale_totale')|float(default=0)  
                +
                (
                states('sensor.fotovoltaico_batteria')|float(default=0)
                + 
                states('sensor.fotovoltaico_rete_elettrica')|float(default=0)
                )
                )|float(default=0)|float|round(1)
              }}"

Hi all,
I‘ve been trying to get this working for more than a week now. Unfortunately without success. I integrated the yaml config to my configuration.yaml. I can see the three sensors (sensor.power_battery_charging, sensor.battery_power_discharging and sensor.power_photovoltaics) which seems to deliver accurate values.
I can‘t see any of the sensors when trying to integrate in the energy dashboard. I read this whole thread multiple times and also read about the problems with „sensor: power“ vs „sensor: energy“.
Surprisingly the photovoltaics sensor is set to energy, but still states „power“ when looking under developer tools.
I do not have deep experience with yaml, therefore I can not identify the problem.




Thankful for any help!

Entities with unit “W” can’t have device_class “energy”. It’s a power unit. “Wh” would be energy - that’s the result of the integration integration.

EDIT: even this forum make me headaches, each time i press enter I have fear that what I am writing is posted before finish or review…

EDIT_2: update template

EDIT_3: update template

EDIT_4: 20.08.2023 - update template - version: 4

EDIT_5: 28.08.2023 - update template - version: 5

This integration made me a lot of heachache,
because the entities are localized and it hard to find a match between other users solutions and the energy dashboard requires at least 1 day to align the data from the inverters

If can help I am posting my template, I have create a file called fotovoltaico.yaml and I put it into the folder /packages.

My suggestion is try to fix one problem at time, start with the solar, then add batteries (if you have), then the enegy in/out from the main etc

# --------------------------
# versione: 5 
# data: 28.08.2023
# --------------------------
template:
  - sensor:

      # Rete Elettrica
      # --------------------
    - name: fotovoltaico_rete_elettrica
      unique_id: f664274e-10e7-4a15-bcd3-3eb550ef0982
      unit_of_measurement: W
      device_class: power
      state: "{% set var_rete_elettrica = states('sensor.fronius10kw_solarnet_rete_elettrica') %}{{ (var_rete_elettrica | float) | round(3) if is_number(var_rete_elettrica) else 0.0 | float }}"

      # immessi in rete
      # --------------------
    - name: fotovoltaico_energia_immessa_in_rete
      unique_id: c05adf46-18c0-11ee-be56-0242ac120002
      device_class: power 
      unit_of_measurement: W 
      state:  "{{ max(0, 0 - states('sensor.fotovoltaico_rete_elettrica') | float) | round(1) }}"
      icon: mdi:transmission-tower-import

      # prelevati dalla rete
      # --------------------
    - name: fotovoltaico_energia_prelevata_dalla_rete
      unique_id: 99458436-18c2-11ee-be56-0242ac120002
      device_class: power 
      unit_of_measurement: W 
      state:  "{{ max(0, states('sensor.fotovoltaico_rete_elettrica') | float) | round(1) }}"
      icon: mdi:transmission-tower-export


      # Batteria
      # --------------------
    - name: fotovoltaico_batteria
      unique_id: 5db8f06d-7f47-436c-92cd-a9be09099939
      unit_of_measurement: W
      device_class: power
      state: "{% set var_batteria = states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') %}{{ (var_batteria | float) | round(3) if is_number(var_batteria) else 0.0 | float }}"

      # Batteria in ricarica Watt
    - name: fotovoltaico_batteria_in_ricarica 
      unique_id: cfffd192-18be-11ee-be56-0242ac120002
      unit_of_measurement: W
      device_class: power
      state: "{{ max(0, 0 - states('sensor.fotovoltaico_batteria') | float(default=0)) }}"

      # Batteria in uso Watt
    - name: fotovoltaico_batteria_in_uso 
      unique_id: cfffd43a-18be-11ee-be56-0242ac120002
      unit_of_measurement: W
      device_class: power
      state: "{{ max(0, states('sensor.fotovoltaico_batteria') | float(default=0)) }}"

      # Batteria carica
      # inverto il valore perchè mi piace di più. valori negativi quando in ricarica, positivi quando in uso
    - name: fotovoltaico_energia_batteria
      unique_id: 99458062-18c2-11ee-be56-0242ac120002
      device_class: power 
      unit_of_measurement: W 
      state:  "{{ (states('sensor.fotovoltaico_batteria') | float * -1) | round(1) }}"
      icon: "{% if is_number(states('sensor.byd_battery_box_premium_hv_stato_di_carica') | float) %}{% set var_batt_perc = states('sensor.byd_battery_box_premium_hv_stato_di_carica') | float %}{% else %}{% set var_batt_perc = 0.0 | float %}{% endif %}
             {% if is_number(states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') | float) %}
             {% set var_batt_stato = states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') | float %}{% else %}{% set var_batt_stato = 0.0 | float %}{% endif %}
             {% if var_batt_stato  | float > 0 %}
             {% if var_batt_perc | float > 70 %}mdi:battery-high
             {% elif var_batt_perc| float > 50 %}mdi:battery-medium
             {% else %}mdi:battery-low
             {% endif %}
             {% else %}
             {% if var_batt_perc | float > 90 %}mdi:battery-charging-high
             {% elif var_batt_perc | float > 60 %}mdi:battery-charging-medium
             {% elif var_batt_perc | float > 30 %}mdi:battery-charging-low
             {% else %}mdi:battery-charging-outline
             {% endif %}
             {% endif %}"


      # batteria percentuale
    - name: fotovoltaico_percentuale_batteria
      unique_id: 22d60120-3364-4ab9-9288-b5b84e8eb7b2
      device_class: battery 
      unit_of_measurement: '%' 
      state:  "{% set var_batteria_perc_carica = states('sensor.byd_battery_box_premium_hv_stato_di_carica') %}{{ (var_batteria_perc_carica | float) | round(1) if is_number(var_batteria_perc_carica) else 0.0 | float }}"
      icon: "{% if is_number(states('sensor.byd_battery_box_premium_hv_stato_di_carica') | float) %}{% set var_batt_perc = states('sensor.byd_battery_box_premium_hv_stato_di_carica') | float %}{% else %}{% set var_batt_perc = 0.0 | float %}{% endif %}
             {% if is_number(states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') | float) %}
             {% set var_batt_stato = states('sensor.fronius10kw_solarnet_batteria_di_alimentazione') | float %}{% else %}{% set var_batt_stato = 0.0 | float %}{% endif %}
             {% if var_batt_stato  | float > 0 %}
             {% if var_batt_perc | float > 70 %}mdi:battery-high
             {% elif var_batt_perc| float > 50 %}mdi:battery-medium
             {% else %}mdi:battery-low
             {% endif %}
             {% else %}
             {% if var_batt_perc | float > 90 %}mdi:battery-charging-high
             {% elif var_batt_perc | float > 60 %}mdi:battery-charging-medium
             {% elif var_batt_perc | float > 30 %}mdi:battery-charging-low
             {% else %}mdi:battery-charging-outline
             {% endif %}
             {% endif %}"


      # produzione Fronius 5kWh
      # --------------------
    - name: fotovoltaico_produzione_symo_5
      unique_id: 75f867d4-7242-4198-96a2-e5b1e6410788
      device_class: power 
      unit_of_measurement: W 
      state: "{% set var_fronius5 = states('sensor.fronius5kw_solarnet_potenza_fotovoltaica') %}{{ (var_fronius5 | float) | round(1) if is_number(var_fronius5) else 0 }}"
      icon: mdi:solar-power-variant


      # produzione Fronius 10kWh
      # --------------------
    - name: fotovoltaico_produzione_gen_10
      unique_id: 00d76ab8-de31-450d-ae16-255ef961beab
      device_class: power 
      unit_of_measurement: "W"
      state: "{% set var_fronius10 = states('sensor.fronius10kw_solarnet_potenza_fotovoltaica') %}{{ (var_fronius10 | float) | round(1) if is_number(var_fronius10) else 0 }}"      
      icon: mdi:solar-power-variant


      # produzione totale
      # --------------------
    - name: fotovoltaico_potenza_attuale_totale
      unique_id: 40e8e3ff-de67-4528-89a2-57d44ab95733
      device_class: power 
      unit_of_measurement: W 
      icon: mdi:solar-power-variant
      state: "{{ 
                (
                states('sensor.fotovoltaico_produzione_gen_10') | float
                +
                states('sensor.fotovoltaico_produzione_symo_5') | float
                ) | round(1)
              }}"


      # consumo casa
      # --------------------
    - name: fotovoltaico_consumo_casa
      unique_id: c05adba4-18c0-11ee-be56-0242ac120002
      device_class: power 
      unit_of_measurement: W 
      icon: mdi:home-lightning-bolt
      state: "{% set var_foto = states('sensor.fotovoltaico_potenza_attuale_totale') | float %}
              {% set var_energia = ((states('sensor.fotovoltaico_energia_immessa_in_rete') | float - states('sensor.fotovoltaico_energia_prelevata_dalla_rete') | float) + states('sensor.fotovoltaico_energia_batteria') | float) %}
              {% set var_cons_casa = (var_foto - var_energia) | round(1) %}
              {% if var_cons_casa > 0 %}
              {{ 
                var_cons_casa
              }}
              {% endif %}"


      # contatore
      # --------------------
    - name: fotovoltaico_energia_rete
      unique_id: 99458760-18c2-11ee-be56-0242ac120002
      device_class: power 
      unit_of_measurement: W 
      state:  "{% if (states('sensor.fotovoltaico_rete_elettrica') | float > 0) %}
                {{ (states('sensor.fotovoltaico_rete_elettrica') | float | round(1)) }}
              {% else %}
                 {{ (states('sensor.fotovoltaico_rete_elettrica') | float | round(1)) * -1}}
              {% endif %}"       
      icon: "{% if (states('sensor.fotovoltaico_rete_elettrica') | float > 0) %}
                mdi:transmission-tower-export
              {% else %}
                mdi:transmission-tower-import
              {% endif %}"                    


      # energia disponibile (fotovoltaico - energia messa in batteria)
      # --------------------
      # se batteria negativo, fotovoltaico carica batteria, altrimenti batteria in uso
    - name: fotovoltaico_potenza_attuale_disponibile
      unique_id: 5c7a8e33-1bca-43e7-aeee-044932efd8a1
      device_class: power 
      unit_of_measurement: W 
      state: "{% set var_foto_totale = states('sensor.fotovoltaico_potenza_attuale_totale') | float %}
              {% set batt_in_carica = states('sensor.fotovoltaico_batteria_in_ricarica') | float %}
              {% set casa_consumo = states('sensor.fotovoltaico_consumo_casa') | float %}
              {% if var_foto_totale <= casa_consumo %}
              0          
              {% else %}
              {{ (var_foto_totale - (batt_in_carica + casa_consumo)) | round(1) }}
              {% endif %}"
      icon: "{% set var_foto_totale = states('sensor.fotovoltaico_potenza_attuale_totale') | float %}
             {% set batt_in_carica = states('sensor.fotovoltaico_batteria_in_ricarica') | float %}
             {% set casa_consumo = states('sensor.fotovoltaico_consumo_casa') | float %}
             {% if var_foto_totale <= casa_consumo %}
              {% set var_disponibile = 0.0 | float %}
             {% else %}
              {% set var_disponibile = (var_foto_totale - (batt_in_carica + casa_consumo)) | float | round(1) %}
             {% endif %}
             {% if var_disponibile > 500 and is_state('sun.sun', 'above_horizon') %}mdi:solar-power-variant
             {% elif is_state('sun.sun', 'above_horizon') %}mdi:weather-partly-cloudy
             {% else %}mdi:weather-night
             {% endif %}"

      # autoconsumo
      # --------------------
    - name: fotovoltaico_autoconsumo
      unique_id: 0f28f9fb-b5a4-45cc-9d69-36936f476110
      unit_of_measurement: '%'
      icon: mdi:solar-power
      state: "{% if states('sensor.fotovoltaico_consumo_casa') | float != 0 
                and states('sensor.fotovoltaico_potenza_attuale_totale') | float != 0
              %} 
                {{ 
                  (
                  (100 * states('sensor.fotovoltaico_consumo_casa') | float)
                  /
                  (
                   (
                    states('sensor.fotovoltaico_potenza_attuale_totale') | float
                    +
                    states('sensor.fotovoltaico_batteria_in_uso') | float
                   )
                  +
                  states('sensor.fotovoltaico_energia_prelevata_dalla_rete') | float
                  )
                  ) | round(1)
                }}
              {% endif %}"

      # autonomia
      # --------------------
    - name: fotovoltaico_autonomia
      unique_id: cdb6553f-8ee3-4bed-b33a-76ddda2a1fd4
      unit_of_measurement: '%'
      icon: mdi:solar-power
      state: "{% set var_foto_tot = states('sensor.fotovoltaico_potenza_attuale_totale') | float %}
              {% set var_rete_set = states('sensor.fotovoltaico_energia_immessa_in_rete') | float %}
              {% set batt_in_carica = states('sensor.fotovoltaico_batteria_in_ricarica') | float %}
              {% set batt_in_uso = states('sensor.fotovoltaico_batteria_in_uso') | float %}
              {% set casa_consumo = states('sensor.fotovoltaico_consumo_casa') | float %}
              {% set var_prodotto = (var_foto_tot - var_rete_set) + (batt_in_uso - batt_in_carica) | float | round(1) %}
              {% set var_autonomia = ((100 * var_prodotto) / casa_consumo) | float | round(1)  %}
              {{ var_autonomia }}"
      


      # energia immessa in kWh
      # --------------------
    - name: fotovoltaico_energia_immessa_kWh
      unique_id: d467fef3-82ef-47f3-87e4-092287d88478
      device_class: energy 
      unit_of_measurement: kWh 
      icon: mdi:transmission-tower-import
      state: "{% set var_energia_immessa = states('sensor.smart_meter_ts_65a_3_energia_reale_prodotta') %}{{ (var_energia_immessa | float) / 1000 if is_number(var_energia_immessa) else 0 }}"


      # energia prelevata in kWh
      # --------------------
    - name: fotovoltaico_energia_prelevata_kWh
      unique_id: 03abd57d-48b1-4ab8-afab-2719d0120e4d
      device_class: energy 
      unit_of_measurement: kWh 
      icon: mdi:transmission-tower-export
      state: "{% set var_energia_prelevata = states('sensor.smart_meter_ts_65a_3_energia_reale_consumata') %}{{ (var_energia_prelevata | float) / 1000 if is_number(var_energia_prelevata) else 0 }}"

Finally I created the helper for the Riemann sum and the tariffs

Add all data to the energy dash

And this is the result


Thanks for the hint. Unfortunately changing „energy“ to „power“ did not change anything for me. Still no sensor for the battery available. Any other suggestions?

Had you tried creating the sensor using the helpers?

Choose Integrations

Then Riemann sum,

set a name
add “sensor.battery_power_charging” as input sensor
select left sum
precision 3 and leave others as default

then create a second helper with same settings for the sensor.battery_power_discharging

Hallo ich bin absolut neu hier
Und habe bis jetzt noch nichts mit Home Assistant gemacht.
Wie bekomme ich das Template bearbeitet
bzw wo muß der Code eingefügt werden damit der Speicher und die Einspeisung stimmt ?

DANKE

Hello and welcome to the community,

if I understood correctly…

to add this template the only way it to modify the yaml files.

You can add the above sensors (using the entities you have) in /home_assistant/sensors.yaml or in folder /home_assistant/packages/file_name_you_want.yaml

Choice is your :wink:

Hello and thank you very much Is there a guide for beginners where the steps are described how I can find or edit the yaml ?

There is a well done general guide about template(Templating - Home Assistant), but I suggest to watch some video on youtube, there are a lot of guides and howto and are very useful to better understand how everything work, specially if you are new

Have a look here on how to find and edit these files Configuration.yaml - Home Assistant

Thanks @crc-error79 I thought the integration was done by the code provided for the configuration.yaml. I‘ll set up the two helpers and give a feedback!

How about the configuration.yaml? Would it work to add the code there as well?