question

ekki-k avatar image
ekki-k asked

Include Battery Data in Home Assistant Energy dashboard

I use the sfstar hass-victron integration with 4 devices and 247 entities.

bildschirmfoto-2024-03-02-um-155312.png

Unfortunately none of the battery entities qualifies to be included in the energy dashboard (Therefore showing 0 kWh, ;-) ) :

bildschirmfoto-2024-03-02-um-155257.png

According to the documentation the "device_class must be energy for electricity grid". Obviously this is not the case for any entity. To bring the victron energy values into the energy dashboard would be ideal.

bildschirmfoto-2024-03-02-um-155325.png


I see the following possibilities :

- sfstar include "new" entities with device_class energy

- some calculations are made within Home Assistant

- some Node-RED magic coding


Anyone has already success bringing the battery values into the Homeassistant Energy dashboard ?

Energy Meterbatteryhome assistant
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

3 Answers
Joe avatar image
Joe answered ·

+1, would need this aswell! All calculations with Templates only work Part time... If one solar charger Wales up later than others in the morning, those Templates sometimes report a minus yield.

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

klaushab avatar image
klaushab answered ·

Hello,

this is my solution and it works well:

configuration.yaml:

modbus: !include victron.yaml

sensor:
  - platform: template
    sensors:

      # Template sensor for values of energy charge battery (power > 0)
      power_discharge:
        friendly_name: "Batterie Leistung Entladung"
        unique_id: aee34f60-272f-46f0-b938-33659a005365
        unit_of_measurement: "W"
        value_template: >-
          {% if (states('sensor.victron_battery_power_system')|float(0)) < 0 %}
            {
  { (states('sensor.victron_battery_power_system')|float(0) * - 1) }}
          {% else %}
            {
  { 0 }}
          {% endif %}
      # Template sensor for values of energy charge battery (power > 0)
      power_discharge:
        friendly_name: "Batterie Leistung Entladung"
        unique_id: aee34f60-272f-46f0-b938-33659a005365
        unit_of_measurement: "W"
        value_template: >-
          {% if (states('sensor.victron_battery_power_system')|float(0)) < 0 %}
            {
  { (states('sensor.victron_battery_power_system')|float(0) * - 1) }}
          {% else %}
            {
  { 0 }}
          {% endif %}

  # Sensor for Riemann sum of energy charged in battery (W -> Wh)
  - platform: integration
    source: sensor.power_charge
    unique_id: b03797b4-077f-41bf-920d-9132d6dafba9
    name: batterie_gespeicherte_energie
    unit_prefix: k
    round: 2
    method: left

  # Sensor for Riemann sum of energy discharged in battery (W -> Wh)
  - platform: integration
    source: sensor.power_discharge
    unique_id: b03797b4-077f-41bf-920d-9132d6dafba0
    name: batterie_entladene_energie
    unit_prefix: k
    round: 2
    method: left


utility_meter:
  energy_charged_daily:
    source: sensor.batterie_gespeicherte_energie
    unique_id: c8a28599-4a1b-4cdd-8727-fa771575ffe9
    name: Batterie gespeichert taeglich
    cycle: daily
    
  energy_discharged_daily:
    source: sensor.batterie_entladene_energie
    unique_id: c8a28599-4a1b-4cdd-8727-fa771575ffe1
    name: Batterie entladen taeglich
    cycle: daily    

victron.yaml:

# Victron Configuration.

- name: victron
  type: tcp
  host: 192.168.0.7
  port: 502
  sensors:
    - name: "Victron Battery Power System"
      unique_id: 5bec2ff5-99df-499c-840e-0c67fabb0f5e
      unit_of_measurement: "W"
      scan_interval: 5
      slave: 100
      address: 842
      data_type: int16
      scale: 1.0
      precision: 0 
      device_class: power

Configuration of Energy-Dashbord:

1709485443950.png

Hope it works for you too
Klaus


1709485443950.png (25.1 KiB)
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

ekki-k avatar image
ekki-k answered ·

Thanks ! Looks good. I will give it a try. braamvh reported, that the much simpler way works for him :

"sensor.victron_battery_history_chargedenergy and sensor.victron_battery_history_dischargedenergy work very well with the energy dashboard"

I use these values since over a year now and hope, some new SW would bring them to life. In my instance these values are always "0".

2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

Related Resources

Additional resources still need to be added for this topic

Energy Meter Selection Guide