New Plugin - BMW Connected Drive

Posted on
Mon Jan 06, 2020 9:42 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New Plugin - BMW Connected Drive

Issue fixed in 0.0.5 - https://github.com/FlyingDiver/Indigo-B ... /tag/0.0.5

The plugin now handles arrays in the vehicle data properly.

Also submitted to plugin store.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Feb 25, 2020 7:09 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: New Plugin - BMW Connected Drive

A new error started over the weekend. I guess BMW is making API tweaks:

Code: Select all
Feb 25, 2020 at 8:06:12 AM
   Reloading plugin "BMW Connected Drive 0.0.5"
   Stopping plugin "BMW Connected Drive 0.0.5" (pid 667)
   Stopped plugin "BMW Connected Drive 0.0.5"
   Starting plugin "BMW Connected Drive 0.0.5" (pid 74243)
   Started plugin "BMW Connected Drive 0.0.5"
   BMW Connected Drive Error       Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 139, in runConcurrentThread
  File "plugin.py", line 176, in updateVehicle
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/Plugins/BMW ConnectedDrive 2.indigoPlugin/Contents/Server Plugin/bmwcdapi.py", line 149, in get_vehicle_data
TypeError: 'NoneType' object has no attribute '__getitem__'

   BMW Connected Drive Error       plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)


Write Vehicle Data to Log failed.

Posted on
Tue Feb 25, 2020 7:17 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New Plugin - BMW Connected Drive

Hmm. Can't reproduce. Plugin is working fine for me.

Is this repeatable for you?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Tue Feb 25, 2020 5:03 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: New Plugin - BMW Connected Drive

I turned off the Plugin and then noticed my app was disconnected.

I'll turn it back on when I get home.

Posted on
Tue Feb 25, 2020 5:54 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New Plugin - BMW Connected Drive

Also, 0.0.6 is the current version as of today.

Joe

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Feb 26, 2020 7:32 am
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: New Plugin - BMW Connected Drive

I tried again. The error comes every 30 seconds or so.

Posted on
Wed Feb 26, 2020 7:33 am
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New Plugin - BMW Connected Drive

Make sure you're on 0.0.6, then turn on debug logging. Post the log for the time around the error.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Feb 26, 2020 6:49 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: New Plugin - BMW Connected Drive

Looks like an auth issue. This seems to happen every few months and then I have to stop using for a while. Maybe I am using the API too much.

Code: Select all

Feb 26, 2020 at 7:47:33 PM
   Reloading plugin "BMW Connected Drive 0.0.6"
   Stopping plugin "BMW Connected Drive 0.0.6" (pid 68771)
   BMW Connected Drive Debug       runConcurrentThread ending
   BMW Connected Drive             BMW Account: Stopping cdAccount Device 372344672
   BMW Connected Drive             Ryan's BMW 540ix: Stopping cdVehicle Device 105421725
   BMW Connected Drive             Stopping Connected Drive
   Stopped plugin "BMW Connected Drive 0.0.6"
   Starting plugin "BMW Connected Drive 0.0.6" (pid 69506)
   BMW Connected Drive Debug       logLevel = 5
   Started plugin "BMW Connected Drive 0.0.6"
   BMW Connected Drive             Starting Connected Drive
   BMW Connected Drive Debug       updateFrequency = 300.0
   BMW Connected Drive             BMW Account: Starting cdAccount Device
   BMW Connected Drive Error       get_tokens AUTH Error, exception = [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)
   BMW Connected Drive Threaddebug BMW Account: getDeviceStateList, base state_list = States : (list)
     Item : (dict)
          Disabled : false (bool)
          Key : authenticated (string)
          StateLabel : Authenticated (yes or no) (string)
          TriggerLabel : Authenticated (string)
          Type : 52 (integer)
   BMW Connected Drive Threaddebug BMW Account: getDeviceStateList, final state_list = States : (list)
     Item : (dict)
          Disabled : false (bool)
          Key : authenticated (string)
          StateLabel : Authenticated (yes or no) (string)
          TriggerLabel : Authenticated (string)
          Type : 52 (integer)
   BMW Connected Drive             Ryan's BMW 540ix: Starting cdVehicle Device
   BMW Connected Drive Threaddebug Ryan's BMW 540ix: getDeviceStateList, base state_list = States : (list)
     Item : (dict)
          Disabled : false (bool)
          Key : status (string)
          StateLabel : UI Status (string)
          TriggerLabel : UI Status (string)
          Type : 150 (integer)
   BMW Connected Drive Threaddebug Ryan's BMW 540ix: getDeviceStateList, final state_list = States : (list)
     Item : (dict)
          Disabled : false (bool)
          Key : status (string)
          StateLabel : UI Status (string)
          TriggerLabel : UI Status (string)
          Type : 150 (integer)
   BMW Connected Drive Debug       runConcurrentThread starting
   BMW Connected Drive Error       get_tokens AUTH Error, exception = [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)
   BMW Connected Drive Debug       ConnectedDrive account 372344672 not authenticated, skipping update
   BMW Connected Drive Debug       ConnectedDrive get_vehicle_data: WBAJE7C55KWD55588
   BMW Connected Drive Error       Error in plugin execution runConcurrentThread:

