November 30, 20214 yr 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: - platform: integration source: sensor.battery_power name: Battery Power unit_prefix: k method: left round: 2 This allows me to add the relevant sensors to the Home Assistant Energy Dashboard. 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: Does anyone have any tips?
December 1, 20214 yr 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.
December 1, 20214 yr 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.
December 1, 20214 yr 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'
December 4, 20214 yr 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:
December 4, 20214 yr 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]
December 4, 20214 yr 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!
July 9, 20224 yr On 2021/12/04 at 12:08 PM, Denarius said: If you run the latest beta you don't have to do anything fancy: I just installed a new home assistant and can confirm these steps work and is probably the least effort to get going: https://solar-assistant.io/help/home-assistant/energy
March 16, 20233 yr Hi, Does anyone have an idea on how to create a sensor for SolarAssistant in homeassistant to calculate the battery SOC time to zero?
March 16, 20233 yr 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 March 16, 20233 yr by mzezman added credit
March 16, 20233 yr So if i have 27.5 KwH batteries what would i change? I have 5 hubble am2 batteries? Thanks for this
March 16, 20233 yr 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
March 16, 20233 yr Awesome. Thanks so much for this, last question, you dont perhaps knows till wat percentage to zero it calculates? 0 or 20?
March 16, 20233 yr 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)
April 16, 20233 yr 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
April 21, 20233 yr Hi. Is it possible to change this to show how long it will take to charge battery to 100%. Using the info of how many watts are coming into the battery?
August 10, 20232 yr 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.
February 4, 20242 yr 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. 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)}}"
February 4, 20242 yr https://github.com/slipx06/Sunsynk-Home-Assistant-Dash If you scroll down there is some template code for this
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.