BMW Connected Automation - Remind me to lock my car

I thought it was time I shared something with this GREAT community. What drove me to install Home Assistant in the first place. It’s my first share so go easy please.

I wanted to be reminded to lock my car if either my wife or I forgot (usually distracted by screaming children). However, as I started to think more an more about this problem, I decided I also wanted to add to the notification, the following:

  • still image from camera for where the car is parked on the road
  • notification action so I can lock the car directly from the iOS notification
  • trigger this automation only when I open my front door (Wyze door sensor) with the car unlocked

I hope that my yaml below, might be able to help people to tackle similar problems. Shout if any questions and I’ll try to help where I can.

Config (required) for bmw_connected integration (Read only access, if set to true, will not allow the update_state service to run below to get the updated info)

bmw_connected_drive:
  name:
    username: !secret bmw_connected_drive_username
    password: !secret bmw_connected_drive_password
    region: rest_of_world

Config: Optional - so that ‘Camera with Actions’ Category will be synced in the iOS companion App Configuration, it needs to be in your config.
Actionable notifications code for iOS notifications from DrZZZs Youtube Channel

ios:
  push:
    categories:
      - name: Camera with Actions
        identifier: 'camera'
        actions:
          - identifier: 'LOCK'
            title: 'Lock Car'
            destructive: 'true'"

Automation: Update status (required in order to get more up to date information about the car)

alias: BMW Update State
description: BMW Update State every 10 seconds
trigger:
  - platform: time_pattern
    seconds: '10'
condition: []
action:
  - data: {}
    service: bmw_connected_drive.update_state
mode: single"

Note: this can easily be setup in the automations UI, if that is preffered to automations yaml. you can choose how frequently you want the data from the car to be updated. I am using unlock entity so I need a fairly up to date state of this entity.
Bear in mind that although I have not had BMW limit my accounts API calls YET!!!, this could happen if you set the seconds too low. "

Automation: Lock the car automation for iOS notification action - OPTIONAL if you want to have an action available in the iOS notifcation which will unlock the car. actions need to also be added in the config. check the companion app documentation for more detail.

alias: Lock the Car
trigger:
  - event_data:
      actionName: LOCK
    event_type: ios.notification_action_fired
    platform: event
action:
  - entity_id: lock.i3_94_rex_lock
    service: lock.lock
mode: single

Automation - car unlocked reminder: Optional elements are the device tracker condition and the wyze door sensor (this could be replaced with presence detection such as my device is home OR something else like car is unlocked for a set amount of time)

alias: Front Door Open Car Unlocked Notification
description: Notify me when my front door is opened and my car is unlocked
trigger:
  - entity_id: binary_sensor.wyzesense_77939752
    from: 'on'
    platform: state
    to: 'off'
condition:
  - condition: state
    entity_id: lock.i3_94_rex_lock
    state: unlocked
  - condition: and
    conditions:
      - condition: state
        entity_id: device_tracker.i3_94_rex
        state: home
action:
  - data:
      data:
        attachment:
          content-type: jpeg
        entity_id: camera.nest_cam
        push:
          category: camera
      message: Remember to lock the car
      title: Car Unlocked
    service: notify.mobile_app_iphone_sk
mode: single

Other bmw automations
I also have a bunch of other notification automations if anyone is interested let me know.
Examples:

  • Send ios notification with charge level when charging starts
  • Send ios notification when charge level reaches 80%
  • Send ios notification of what the charge level is when charging is complete
  • If it’s after 8pm and the car is at home and unlocked, remind me to unlock it
5 Likes

Nice work and thanks for sharing. Also the actionable notifications for iOS is really nice. Reminds me that I have to put some time in those automations :wink:
I have also put a link to this topic on the bimmer_connected Github page -> https://github.com/bimmerconnected/bimmer_connected/discussions/253.

Regarding the bmw_connected_drive.update_state automation. I would recommend to not make an automation for this which checks the data every 10 seconds. That means a lot of extra API calls
compared to the current 5 minute interval and I am not sure how BMW will deal with that on a long term.

My suggestion would be that you call the service on the front door trigger, put in a delay after that for e.g. 30 seconds to make sure the HA data get’s updated and then check if your car is still unlocked. That would still be quick enough.

BTW do you see that the data regarding the locks gets updated really faster by calling the service? Our view is that the service does not trigger an update from the car but gets the data from the BMW servers. So this service does not interact with the car.

Thanks for sharing on the other thread and for the recent hot fix too. Out of all of my automations i think these ones are my favourites.

On the update frequency. I’d agree that I’d prefer not to have to update so regularly. However, I’d originally planned to make these automations with read only access. But I was finding that using the door lock status binary sensor rather than the status of the lock entity was proving very slow to update and therefore was not reliable for these anti theft automations. One of my automations also shows a camera view pointed at my car when the car is unlocked. I still hope to go back to read only at some point due to the inherent security concerns around the lock service. Eg. In your example, even if I delay the automation by 30seconds, isn’t there a risk that the data won’t be refreshed for up to another 9.5 minutes??

