Skip to content
View in the app

A better way to browse. Learn more.

Power Forum - Renewable Energy Discussion

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Home Assistant - Battery Power with Solar Assistant

Featured Replies

Hi All

This might be a stupid question, but I am not winning with this simple integration in Home Assistant.

With Solar Assistant, all the load sensors are created with Watt as the unit. I convert these sensors to KW via means of an integration sensor as follows:

  - platformintegration
    sourcesensor.battery_power
    nameBattery Power
    unit_prefixk
    methodleft
    round2

This allows me to add the relevant sensors to the Home Assistant Energy Dashboard. 

image.png.27c39a35d639ddf658b089aa259b5863.png

The one that has me stumped though is the battery. Home Assistant requires a battery in and battery out sensor. The Battery out I configure with the sensor as above, however, which sensor is used to define the power going into the battery? I can only see the following sensors from Solar Assistant with MQTT:

image.png.067fce2ef5e9aca62f8c3337092ae130.png

 

Does anyone have any tips?

 

 

  • Author

Just an update. When battery is providing load, the Battery power displays a negative load. When battery is receiving load to charge, the value is positive.

template:
  - sensor:
    - name: battery_charge
      unit_of_measurement: W
      state_class: measurement
      device_class: power
      state: >
        {% if states('sensor.battery_power') | float >= 0 }
          {{ states('sensor.battery_power')|float}}
        {% else %}
          {{ 0 }}
        {% endif %}

    - name: battery_discharge
      unit_of_measurement: W
      state_class: measurement
      device_class: power
      state: >
        {% if states('sensor.battery_power') | float < 0 }
          {{ states('sensor.battery_power')| float * -1}}
        {% else %}
          {{ 0 }}
        {% endif %}

I have not tested this, so I take no responsibility, but it should give you a place to start.

  • Author

Thank You! 

 

You put me on the correct path. Template is as follows:

 

      battery_energy_in:
        unique_id: battery_power_in
        value_template: >-
          {% set power = states('sensor.battery_power') | float %}
          {% if power > 0.0 %} {{ states('sensor.battery_power')|float }}
          {% else %} 0.0 {% endif %}
        device_class: Power
        unit_of_measurement: 'W' 
      battery_energy_out:
        unique_id: battery_energy_out
        value_template: >-
          {% set power = states('sensor.battery_power') | float %}
          {% if power < 0.0 %} {{ (states('sensor.battery_power')|float * -1) }}
          {% else %} 0.0 {% endif %}
        device_class: Power
        unit_of_measurement: 'W' 

 

 

image.png.86b0ed1a8e315b0a96cde412dcbd3b11.png

image.png.6fe208719e892f84cf316b92add63e6d.png

On 2021/11/30 at 7:56 PM, ggza said:

This might be a stupid question, but I am not winning with this simple integration in Home Assistant.

If you run the latest beta you don't have to do anything fancy:

 

I too can confirm that with the following versions I am able to correctly reflect the information within Home Assistant for the Energy module. And did not have to do any workarounds in HASS templates etc.

HASS Version : 2021.11.5

