I have a template sensor (code below) that is trying to calculate the appropriate target amperage for my Level 2 charger to send to my car during solar overproduction.
I’m testing it and it seems to be working well, except my whole home power consumption data (via sunpower) doesn’t update immediately upon any changes.
This means I can’t reliably automate this because each time the charger amperage updates, the calculation will just recalculate against the same power consumption so the target will spiral either upwards or downwards until the power consumption data updates again.
In the Homeassistant dashboard, the template says it will listen to events for:
sensor.power_2
(whole home consumption)switch.charger_charge_control
(charger on/off)- number.charger_maximum_current (charger max amperage)
Is it possible to only have the template listen to sensor.power_2
and switch.charger_charge_control
?
The other option, I suppose, would be to only run an automation against this template sensor once every 5 minutes or so, giving the values time to stabilize and recalculate.
{% if states('sensor.power_2')|float %}
{% if is_state('switch.charger_charge_control', 'on') %}
{{ ((
((states('sensor.power_2')|float*-1000))
+ (240*(states('number.charger_maximum_current')|int))
) / 240) | round(0, 'floor')
}}
{% else %}
{{ (((states('sensor.power_2')|float*-1000)) / 240) | round(0, 'floor') }}
{% endif %}
{% endif %}