Car integration
-
I have been wondering what to post here so bear with me as I am just having a bit of fun given the fact that I haven't had much to fix, improve on or optimize for my home automation setup, I just added a scene today to make a TTS announcement to remind me to plug in my car when its level is low. Not really a necessity but since I have not been commuting anymore for a few months, I caught myself a few times wishing I had recharged my car the day before.
This is what it looks like on openLuup:
I reused a SiteSensor device which was polling my HomeAssistant integration for its lock status (Yes I can get openLuup to lock and unlock my car remotely) and made Home Assistant send the battery status.
To do this, I added a rest service command on home assistant:
rest_command: bmw_bat: url: "http://openLuupIP:3480/data_request?id=variableset&DeviceNum=26&serviceId=urn:micasaverde-com:serviceId:HaDevice1&Variable=BatteryLevel&Value={{states('sensor.i3_charging_level_hv')}}"
Note the device number which will need to be the device you want to send the battery status to and the home assistant entity which you will have to replace with the one you want. Then I created an automation on home assistant to trigger this service whenever the entity state changes.
After that I just simply created a scene on openLuup to watch the battery level variable and do whatever I need to do with it.
This is an example of syncing entities in home-assistant to openLuup. I have a number of other similar integrations...
-
NICE! Reminds me of the time I tried (and failed) to connect my car with Vera using a HomeLink transceiver (which itself was probably broken - bought it on eBay). Coulda been cool. Newer cars have WiFi which is a handy way to detect presence on the network (e.g. using SiteSensor plug-in or similar).
I'm sure your foray into this area will inspire others.
-
I am sure there are more complete integrations like Tesla like what @mrFarmer's plugin does. My modest car is actually quite old... just new enough to have web service with satellite link for some basic functions. Nope... not even wifi but it's fun to play with.
-
Intriguing! I have openLuup, and I have an i3... what am I missing?
-
therealdbreplied to akbooer on Mar 9, 2021, 9:39 AM last edited by therealdb Mar 9, 2021, 4:41 AM
@akbooer there's an BMW integration for Home Assistant (that I've ported it to my own C# framework just for fun). I've a POC getting the car state too, but I'm still on diesel, so it's not really useful to me, since I'd only get door status, mileage and similar things.
the APIs are unofficial and are blocked when the car is moving but they are precise enough. you could also honk, turn on the lights, etc. since it's a reverse engineer of the app, you'd do anything available in the app.
EDIT: my BMW has a 4g sim inside, so it's always connected. I think ConnectedDrive is always available for electric cars.
-
rafale77replied to akbooer on Mar 9, 2021, 3:01 PM last edited by rafale77 Mar 9, 2021, 10:06 AM
yep, @therealdb is correct, this is simply using the bmw connected integration on home assistant. I just wanted to give an example of how to set up an uplink connection from a home assistant entity to openLuup. I am running about 30 devices this way and another dozen using the sitesensor plugin.
Even a gas/petrol/diesel car can get you the fuel level, it's just a different entity/API endpoint. I use mine to check that my windows are rolled up, turn on the heat at certain time (preheat the cabin while it is plugged) when I was commuting and the weather was cold (all done with openLuup scenes). In the example above, I used SitenSensor "arm/disarm" status to trigger a scene to lock/unlock the car and SiteSensor readsback the status and it "trips/untrips" according to its alarm status.
-
toggledbitsreplied to rafale77 on Mar 9, 2021, 3:03 PM last edited by toggledbits Mar 9, 2021, 10:28 AM
@rafale77 said in Car integration:
using the bmw connected integration on home assistant.
There's a file called
hass_states.json
inlogs
on 21067 (the first part may be different if you used a different controller ID in MSR). Would you mind sending me that file so I can examine the domain and services associated with the car integration?Edit: actually two files:
hass_states.json
andhass_services.json
-
Will do! I will update this post in a bit.
See the two json files you requested attached.
Note: After updating to 21067, I am getting new errors on both the hass websocket connection and the openLuup connection as shown below:
-
@rafale77 said in Car integration:
Even a gas/petrol/diesel car can get you the fuel level, it's just a different entity/API endpoint. I use mine to check that my windows are rolled up, turn on the heat at certain time (preheat the cabin while it is plugged) when I was commuting and the weather was cold (all done with openLuup scenes). In the example above, I used SitenSensor "arm/disarm" status to trigger a scene to lock/unlock the car and SiteSensor readsback the status and it "trips/untrips" according to its alarm status.
I'll grab a couple of your ideas for the future, since we're opening an office near me.
-
toggledbitsreplied to rafale77 on Mar 9, 2021, 6:01 PM last edited by toggledbits Mar 9, 2021, 1:15 PM
@rafale77 said in Car integration:
Note: After updating to 21067, I am getting new errors on both the hass websocket connection and the openLuup connection as shown below:
Cover/position messages are just my midwork at getting the cover domain working on Hass when I don't own any cover devices myself. File attached should quiet those messages.
The message on the openLuup side is pretty dire. It suggests that either the user_data or status response
devices
astates
subkey is not an array, and that is unexpected. What version of openLuup are you on? -
I am running 21.03.04. I will update when I get a break from work.
-
No need, I think I know what it is. Since openLuup is implemented in Lua, unless you take special action, the JSON library doesn't know whether to convert an empty table to array form
[]
or dictionary form{}
, so it defaults to the latter. So I suspect there is some device of yours that has no states, so thestates
array is empty, and openLuup's JSON library is emitting{}
for it instead of[]
, and the more literal parser in node/JS, which of course does distinguish between empty array and empty dictionary, is seeing an unexpected data type and therefore doesn't have a member method it wants.I can code around it, but I think @akbooer should also guard for empty tables in his code so that the response format stays consistent (with both itself and Vera Luup). I had to do a bunch of this my Lua plugins that use JSON, too.
-
@toggledbits said in Car integration:
I think @akbooer should also guard for empty tables in his code
Happy to help. You’re suggesting that any empty table should be reported as an empty array?
-
@akbooer said in Car integration:
You’re suggesting that any empty table should be reported as an empty array?
Not exactly. I'm saying it should be emitted consistent with its usage. In this case, the
states
key should always be an array. So it should be an array whether it is empty or not. In another place (no example comes to mind) where the expected data type would be an object, then it should be an object whether it contains keys or not. -
Not so easy, then. To me, this is not a very clever use of JSON, ascribing meaning when there is none, really.
-
Actually, it's Lua's fault, because it doesn't give JSON any hint to know if any empty table is actually an empty array or an empty object. But it has significant meaning to clients using your JSON output. If
states
is meant to be an array, then it should always be an array and formatted as one in the JSON output. That's the definition of data returned by Luup. If the data types are not stable in an API, that makes it pretty hard to make sure code that uses the API can handle the responses, as in this case. -
Was playing with the notification service to send messages to the car from openLuup. Not very useful on my car since it shows up in the mail box and not on the dashboard forcing me to navigate to go look at the message... oh well. It's there now if I ever want to do something with it. I will make do with honking for now.
-
Subaru owners with an active StarLink subscription may wish to explore https://pypi.org/project/subarulink/
6/19