Home Assistant and my WRX
I installed the experimental Subaru Starlink integration plugin to Home Assistant last week. There is an underlying library for accessing Starlink, but since I already have Home Assistant I decided to attempt to use that. There are features in the underlying library that are not available to home assistant, but for now most of what I want is in the homelink integration.
The integration itself produces a relatively simple dashboard in Home Assistant. It has both controls and sensors. I'm mainly interested in the sensors as I want to be able to log then and send myself alerts.
I also want to be able to log this data to my time series database. To do this, I set up an automation in Home Assistant that watches each of these sensors and pushes them to my MQTT broker if there's an update. It took a while to figure out how to configure the automation to be relatively robust against bad input:
alias: WRX to MQTT (Tracker)
description: Publish WRX Device Tracker updates to MQTT
trigger:
- platform: state
entity_id: device_tracker.orange
condition: []
action:
- service: mqtt.publish
metadata: {}
data:
qos: 1
retain: true
topic: wrx/device_tracker
payload: |
{{
{
"entity_id": trigger.entity_id,
"location": states(trigger.entity_id),
"latitude": state_attr(trigger.entity_id, 'latitude'),
"longitude": state_attr(trigger.entity_id, 'longitude'),
"position_timestamp": state_attr(trigger.entity_id, 'Position timestamp').isoformat() if state_attr(trigger.entity_id, 'Position timestamp') is not none else None
} | tojson | safe
}}
mode: queued
max: 10
The result shown in MQTT Explorer is something like this (not all fields shown):
Next up is a Node Red flow that grabs these MQTT messages and stuffs them into the appropriate place in TimescaleDB.
The first thing I intend to do with this is to set up an alarm to notify me if I parked somewhere and forgot to close my sunroof. I haven't had a sunroof in a really long time, so I'm not yet back in the habit of checking it. Next after that will be to set up my own triggers on maintenance intervals. Starlink does some of this on its own but it doesn't know about my own "special" maintenance, especially things like taking the car to the detailer annually to have the paint protection film inspected.
It's pretty fun. It's both more and less than I had hoped for - it is very cool, but I would like, for example, to get a complete list of DTCs. I suspect StarLink has a lot of this kind of information they don't expose to the end user.
The way this starlink library came to be is pretty interesting. The author found that the Web based API changed, so he is using the mobile app API (which inexplicably is different). I thought it would be much more diffficult to reverse engineer the protocol using android or ios. I had visions of trying to intercept encrypted traffic using the Android debugger - ugh. It turned out to be much simpler. The Subaru StarLink app store apps are Apache Cordova, which basically means that they are HTML and javascript inside. The Javascript is relatively easy to extract from the APK and examine. I haven't done this myself but the author explained to me that it was pretty straight-forward, and that the mobile API has - so far - been pretty stable. I will make one complaint about something that irritates me - numbers (like odometer and fuel level) come through the JSON as strings rather than numbers. It's easy enough to convert them, but it still feels sloppy to me. If Harmon-Kardon had anything to do with this software then it doesn't surprise me. H-K software is not the greatest, and their support and responsiveness has gotten far worse since they were bought by Samsung. My Gold Wing is a pretty amazing machine; the software was all done by H-K and I give them a "C" grade at best, in terms of features, reliability, and general tenets of good UI design. (The number if clicks it takes to pop back and forth between Android Auto and SXM controls is, on my motorcycle, something for which I think H-K should be charged criminally).
No comments:
Post a Comment