@AllHailJ This is awesome! Iāve been doing mental calculations of this since I got my solar installed and this just tells me what Iām always thinking about. Thank you for sharing this!
A few questions for you:
1. Do you see the variance in Tesla Powerwall integration reporting a different battery percentage when below 100% than the Tesla Mobile App?
e.g. when at or near the reserve amount (20% in my case), my Tesla Mobile App shows 20% battery level remaining, the web UI via IP for Powerwall shows 24%, and the HA sensor shows 24%. So as of right now, my Powerwall in the Tesla app is at 21%, but HA is reporting 25% and the sensor is showing the battery life based on the 5% remaining it thinks I have instead of the 1% thatās really there. Itās usually a 4% diff.
This isnāt an issue at 100% since all sensors report the same, but when at the reserve level itās misleading. Iāve raised this to Tesla support, but their Tier 2 support indicated the difference between the Tesla App and Web UI (I assume the HA integration is pulling from the same location which is why theyāre the same) is by designā¦do you see this?
Also, the Tesla custom integration via HACS appears to have a sensor that reports the correct value, however Iāve found that integration to periodically toggle between 0% and the correct percentage. So, thatās not a reliable option.
UPDATE - after more research and filing an issue with the official HA Tesla Powerwall Integration, I found a reddit post that provided the formula that appears to correct for the 5% backup reserve. Iāve updated the solar_battery_life sensor below using that logic and it looks right so far on my end. Here is how Iāve modified your code to attempt to adjust for this difference, but I am now thinking itās proportional and not a straight 4% difference. How would you approach this?
- sensor:
- name: "solar_battery_life_actual"
unique_id: "solar_battery_life_actual"
state: >-
{% set percent = ((states('sensor.powerwall_charge') | float(0) / 100.0) - (0.05)) / (0.95) %}
{% set number = 2 %}
{% set energy = 13.5 %}
{% set reserve = 0.2 %}
{% set charge = (percent - reserve) * number * energy %}
{% set a = states('sensor.powerwall_solar_now') | float(0) %}
{% set b = states('sensor.powerwall_site_now') | float(0) %}
{% set c = states('sensor.powerwall_battery_now') | float(0) %}
{% set current_power = a + b + c %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{{ decimal_hours | int(0) ~ ' hrs ' ~ minutes ~ ' minutes' }}
2. If you wanted to create a sensor to show Battery Life at Current Power Draw Including Reserve, would you just pull out the mentions of āreserveā ? Hereās what Iāve put togetherā¦anything you would do differently?
- sensor:
- name: "solar_battery_life_total"
unique_id: "solar_battery_life_total"
state: >-
{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 %}
{% set number = 2 %}
{% set energy = 13.5 %}
{% set charge = (percent) * number * energy %}
{% set a = states('sensor.powerwall_solar_now') | float(0) %}
{% set b = states('sensor.powerwall_site_now') | float(0) %}
{% set c = states('sensor.powerwall_battery_now') | float(0) %}
{% set current_power = a + b + c %}
{% set decimal_hours = charge / current_power %}
{% set minutes = (decimal_hours % 1 * 60) | round(0) %}
{{ decimal_hours | int(0) ~ ' hrs ' ~ minutes ~ ' minutes' }}
3. Do you get these errors on boot for these sensors? Iām seeing this at ever reboot in the logs, so Iām wondering if itās just because the system rebooted.
Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:356
First occurred: 22:01:28 (3 occurrences)
Last logged: 22:01:28
TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template("{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 %} {% set number = 2 | float(0) %} {% set energy = 13.5 | float(0) %} {% set reserve = 0.2 | float(0) %} {% set charge = ((percent - reserve) * number * energy) | float(0) %} {% set current_power = states('sensor.average_kw_used_last_hour') | float(0) %} {% set decimal_hours = charge / current_power %} {% set minutes = (decimal_hours % 1 * 60) | round(0) %} {{ decimal_hours | int(0) ~ ' hrs ' ~ minutes ~ ' minutes' }}")' for attribute '_attr_native_value' in entity 'sensor.solar_battery_life_1_hr'
TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template("{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 %} {% set number = 2 | float(0) %} {% set energy = 13.5 | float(0) %} {% set reserve = 0.2 | float(0) %} {% set charge = ((percent - reserve) * number * energy) | float(0) %} {% set current_power = states('sensor.average_kw_used_last_12_hour') | float(0) %} {% set decimal_hours = charge / current_power %} {% set minutes = (decimal_hours % 1 * 60) | round(0) %} {{ decimal_hours | int(0) ~ ' hrs ' ~ minutes ~ ' minutes' }}")' for attribute '_attr_native_value' in entity 'sensor.solar_battery_life_12_hr'
TemplateError('ZeroDivisionError: float division by zero') while processing template 'Template("{% set percent = states('sensor.powerwall_charge') | float(0) / 100.0 %} {% set number = 2 | float(0) %} {% set energy = 13.5 | float(0) %} {% set reserve = 0.2 | float(0) %} {% set charge = ((percent - reserve) * number * energy) | float(0) %} {% set current_power = states('sensor.average_kw_used_last_24_hour') | float(0) %} {% set decimal_hours = charge / current_power %} {% set minutes = (decimal_hours % 1 * 60) | round(0) %} {{ decimal_hours | int(0) ~ ' hrs ' ~ minutes ~ ' minutes' }}")' for attribute '_attr_native_value' in entity 'sensor.solar_battery_life_24_hr'```