#Remaining Charging Time for PV Battery

1 messages · Page 1 of 1 (latest)

brittle owl
#

Hello, I need help choosing a template for creating a "helper" to calculate the Remaining charging Time for my PV Battery. It should be calculated from the Capacity ( 10kwh - actual SOC / actual charging current). Any advise which helper I should choose??

white copper
#

You want a template helper. You’ll have to work on your formula though. And if you’re charging to 100% soc, the charging current is going to drop off as you get to a high soc and therefore a linear estimation of charging time is going to be off the mark.

brittle owl
#

Do you have any advise about the formula? For some other template helpers I used formulas that I found in the Internet and changed them but here I couldn't find anything. Your right, the charging current will be reduced at a SOC of 100% but it is not that extrem like in an EV. ( It's really near linear at the end.)

white copper
#

It depends what data you have available to you. Which side of your converter is charging current measured (PV side or battery side)? Do you need have a charging power measurement? Do you have battery voltage?

#

A general formula would be hours_remaining = battery_capacity * (1-SOC) / charging_power
So a 10kWh battery at 30% SOC and 8kW of charging would be 10*(1-0.3)/8 = 0.875 hours

#

If you have charging current going into the battery you would multiply that by the battery voltage to get charging power

brittle owl
#

The capacity is 10kW, the "sensor.battery_state_of_capacity" is in % and my combined helper ( PV on both sides of the roof) "battery_charge_discharge_power" is in W .

#

But now I have to get these values in a form like ( a helper for displaying the current output from one PV side "{{ (float(states( "sensor.inverter_pv_1_current"))) * (float(states( "sensor.inverter_pv_1_voltage"))) }}" And this is where i struggle.

brittle owl
#

{{ (float(states( "sensor.battery_state_of_capacity"))) / (float(states( "sensor.battery_charge_discharge_power"))) }} works for SOC / charging_power

white copper
#

I like to use filters instead of functions because it makes the code easier to read, but what you are doing is fine too.

#

If you want it to be easy to read and easy to follow what is going on, so you can look at it a year from now and understand what you did:

#

{% set batt_kwh = 10 %}
{% set soc = states('sensor.battery_state_of_capacity') | float %}
{% set current = states('sensor.inverter_pv_1_current') | float %}
{% set voltage = states('sensor.inverter_pv_1_voltage') | float %}
{% set charge_power = voltage * current %}
{{ batt_kwh * (1 - soc) / charge _power }}
#

But this should do the exact same thing in a single line:

#

{{ 10 * ( 1 - states('sensor.battery_state_of_capacity') | float ) / ( states('sensor.inverter_pv_1_current') | float * states('sensor.inverter_pv_1_voltage') | float ) }}  
brittle owl
#

Agree that your first solution looks more "clean" and yes I agree that if you come back later it's easier to understand, but I dont know where/how to put these code in HA. with a little change your second hint is giving me a result. The original one is ending with ZeroDivisionError: float division by zero {{ 10 * ( 1 - states('sensor.battery_state_of_capacity') |float ) / ( states('sensor.battery_charge_discharge_power') | float )}}`
actual result: 2.694610778443114
But as I realized there are a few more things I have to solve:

  • the sensor.battery_charge_discharge_power is returning a positiv Value as long th Sun is shining, but when the Battery get's discharged it's return is -450W ... -800W and so the result displays a shorter remaining Time
  • round the result to 1 digit
  • In your example your calculation was 10*/1-0.3)/8, but my sensor.battery_state_of_capacity is 30% , not 0.3
brittle owl
#

{{ (10000 * ( 1 - states('sensor.pv_soc_2') |float ) / ( states('sensor.battery_charge_discharge_power')) | float(0)) | round(2) }}

One step closer to my goal: 🙃
I created a second helper sensor.pv_soc_2 which is just the actual SOC % value divided by 100.
Now the result is a positiv Value as long as the Battery is getting charged, but when there is no sun and/or the Battery get's discharged i get a nagative Value for the remaining Time.

white copper
#

What do you want the sensor to show when the battery is being discharged? Having the sensor show unavailable makes the most sense to me but you may not like that

#

You could have it show zero, or you could have it show the time until the battery is drained. Or whatever else you want.

brittle owl
#

As there was enough sun today the battery got fully charged and I saw for the first Time that then the sensor is showing "unavailable", and when there is not enough power to charge the Battery it is showing "0". So that's OK for me.
A little bit confusing that the code inserted in the DEVELOPER -> TEMPLATE section show's different outputs as if you insert it into a "real sensor". That fact botherd me the most time.

brittle owl
white copper
#

you can either create a template sensor in the UI (settings -> devices & services -> helpers) or you can do it in YAML

#

you can use either code (the single line or the multi-line version) anywhere templates are accepted

#

just note that in YAML, the single-line format is state: "{{ template_here }}" and multiline is

state: >
  {{ template_here }}
brittle owl
#

Looks not so bad. For my next helper/sensor to create I will use your version. Thank you !!🤝

white copper
#

that sensor should be in units of 'hours' though?

#

should be able to choose these: