Template changes from False to True but automation won't trigger

Hi,

I’m just starting out with home assistant and slowly building my automations. I’ve created a template to tell me when my car is charged. It looks at the state of charge and the target state of charge and sends a notification using the telegram integration when charging is complete.

I can see that the template changes from False to True when it reaches the required charge but my automation will not trigger. When I manually run the automation I get the notification fine.

Can anyone point me in the right direction as to what i’m doing wrong here?

Here’s the automation code below

alias: ID.3 Notification when charging complete
description: “”
trigger:

- platform: template
value_template: sensor.id3_charging_complete
condition:
action:
- service: notify.brendan
data:
message: >-
Your ID.3 is done charging, the current range is now
{{states(‘sensor.my_volkswagen_range’)}} km and the battery level is
{{states(‘sensor.my_volkswagen_state_of_charge’)}}%
mode: single

And here’s the code for the template i created

“{{ states.sensor.my_volkswagen_state_of_charge.state >= states.sensor.my_volkswagen_target_state_of_charge.state }}”

Many thanks in advance

Hi @bmines67

The template_value line in your automation needs to be:

value_template: "{{ states('sensor.id3_charging_complete') }}"

Your template sensor should be something like:

“{{ states('sensor.my_volkswagen_state_of_charge') | float(0) >= states('sensor.my_volkswagen_target_state_of_charge') | float(0) }}”

Although, the default float values of 0 may need some alteration to avoid undesired results if the sensors are unavailable.

Thanks very much for the response and the help. I’ve just copied that into my automation now so hopefully it will work when i charge again tomorrow. I’ll be sure to let you know how it goes :grinning:

that’s not going to work.

Just make your template trigger…

- platform: template
  value_template: >
    {{ {{ states('sensor.my_volkswagen_state_of_charge') | float(0) >= states('sensor.my_volkswagen_target_state_of_charge') | float(0) }}

If you want to make it a separate entity, don’t make a template sensor, make a template binary_sensor.

So a quick update on this thread as I’ve managed to get the automation working. @templeton_nash I initially tried your configuration but unfortunately it did not work. The template continued to change state but the automation still didn’t trigger

@petro I also tried to use your code as a trigger but kept getting configuration errors. I’m not sure what i was doing wrong so i took your advice and created a binary_sensor template and everything is now working as it should.

Thanks very much for the help guys, it’s very much appreciated. Here’s the code below for the template and automation in case anyone gets some value from it in future

Template

{{ states('sensor.my_volkswagen_state_of_charge') | float(0) >= states('sensor.my_volkswagen_target_state_of_charge') | float(0) }}

Automation

alias: ID.3 Notification when charging complete
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.id3_charged
    from: "off"
    to: "on"
condition: []
action:
  - service: notify.brendan
    data:
      message: >-
        🔋 Your ID.3 is done charging, the current range is now
        {{states('sensor.my_volkswagen_range')}} km and the battery level is
        {{states('sensor.my_volkswagen_state_of_charge')}}%
mode: single