Solar Assistant Software build date : 2021-12-01  [I have joined the BETA program and see this version (at the time of this post) is BETA according to their change log https://solar-assistant.io/help/updates/changelog] 

  • Author
1 hour ago, StickeyTape said:

I too can confirm that with the following versions I am able to correctly reflect the information within Home Assistant for the Energy module. And did not have to do any workarounds in HASS templates etc.

HASS Version : 2021.11.5

Solar Assistant Software build date : 2021-12-01  [I have joined the BETA program and see this version (at the time of this post) is BETA according to their change log https://solar-assistant.io/help/updates/changelog] 

Yip, just updated my Solar-Assistant and all the sensors for the energy dashboard are there!

 

 

  • 7 months later...
  • 8 months later...
56 minutes ago, CBothma said:

Hi,

 

Does anyone have an idea on how to create a sensor for SolarAssistant in homeassistant to calculate the battery SOC time to zero?

Template sensors to be created in configuration.yaml:

  - platform: template
    sensors:
      soc_battery_depletion_seconds_backup_circuit:
        friendly_name: "Battery Depletion Seconds - Backup Circuit"
        unit_of_measurement: Seconds
        value_template: "{{ (((states('sensor.battery_state_of_charge') | float * 9.6 * 10) - 960 - 60) / ((states('sensor.load_power')) | float) * 60 * 60 ) | timestamp_custom('%s', 0)}}"
      soc_battery_depletion_backup_circuit_formatted_no_ago:
        friendly_name: "Battery Depletion No Ago - Backup Circuit"
        value_template: >
          {% set time = states('sensor.soc_battery_depletion_seconds_backup_circuit') | int %}
          {%- set minutes = ((time % 3600) // 60) %}
          {%- set minutes = '{} minutes'.format(minutes) if minutes > 0 else '' %}
          {%- set hours = ((time % 86400) // 3600) %}
          {%- set hours = '{} hours, '.format(hours) if hours > 0 else '' %}
          {%- set days = (time // 86400) %}
          {%- set days = '{} day, '.format(days) if days > 0 else '' %}
          {{ 'Less than 1 minute' if time < 60 else days + hours + minutes }}

YAML to display:

Battery runtime {{
  states('sensor.soc_battery_depletion_backup_circuit_formatted_no_ago') }} at current ({{states('sensor.load_power') }}W) load

The above is for a 9.6kwh battery bank.

Edit: Credit to the developer (PilgrimtoHyperion on MyBB) - i just cut and paste 🙂 @PilgrimToHyperion

Edited by mzezman
added credit

50 minutes ago, CBothma said:

So if i have 27.5 KwH batteries what would i change? I have 5 hubble am2 batteries?

 

Thanks for this

Change this line 

((states('sensor.battery_state_of_charge') | float * 9.6 * 10)

to 

((states('sensor.battery_state_of_charge') | float * 27.5 * 10)

 

42 minutes ago, CBothma said:

Also what do i do with the display yaml?

 

thanks in advance

If you have the mushroom cards add-on then you can use a mushroom template card like this

type: custom:mushroom-title-card
title: ''
alignment: center
subtitle: |
  Battery runtime {{
    states('sensor.soc_battery_depletion_backup_circuit_formatted_no_ago') }} at current ({{states('sensor.load_power') }}W) load

If you do not have that add-on then just use a normal Markdown card

type: markdown
content: |2
    Battery runtime {{
      states('sensor.soc_battery_depletion_backup_circuit_formatted_no_ago') }} at current ({{states('sensor.load_power') }}W) load

 

17 minutes ago, CBothma said:

Awesome. Thanks so much for this, last question, you dont perhaps knows till wat percentage to zero it calculates? 0 or 20?

Looking back at the original post it goes down to 90% DOD (10% SOC)

  • 1 month later...
On 2023/03/16 at 2:14 PM, mzezman said:

Template sensors to be created in configuration.yaml:

  - platform: template
    sensors:
      soc_battery_depletion_seconds_backup_circuit:
        friendly_name: "Battery Depletion Seconds - Backup Circuit"
        unit_of_measurement: Seconds
        value_template: "{{ (((states('sensor.battery_state_of_charge') | float * 9.6 * 10) - 960 - 60) / ((states('sensor.load_power')) | float) * 60 * 60 ) | timestamp_custom('%s', 0)}}"
      soc_battery_depletion_backup_circuit_formatted_no_ago:
        friendly_name: "Battery Depletion No Ago - Backup Circuit"
        value_template: >
          {% set time = states('sensor.soc_battery_depletion_seconds_backup_circuit') | int %}
          {%- set minutes = ((time % 3600) // 60) %}
          {%- set minutes = '{} minutes'.format(minutes) if minutes > 0 else '' %}
          {%- set hours = ((time % 86400) // 3600) %}
          {%- set hours = '{} hours, '.format(hours) if hours > 0 else '' %}
          {%- set days = (time // 86400) %}
          {%- set days = '{} day, '.format(days) if days > 0 else '' %}
          {{ 'Less than 1 minute' if time < 60 else days + hours + minutes }}

YAML to display:

Battery runtime {{
  states('sensor.soc_battery_depletion_backup_circuit_formatted_no_ago') }} at current ({{states('sensor.load_power') }}W) load

The above is for a 9.6kwh battery bank.

Edit: Credit to the developer (PilgrimtoHyperion on MyBB) - i just cut and paste 🙂 @PilgrimToHyperion

Thanks for this. It needs a small correction. 

- platform: template
  sensors:
    soc_battery_time_left:
      friendly_name: "Battery Depletion Seconds"
      unit_of_measurement: Seconds
      value_template: "{{ ((((states('sensor.battery_soc') | float - 20) /100) * 15960) / ((states('sensor.load_power') | float + 60 ) | float) * 60 * 60 ) | timestamp_custom('%s', 0)}}"
    soc_battery_time_left_friendly:
      friendly_name: "Battery Depletion Time"
      value_template: >
        {% set time = states('sensor.soc_battery_time_left') | int %}
        {%- set minutes = ((time % 3600) // 60) %}
        {%- set minutes = '{} minutes'.format(minutes) if minutes > 0 else '' %}
        {%- set hours = ((time % 86400) // 3600) %}
        {%- set hours = '{} hours, '.format(hours) if hours > 0 else '' %}
        {%- set days = (time // 86400) %}
        {%- set days = '{} day, '.format(days) if days > 0 else '' %}
        {{ 'Less than 1 minute' if time < 60 else days + hours + minutes }}

15960 = Is my battery capacity in Wh (Update to match your battery size)

20 = Is the minimum SOC percentage or shutdown percentage

Added 60W to the load  to cater for inverter self power

  • 3 months later...

Hi Everyone,

thanks for this post, I was able to use the code to do both time to 30% and time to 100% SOC, now I'm interested in modifying it to use an average consumption rather than the instant current power.

HA.png

  • 5 months later...
On 2023/08/10 at 3:40 PM, DMAC said:

Hi Everyone,

thanks for this post, I was able to use the code to do both time to 30% and time to 100% SOC, now I'm interested in modifying it to use an average consumption rather than the instant current power.

HA.png

how to show how long it will take to charge battery to 100% with this code? what needs to be changed? Thank you

{{ ((((states('sensor.battery_soc') | float - 20) /100) * 15960) / ((states('sensor.load_power') | float + 60 ) | float) * 60 * 60 ) | timestamp_custom('%s', 0)}}"

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.