Help with state change automation trigger

Hello. I’m trying to set up an automation that disables my electric car charger when the car is not at home, however the automation is not triggering, so I think I have something wrong with the states…
Automation yaml:

alias: disable car charger podpoint
description: ''
trigger:
  - platform: state
    entity_id:
      - device_tracker.car_device_tracker
    from: '"home"'
    to: '"away"'
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.podpoint_charging_allowed
mode: single

I have read here that actual states might be different to what is shown in the UI. Can someone help me with what I’m looking for in the dev tools please?

Thanks

There are two problems

  1. You added quotes in the UI editor, so the automation is looking for "home" and "away" as the states
  2. The actual state for away is not_home
  - platform: state
    entity_id:
      - device_tracker.car_device_tracker
    from: 'home'
    to: 'not_home'

Thanks. I’d played around with a few quotation attempts to see if that was the problem. Adjusted back to your recommendation.
Thanks for the tip on ‘not_home’ - how did you know that?

It’s in the docs, and you can check the current raw state by looking at Developer Tools → States. Everywhere else it’s translated.

1 Like

Fab, thanks. Hadn’t seen the Device Tracker docs - I was reading the Automation Trigger pages.
Made it slightly simpler again and changed to:

alias: disable car charger podpoint
description: ''
trigger:
  - platform: state
    entity_id:
      - device_tracker.car_device_tracker
    from: home
condition: []
action:
  - service: switch.turn_off
    data: {}
    target:
      entity_id: switch.podpoint_charging_allowed
mode: single

Works perfectly. Thanks for the help!