solar_production : in kWh the amount of solar being produced
new_charge_limit : in A, a new charge limit to set for the EVSE
Wanted functionality:
When the solar_production / 235 goes above the new_charge_limit for x time (10 seconds), then the new new_charge_limit is calculated from the solar_production value.
When the solar_production / 235 goed below the new_charge_limit, then the new new_charge_limit must be set immediately.
When the solar_production is high, the value is eventually updated. That’s good.
When the solar_production is low, the value is updated immediately. However, when the solar_production drops further, the automation is not triggered anymore.
When starting the automation manually, it does run and the value is decreased.
So why is it not triggering every time the value goes down?
Is the new_charge_limit somehow cached in the automation or trigger not causing the automation to be triggered again?
Your automation will be triggered when solar production crosses from high to low. If it’s already below the threshold, it won’t be triggered again. A trigger is a change of state, not a condition.
It works when you run it manually because doing that skips over the triggers.
I know this.
However, the threshold of the trigger is adjusted in the automation so I had hoped it would re-evaluate the threshold value, causing the trigger to fire again when the solar_production value would descend again.
Any tip on how the wanted functionality, with a changing threshold for the trigger, could be achieved?
Is there a way to use a template for a trigger?
I replaced the triggers with 'trigger template’s and this seems to give me the wanted functionality: the trigger is evaluated against the lasted threshold value.
I ended up splitting the automation in 2: one for handling ‘solar power increase’ and one for ‘solar power decrease’.
Automations:
alias: Solar power - decrease charging
description: Decrease charging when producing solar power decreases
trigger:
- platform: template
value_template: >-
{% set solarKWh = states('input_number.solar_production') | float %}
{% set solarAmp = solarKWh / 235 %}
{% set solarAmpRounded = solarAmp | round(1) %}
{% set newChargeLimit = states('input_number.new_charge_limit') | float %}
{{ solarAmpRounded < newChargeLimit }}
condition: []
action:
- if:
- condition: numeric_state
entity_id: input_number.solar_production
below: 1500
then:
- action: input_number.set_value
alias: Stop charging
data:
value: 0
target:
entity_id: input_number.new_charge_limit
else:
- action: input_number.set_value
alias: Decrease charging with maximum of 16A
metadata: {}
data:
value: >-
{% set solarKWh = states('input_number.solar_production') | float %}
{% set solarAmp = solarKWh / 235 %}
{% set solarAmpRounded = solarAmp | round(1) %}
{{ [solarAmpRounded, 16] | min }}
target:
entity_id: input_number.new_charge_limit
- action: script.put_new_charging_limit
alias: Put new charging limit
data: {}
mode: single
alias: Solar power - increase charging
description: Increase charging when producing solar power
trigger:
- platform: template
value_template: >-
{% set solarKWh = states('input_number.solar_production') | float %}
{% set solarAmp = solarKWh / 235 %}
{% set solarAmpRounded = solarAmp | round(1) %}
{% set newChargeLimit = states('input_number.new_charge_limit') | float %}
{{ solarKWh > 1500 and solarAmpRounded > newChargeLimit }}
for: "00:00:10"
condition:
- condition: numeric_state
entity_id: input_number.solar_production
above: 1500
action:
- action: input_number.set_value
alias: Set new charge limit with maximum of 16A
metadata: {}
data:
value: >-
{% set solarKWh = states('input_number.solar_production') | float %}
{% set solarAmp = solarKWh / 235 %}
{% set solarAmpRounded = solarAmp | round(1) %}
{{ [solarAmpRounded, 16] | min }}
target:
entity_id: input_number.new_charge_limit
- action: script.put_new_charging_limit
alias: Put new charging limit
data: {}
mode: restart
Note: it’s a pitty the formatting of the template values changes every time the automation is changed. The code becomes quite hard to read that way.
These automations will be part of a demo on ‘Build your own EV Smart charge solution’ on the Devoxx BE conference in two weeks.
I know these automations are not perfect, but they serve the purpose.