Creating automation with trigger state based on device class enum

Hi there,
I’m currently trying to create an automation system for my EV charging station. I have a SMA EV-Charger charging station and I get the status via the sensor sensor.smaev_3013950814_charging_session_status as device class enum in Home Assistant. Now I want to send some values automated in a Telegram chat when switching to the ‘not_connected’ state. When I run the automation manually (without the trigger), it works. But I can’t get it to work with the trigger. Even when I set the state to ‘not_connected’ manually, nothing happens. Does anyone have any ideas?
My automation:

- id: '1735682603342'
  alias: Send Telegram Message When Charging Status Changes to Not Connected
  description: Sends a message to Telegram when the charging session status changes
    from active_mode to not_connected.
  trigger:
  - platform: state
    entity_id: sensor.smaev_3013950814_charging_session_status 
    to: 'not_connected'  
  condition:
  - condition: template
    value_template: >
      {{ states('sensor.smaev_3013950814_charging_session_status') == 'not_connected' }}  
  actions:
  - action: notify.telegram_smarthome_bot
    data:
      message: 'EV hat am SMA EV Charger: {{ states(''sensor.smaev_3013950814_charging_session_energy'')}} Wh geladen. Drehschalter steht auf {{ states(''select.smaev_3013950814_operating_mode_of_charge_session'') }}'
      data:
        parse_mode: html
  mode: single

Sensor sensor.smaev_3013950814_charging_session_status information:

options: not_connected, sleep_mode, active_mode, station_locked
device_class: enum
friendly_name: EV Charger Status Ladevorgang

What is the actual state of the sensor as shown on Developer Tools / States?

Your template condition is unneeded, as it’ll always be true when the trigger fires.

the actual state is sleep_mode

Are there any automation traces available? Does it trigger but just fail to run the action? Any errors in the logs?

Your YAML syntax is a little out of date and mixed (e.g. trigger / platform rather than triggers / trigger) — is this a UI-generated automation that you’ve saved as YAML, or are you on an old version of HA? Timestamp of the id is 31-Dec-2024…

Try this if you’re on a recent version:

- id: '1735682603342'
  alias: Send Telegram Message When Charging Status Changes to Not Connected
  description: >-
    Sends a message to Telegram when the charging session status
    changes from active_mode to not_connected.
  triggers:
    - trigger: state
      entity_id: sensor.smaev_3013950814_charging_session_status 
      to: 'not_connected'  
  actions:
    - action: notify.telegram_smarthome_bot
      data:
        message: "EV hat am SMA EV Charger: {{ states('sensor.smaev_3013950814_charging_session_energy') }} Wh geladen. Drehschalter steht auf {{ states('select.smaev_3013950814_operating_mode_of_charge_session') }}"
        data:
          parse_mode: html
  mode: single
1 Like

I tried your advice and it works :slight_smile: Great. A few other lines and it works fine.
Unfortunately there was no indication of the error in the log. Thanks for your support and your time.

P.S it was a mixed version of UI generated and manually YAML modified code.