From e94acbbd83d9185b2b2e49bf3c68a5f418677f5e Mon Sep 17 00:00:00 2001 From: Ryan McLean Date: Fri, 17 Mar 2023 15:03:54 +0000 Subject: [PATCH] Fixed Time to Discharge --- packages/energy_stats.yaml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/energy_stats.yaml b/packages/energy_stats.yaml index 6166775..23345ce 100644 --- a/packages/energy_stats.yaml +++ b/packages/energy_stats.yaml @@ -119,12 +119,13 @@ template: availability: > {{ states('sensor.solaredge_b1_status_text') == 'Charging' }} - # WRONG!!!!! - name: "Solar Battery Time to Empty" unique_id: battery_time_to_empty state: > - {% set ct = ((states('sensor.solaredge_b1_maximum_energy') | float * (100 - states('sensor.solaredge_b1_state_of_energy')| float) /100) / ((states('sensor.solaredge_b1_dc_power') |float *-1)/1000) * 60) | int %} - {% if ct > 60 %}{{ ct // 60 }}:{{ '{:0>2d}'.format(ct%60) }} hours{% else %}{{ct}} minutes{% endif %} + {% set batterypower = (states('sensor.solaredge_b1_dc_power') | int * -1) %} + {% set wattsToDischarge = ((states('sensor.solaredge_b1_maximum_energy') | float(0) *1000)/100)*(states('sensor.solaredge_b1_state_of_energy') | float) %} + {% set totalhrs = (wattsToDischarge | float / batterypower | float) | round(2) %} + {{ '%02d:%02d' | format((totalhrs | int),((totalhrs*60) % 60) | round(0)) }} availability: > {{ states('sensor.solaredge_b1_status_text') == 'Discharging' }}