Automation trigger change of state does not work as expected

Hi.

I am trying to write an automation which turns off the charging functionality of my electric car by just using the change of state of its charging status.

When the charging is finished, the charging status changes from ‘charging’ to ‘connected’. If I remove the car while charging, it changes from whatever to ‘not connected’. And, if it comes from whatever to ‘sleeping’, it means that the charging is disabled. In order to avoid problems with transients, I have set that the duration shall be 1 minute.

This is the code:

alias: Coche Stop Charging
description: Set Charging to OFF when car is at 100% or disconnected
trigger:
  - platform: state
    entity_id: sensor.openevse_openevse_a25c_charging_status
    from: charging
    to: connected
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: state
    entity_id: sensor.openevse_openevse_a25c_charging_status
    to: not connected
    for:
      hours: 0
      minutes: 1
      seconds: 0
  - platform: state
    entity_id: sensor.openevse_openevse_a25c_charging_status
    to: sleeping
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - service: input_select.select_option
    data:
      option: "Off"
    target:
      entity_id: input_select.coche_modo_carga
mode: single

The thing is that this automation is not triggered as I expected.

For example, this morning, the succession of charging states have been:

  • ‘charging’ until 8:15:22
  • ‘connected’ from 8:15:22 until 8:25:42
  • ‘sleeping’ from 8:25:42

With this data, I expected the automation to be triggered at 8:16:22, that is 1 minute after changing from ‘charging’ to ‘connected’.

However, the automation has been triggered by the last condition at 8:26:42, that is one minute after being in ‘sleeping’:

image

What am I doing wrong, or how could I write it?

Thanks!

This trace only shows the latest run, which seems correct, since you are also triggering 1 min after it enters sleeping. Can you show the previous run as well?

1 Like

You are right!!! Sorry, I did not notice that I can check the history of triggers.

You are right, it was triggered, as expected, at 8:16:22, when the charging status changed from ‘charging’ to ‘connected’:

image

And, the charging mode has, in fact, changed at 8:16:22 to ‘off’:

image

Thanks for teaching this! False alarm.

no problem at all - glad to help.