Should I use an if-then automation to lock my vehicle?

I installed the FordPass integration and can see all of the entities. The one I’m interested is fordpass_doorlock. My idea for my automation is that if the state of the door lock is unlocked after 9PM and the vehicle is in my home zone and the ignition is off, then the door will lock. I was trying an if/then automation, but I can’t figure out what action to choose to be able to toggle the door lock. I have the button available on my home screen, I just don’t know what the action is called to trigger it.

if:
  - condition: state
    entity_id: lock.fordpass_doorlock
    state: unlocked
  - condition: zone
    entity_id: sensor.fordpass_gps
    zone: zone.home
then:
  - condition: state
    entity_id: lock.fordpass_doorlock
    state: locked

Use the lock.lock service call.

then:
  - service: lock.lock
    target:
      entity_id: lock.fordpass_doorlock

Thanks. I’m seeing this error so maybe there is a numeric value to locked and unlocked?

2022-10-09 22:01:00.012 ERROR (MainThread) [homeassistant.components.automation.carlock9pm] CarLock9PM: Error executing script. Unexpected error for if at pos 1: must be real number, not str

Post the entire automation.

alias: CarLock9PM
description: ""
trigger:
  - platform: time
    at: "11:50:00"
condition: []
action:
  - if:
      - condition: state
        entity_id: lock.fordpass_doorlock
        state: unlocked
      - condition: zone
        entity_id: sensor.fordpass_gps
        zone: zone.home
    then:
      - service: lock.lock
        target:
          entity_id: lock.fordpass_doorlock
        data: {}
  - service: notify.notify
    data: {}
mode: single

You’re using a sensor entity for the Zone Condition. Isn’t it normally used with a device_tracker entity?

Go to Developer Tools > States and find the current value of sensor.fordpass_gps. What is it?

State = UNSHIFTED and attributes are

latitude: 38.XXXXXX
longitude: -90.XXXXX
gpsState: UNSHIFTED
status: CURRENT
timestamp: 10-10-2022 19:50:41
icon: mdi:radar
friendly_name: fordpass_gps

That explains why the Zone Condition fails.

I just removed the Zone portion and ran the automation and it did lock the vehicle although the logs are showing a different error

Logger: homeassistant.components.automation.carlock9pm
Source: components/automation/init.py:567
Integration: Automation (documentation, issues)
First occurred: 3:20:10 PM (1 occurrences)
Last logged: 3:20:10 PM

Error while executing automation automation.carlock9pm: required key not provided @ data[‘message’]

You overlooked to supply notify.notify with a message value.

Reference: Notifications

  - service: notify.notify
    data:
      message: "Hello world"

Thanks for all of your help. Works perfect now!

You’re welcome!

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions.

For more information about the Solution tag, refer to guideline 21 in the FAQ.