Traceback (most recent call last):
  File "plugin.py", line 140, in runConcurrentThread
  File "plugin.py", line 177, in updateVehicle
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/Plugins/BMW ConnectedDrive.indigoPlugin/Contents/Server Plugin/bmwcdapi.py", line 149, in get_vehicle_data
TypeError: 'NoneType' object has no attribute '__getitem__'

   BMW Connected Drive Error       plugin runConcurrentThread function returned or failed (will attempt again in 10 seconds)
   BMW Connected Drive Debug       runConcurrentThread starting


Posted on
Wed Feb 26, 2020 6:57 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New Plugin - BMW Connected Drive

What version MacOS you running?

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Wed Feb 26, 2020 7:17 pm
ryanbuckner offline
Posts: 1080
Joined: Oct 08, 2011
Location: Northern Virginia

Re: New Plugin - BMW Connected Drive

Sierra 10.12.6

It had been working fine up until today. I tested my credentials on the website and they passed.

Posted on
Wed Feb 26, 2020 7:19 pm
FlyingDiver offline
User avatar
Posts: 7222
Joined: Jun 07, 2014
Location: Southwest Florida, USA

Re: New Plugin - BMW Connected Drive

ryanbuckner wrote:
Sierra 10.12.6

It had been working fine up until today. I tested my credentials on the website and they passed.


You're running into the SSL/TLS issue. They must have just upgraded their servers.

Code: Select all
   BMW Connected Drive Error       get_tokens AUTH Error, exception = [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:590)


The only fix is to upgrade to at least High Sierra.

joe (aka FlyingDiver)
my plugins: http://forums.indigodomo.com/viewforum.php?f=177

Posted on
Sat Apr 25, 2020 3:57 am
Turribeach offline
Posts: 429
Joined: Feb 06, 2015
Location: London, UK

Re: New Plugin - BMW Connected Drive

Hi, great plugin (once I can get it working) :mrgreen:

I installed the plugin, created the account device and then when I try to create the Vehicle device I get this error:

Code: Select all
   BMW Connected Drive Debug       ConnectedDrive get_vehicles
   BMW Connected Drive Error       Error in plugin execution GetUiDynamicList:

Traceback (most recent call last):
  File "plugin.py", line 258, in get_vehicle_list
  File "/Library/Application Support/Perceptive Automation/Indigo 7.4/Plugins/BMW ConnectedDrive.indigoPlugin/Contents/Server Plugin/bmwcdapi.py", line 145, in get_vehicles
TypeError: 'NoneType' object has no attribute '__getitem__'


Any ideas?

Posted on
Sat Apr 25, 2020 3:59 am
Turribeach offline
Posts: 429
Joined: Feb 06, 2015
Location: London, UK

Re: New Plugin - BMW Connected Drive

OK I think I know what happened, I was too eager! It seems I needed to give the plugin some time to query the API to get the vehicles. It's working now...

Posted on
Sun Apr 26, 2020 4:53 pm
Turribeach offline
Posts: 429
Joined: Feb 06, 2015
Location: London, UK

Re: New Plugin - BMW Connected Drive