I will try what you suggested with the delay and see how it goes. Unfortunately as soon as the automation becomes less than 100% reliable it’s much less useful.

Yes I think I’d agree that the lock entity does not seem to rely on the data refresh in the same way as for example the lock status binary sensor. Although it’s still not immediate.

That’s indeed possible I guess, but you can add another refresh after 30 seconds to avoid that maybe?

Any updates on this?

Do you see different update behaviour when calling the update_state service for the lock entity and the lock status binary sensor? I have never tested this so curious what your experencies are with this.

Fantastic… like you, I’m new to this, so still finding my way with integrations, automations etc. I would be really grateful if you could state your " * If it’s after 8pm and the car is at home and unlocked, remind me to unlock it" script…

Hi Gerard, I’m really sorry for the delay in coming back to you. My connected drive service subscription expired and I am selling the car in 2 months (third child), so I’m finding it difficult to make the time to look into this any more.

The camera part of the notification might confuse somewhat, but this is the automation (I’m guessing that’s what you meant)

- id: carunlockedreminder34928374982374
  alias: Car Unlocked After 8 Notification
  description: When it gets to 8pm notify me if the car is unlocked
  trigger:
  - entity_id: binary_sensor.*i3_94_rex*_door_lock_state
    platform: state
    to: 'on'
  condition:
  - after: '20:00:00'
    condition: time
  action:
  - data:
      data:
        attachment:
          content-type: jpeg
        entity_id: camera.*nest_cam*
        push:
          category: *camera*
        url: *nestmobile://*
      message: It's 8pm and the Car is still open!!
    service: notify.*mobile_app_iphone_sk*

You could delete everything between the first data and message if you didnt want to have a snapshot from a camera in the notification and open a URL when the notification is opened, which will open the Nest app using it’s iOS custom URL in the above case. Everything which MUST be edited for your setup is surrounded by asterisks so just copying the automation into your config is not going to work.

Brilliant… thank you so much… I will give it a try…

No problem and thanks again for sharing your automation here :+1:
I can image you have other priorities right now :grinning:

My ConnectedDrive service expired as well, but all is still working (knocking on wood).

I made a complication for my Apple Watch containing information on my car → lock state, range and fuel left. The complication is not updating very often, but it gives a good overview if I left my car unlocked or not or when I need to go to the gas station.

IMG_2895

Well, I’m wondering whether my 640D (2014) is just too old…? Even BMW connected app on the iPhone is a bit flakey - doesn’t always work - but I’m not getting anywhere with locking/unlocking the doors even if I set read_only to false. In fact, it feels a bit like the iOS app in that it goes through the motions of doing what you ask, but doesn’t actually do it. Has anyone else encountered (or overcome) these sorts of issue? I will happily leave this integration (in the too difficult pile) if others have failed too ;>)

I really struggled with it at first. Could you share your automation yaml? I assume under developer tools you can see all the bmw entities along with their state attributes?

alias: 8.00pm Check BMW 640D car is locked
description: Check BMW 640D car is locked
trigger:

  • platform: time
    at: ‘20:00:00’
    condition:
  • condition: state
    entity_id: lock.640d_lock
    state: unlocked
    action:
  • service: notify.mobile_app_ _iphone_xs_max
    data:
    title: BMW 640D
    message: ‘Your car is {{ states(’‘lock.640d_lock’’) }}’
    mode: single

The strange bit is the ‘unknown’ state… regardless of whether the care is locked or unlocked. I can also set the state to locked or unlocked, but it doesn’t do anything…

Sorry, forgot to hit reply - see below… thanks Simbieski…

Do you have a binary sensor entity called something similar like binary_sensor.i3_94_rex_door_lock_state
you could use this as an alternative to the lock entity since you’re only wanting to read the state.

Yeah I noticed that hass is still able to connect to bmw connected which was surprising. This watch complication is great. Been meaning to get round to try watch complications.

Mmmm… No, but its odd that some of the other entities that existed before like lights flashing have disappeared. Perhaps I should remove the integration (remove the lines from the config file?), reboot, then add them back in and reboot…

Yeah I’m not sure why your lock state is unknown. Are you getting any bmw related errors in the log?

Worth a try adding integration again. Just add a # to start of every toe you’d like to comment out. Then restart server. Then remove the # and restart again.

One error - ‘vehicle tracking’ - see below, but not lock related…

Logger: bimmer_connected.vehicle_status
Source: /usr/local/lib/python3.8/site-packages/bimmer_connected/vehicle_status.py:140
First occurred: 16:36:05 (1 occurrences)
Last logged: 16:36:05

Vehicle tracking is disabled

Searching for a long time where i can put my question regarding some automation what i want with BmW connected services and finally found this thread!!

Now the question is: In HA with this integration we can see the how much fuel we have and we can see how many KM range we have totally.

When we go to the tank station and fill the fuel, then we see the rest fuel range right?!

Now i want now that HA register the amounts somewhere and as result get the KM range i have done from the last fuel tank up to know every time.

How can we do that?

We have all the data from the integration what we need but where to put/calculate this data?

I have grafana with inlfuxdb as an option to use.