This looks OK so maybe the automation trigger is looking for a change to “true” when it is already “true”.
Try setting the input_number to 14 then back to 10 to see what happens, you can also monitor what is happening by pasting the template (everthing between and including the curly brackets) into Developer Tools - Template.
If I trigger it in the developer tools using the automation.trigger, it returns ‘false’ if the sensor.evse_mileage is ‘0’ and it returns ‘true’ when I set the sensor.evse_mileage to ‘20’ manually and then trigger the automation.
Triggers only trigger if the template code changes from false to true. It wasn’t triggering because it was already true. True to true will not cause a trigger.
I tried as described above, but it didn’t work. And even if it does, it needs to switch off in all cases above the set mileage and in that case there would still be a potential issues that the evse does not reset and the milage stays above 10 and rising, without the evse ever switching off.
Would this be a better option?
## Turn off at set charged milage
- id: evse_uitschakelen_indien_bijgeladen_afstand_behaald
alias: EVSE uitschakelen indien bijgeladen afstand behaald
initial_state: on
trigger:
- platform: state
entity_id:
- sensor.evse_mileage
condition:
condition: and
conditions:
- condition: state
entity_id: switch.evse
state: 'on'
- condition: template
value_template: "{{ states('sensor.evse_mileage')|int > states('input_number.evse_max_charge_distance')|int }}"
action:
- service: switch.turn_off
entity_id: switch.evse
Blockquote
Your second example will also turn off the switch when mileage exceeds distance but it will continue to turn it off repeatedly with each increase in mileage . I don’t know if you are aware of that.
Is that so? I think I’m solving a ‘non issue’ as the sensor.evse_mileage state only changes when charging and thus does not trigger the automation if the charger is off (as the mileage does not change then)… correct?
The mileage is usually set to 0 or ’ unknown’ when the charger is eiher reset or the car is unplugged from it, but there sometimes it some strange behaviour when wifi is lost or the disconnect is not properly detected.
Blockquote
It is so.
If repeatedly turning off the switch is something you want, now you have it.
Could you elaborate how that can happen? Maybe I understand this wrong…
The charger starts charging and ‘sensor.evse_mileage’ goes up from unknown to 3, 5, 9 get’s triggered, but the condition prevents it from switching the evse off… and
then finally it reaches the ‘input_number.evse_max_charge_distance’ (now set to 10) and then switches the evse off.
Since the evse is off, ‘sensor.evse_mileage’ will not go up any further and thus not trigger the automation any longer or am I still making a mistake and if yes what mistake exactly?