So here is my first try at using this plugin. I wrote a script that checks if my car is at home. If it is at home then it checks the car is locked (doors, windows, hood, sunroof and trunk) and the alarm is activated. If it is not it will send me a Pushover alert. I added a few configuration options like repeated alerts and the option to override alerts with a variable. I will expose this in Indigo Touch so I can silent the alert if I need to. At the moment I am running the script with a trigger with UI Status has any change but it will be great if the plugin allowed me to select the device's Last Update Date/Time so I can fire off my code at every refresh from the plugin. Feel free to add this to the plugin if you think it's useful.

Thanks,
Christian

Code: Select all
# Imports
import string
import datetime
from math import radians, cos, sin, asin, sqrt

# Constants
home_lat = 50.1234567             # Your home latitude, get it from Google maps by clicking on your house
home_log = 0.1234567              # Your home longitude, get it from Google maps by clicking on your house
car_device_id = 123456789       # Device ID of the vehicle you created with the Connected Drive plugin
geo_distance_unit = "meters"     # meters or miles
geo_fence_distance = 50          # How big you want the geofence to be for your car to be considered at home
wait_minutes_before_alert = 5    # How many minutes to wait before sending an alert
repeat_alerts = True             # Set to false to not receive the same alert repeatedly every time the Connected Drive plugin refreshes the data
variables_folder_id = 987654321  # Folder ID where you want the variables that this script uses to be created

# Functions
def log(msg):
   indigo.server.log(msg, type="Check Car is Locked")

def haversine_distance(lon1, lat1, lon2, lat2):
   # convert decimal degrees to radians
   lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
   # haversine formula
   dlon = lon2 - lon1
   dlat = lat2 - lat1
   a = sin(dlat/2)**2 + cos(lat1) * cos(lat2) * sin(dlon/2)**2
   c = 2 * asin(sqrt(a))
   if geo_distance_unit == "meters":
      r = 6371 # Radius of earth in kilometers
   if geo_distance_unit == "miles":
      r = 3956 # Radius of earth in miles
   return round(c * r, 2)

# Main code
my_car = indigo.devices[car_device_id]
my_car_name = my_car.name
my_car_lat_pos = my_car.states["s_position_lat"]
my_car_lon_pos = my_car.states["s_position_lon"]
car_open = False
message_and = ""
alert_message = ""

varName = my_car_name.replace(" ", "_") + "_Alert_Active"
try:
   alert_active_var = indigo.variables[varName]
except:
   indigo.variable.create(varName, value="false", folder=variables_folder_id)
   alert_active_var = indigo.variables[varName]

alert_active = alert_active_var.value

varName = my_car_name.replace(" ", "_") + "_Override_Alert"
try:
   override_alert = indigo.variables[varName].value
except:
   indigo.variable.create(varName, value="false", folder=variables_folder_id)
   override_alert = indigo.variables[varName].value

# Calculate distance from homer to the current reported position of the car
distance_from_home = haversine_distance(home_lat, home_log, my_car_lat_pos, my_car_lon_pos)

# Make sure the distance is within the geofence
if distance_from_home <= geo_fence_distance:

   car_Last_Updated_DT = datetime.datetime.strptime(my_car.states["s_updateTime"], "%Y-%m-%dT%H:%M:%S+0000")
   car_Last_Updated_DT_str = car_Last_Updated_DT.strftime("%-d-%B-%Y %-H:%M.%S")
   device_Last_Updated_DT = my_car.lastChanged
   device_Last_Updated_DT_str = device_Last_Updated_DT.strftime("%-d-%B-%Y %-H:%M.%S")

   car_minutes_diff = int(round((datetime.datetime.now() - car_Last_Updated_DT).total_seconds() / 60.0, 0))
   device_minutes_diff = int(round((datetime.datetime.now() - device_Last_Updated_DT).total_seconds() / 60.0, 0))

   # Only send alert after wating time is reached
   if car_minutes_diff >= wait_minutes_before_alert:

      log(my_car_name + " distance from home is: " + str(distance_from_home) + " " + geo_distance_unit)
      log("Minutes since last car change: " + str(car_minutes_diff) + " (" + car_Last_Updated_DT_str + ")")
      log("Minutes since last device update: " + str(device_minutes_diff) + " (" + device_Last_Updated_DT_str + ")")

      car_feature_name = []
      car_feature_state = []

      # Fetch all the car features and their statuses
      my_car_status = my_car.states["status"]
      my_car_doors_lock_state = my_car.states["s_doorLockState"]

      car_feature_name.append("Driver Front Door")
      car_feature_name.append("Driver Rear Door")
      car_feature_name.append("Passenger Front Door")
      car_feature_name.append("Passenger Rear Door")
      car_feature_name.append("Driver Front Window")
      car_feature_name.append("Driver Rear Window")
      car_feature_name.append("Passenger Front Window")
      car_feature_name.append("Passenger Rear Window")
      car_feature_name.append("Hood")
      car_feature_name.append("Sunroof")
      car_feature_name.append("Trunk")

      car_feature_state.append(my_car.states["s_doorDriverFront"])
      car_feature_state.append(my_car.states["s_doorDriverRear"])
      car_feature_state.append(my_car.states["s_doorPassengerFront"])
      car_feature_state.append(my_car.states["s_doorPassengerRear"])
      car_feature_state.append(my_car.states["s_windowDriverFront"])
      car_feature_state.append(my_car.states["s_windowDriverRear"])
      car_feature_state.append(my_car.states["s_windowPassengerFront"])
      car_feature_state.append(my_car.states["s_windowPassengerRear"])
      car_feature_state.append(my_car.states["s_hood"])
      car_feature_state.append(my_car.states["s_sunroof"])
      car_feature_state.append(my_car.states["s_trunk"])

      # Loop through list to check any features not Closed
      for idx, state in enumerate(car_feature_state):
         if state not in "CLOSED":
            car_open = True
            log(car_feature_name[idx] + " is " + state.title())
            alert_message = alert_message + message_and + car_feature_name[idx] + " is " + state.title()
            message_and = " and "

      # Make sure care is not just LOCKED but also SECURED (alarm on)
      if my_car_status not in "SECURED" or my_car_doors_lock_state not in "SECURED":
         car_open = True
         log("Car status: " + my_car_status.title() + " / Doors Lock State: " + my_car_doors_lock_state.title())
         if alert_message:
            log(alert_message)

      # The conditions for the alert are: car is not secured and either first time alert or we want repeated alerts and no override
      if car_open and (alert_active == "false" or repeat_alerts) and override_alert == "false":

         msg_body = "Car is at home (distance " + str(distance_from_home) + " " + geo_distance_unit + "). Car status: " + my_car_status.title() + " / Doors Lock State: " + my_car_doors_lock_state.title()
         if alert_message:
            msg_body = msg_body + ". " + alert_message + "."

         PushoverPlugin = indigo.server.getPlugin('io.thechad.indigoplugin.pushover')
         if PushoverPlugin.isEnabled():
            PushoverAlertProps = {'msgTitle'       : my_car_name + " alert",
                                     'msgBody'        : msg_body,
                                     'msgSound'       :'pushover',
                                     'msgPriority'    :'1',
                                     'msgDevice'      :'',
                                     'msgSupLinkUrl'  :'',
                                     'msgSupLinkTitle':''
                                     } 
            PushoverPlugin.executeAction("send", props=PushoverAlertProps)
         else:
            indigo.server.log('Error: Pushover plugin is not available!')
         alert_active = "true"
      else:
         # Car is at home but secured so reset any active alerts
         alert_active = "false"
else:
   # Car no longer at home so reset any active alerts
   alert_active = "false"

# Save back value to variable
indigo.variable.updateValue(alert_active_var, alert_active)

Posted on
Sun May 10, 2020 5:46 am
tomet offline
Posts: 6
Joined: Sep 30, 2014

Re: New Plugin - BMW Connected Drive

Hey mate, loving the API. Works well on retrieving the status of the vehicle.

However, it would seem that the actions are yet to be completed to send commands to the car, lock/unlock, etc. Do you have any plans to implement these in the near future?

I'm happy to test with you. I have done API development in the past but my attempts to modify your plugin to send the commands have not been successful for me.

Let me know.

Cheers

Page 4 of 12 1, 2, 3, 4, 5, 6, 7 ... 12

Who is online

Users browsing this forum: No registered users and 5 guests