BigThunderSR / onstar2mqtt

OnStarJS wrapper for MQTT
MIT License
17 stars 6 forks source link

onstar2mqtt

ci CodeQL release

A service that utilizes the OnStarJS library to expose OnStar data to MQTT topics. Please note that only US and Canadian OnStar accounts are known to work with this integration.

The functionality is mostly focused around EVs (specifically the Bolt EV), however PRs for other vehicle types are certainly welcome.

There is no affiliation with this project and GM, Chevrolet nor OnStar. In fact, it would be nice if they'd even respond to development requests so we wouldn't have to reverse engineer their API.

Running

Collect the following information:

  1. Generate a v4 uuid for the device ID
  2. OnStar login: username, password, PIN, TOTP Key (Please click link for instructions)
  3. Your car's VIN. Easily found in the monthly OnStar diagnostic emails.
  4. MQTT server information: hostname, username, password
    1. If using TLS, define MQTT_PORT and MQTT_TLS=true
    2. NEW! - Provide MQTT topic (MQTT_ONSTAR_POLLING_STATUS_TOPIC) for Onstar Data Polling Status to monitor success/failure when OnStar is polled for data
      • MQTT_ONSTAR_POLLING_STATUS_TOPIC/lastpollsuccessful - "true" or "false" depending on status of last poll
      • MQTT_ONSTAR_POLLING_STATUS_TOPIC/state - Polling Status and Detailed Error Messages in JSON
      • NEW! - Automatic creation of pollingStatusTopic starting at v1.11.0
        • No longer need to specify MQTT_ONSTAR_POLLING_STATUS_TOPIC as this is now created automatically
        • Format is "homeassistant/YOUR_CAR_VIN/polling_status/"
        • If it is explicitly specified, will use the specified value, so does not break backwards compatibility

Supply these values to the ENV vars below. The default data refresh interval is 30 minutes and can be overridden with ONSTAR_REFRESH with values in milliseconds.

Helpful Usage Notes

Docker

Docker Hub

docker run \
  --env ONSTAR_DEVICEID= \
  --env ONSTAR_VIN= \
  --env ONSTAR_USERNAME= \
  --env ONSTAR_PASSWORD= \
  --env ONSTAR_TOTP= \
  --env ONSTAR_PIN= \
  --env TOKEN_LOCATION \ ## NOTE: This is optional and allows you to save/read tokens from persistent storage
  --env MQTT_HOST= \
  --env MQTT_USERNAME \
  --env MQTT_PASSWORD \
  --env MQTT_ONSTAR_POLLING_STATUS_TOPIC \
  bigthundersr/onstar2mqtt:latest

GitHub Container Registry

docker run \
  --env ONSTAR_DEVICEID= \
  --env ONSTAR_VIN= \
  --env ONSTAR_USERNAME= \
  --env ONSTAR_PASSWORD= \
  --env ONSTAR_TOTP= \
  --env ONSTAR_PIN= \
  --env TOKEN_LOCATION \ ## NOTE: This is optional and allows you to save/read tokens from persistent storage
  --env MQTT_HOST= \
  --env MQTT_USERNAME \
  --env MQTT_PASSWORD \
  --env MQTT_ONSTAR_POLLING_STATUS_TOPIC \
  ghcr.io/bigthundersr/onstar2mqtt:latest

docker-compose

Docker Hub

  onstar2mqtt:
    container_name: onstar2mqtt
    image: bigthundersr/onstar2mqtt
    restart: unless-stopped
    env_file:
      - /srv/containers/secrets/onstar2mqtt.env
    environment:
    - ONSTAR_DEVICEID=
    - ONSTAR_VIN=
    - MQTT_HOST=

GitHub Container Registry

  onstar2mqtt:
    container_name: onstar2mqtt
    image: ghcr.io/bigthundersr/onstar2mqtt
    restart: unless-stopped
    env_file:
      - /srv/containers/secrets/onstar2mqtt.env
    environment:
    - ONSTAR_DEVICEID=
    - ONSTAR_VIN=
    - MQTT_HOST=

onstar2mqtt.env:

ONSTAR_USERNAME=
ONSTAR_PASSWORD=
ONSTAR_TOTP=
ONSTAR_PIN=
TOKEN_LOCATION=  # (NOTE: This is optional and allows you to save/read tokens from persistent storage)
MQTT_USERNAME=
MQTT_PASSWORD=
MQTT_ONSTAR_POLLING_STATUS_TOPIC=

Node.js

It's a typical node.js application, define the same environment values as described in the docker sections and run with: npm run start. Currently, this is only tested with Node.js 18.x.

Home Assistant configuration templates

MQTT auto discovery is enabled. For further integrations and screenshots see HA-MQTT.md.

Development

Running with npm

npm run start

Testing

npm run test

Coverage

npm run coverage

Releases

npm version [major|minor|patch] -m "Version %s" && git push --follow-tags

Publish the release on GitHub to trigger a release build (i.e. update 'latest' docker tag).

If you would like to run this as a Home Assistant add-on

https://github.com/BigThunderSR/homeassistant-addons-onstar2mqtt

My other related project which provides additional capabilities through Node-RED

https://github.com/BigThunderSR/node-red-contrib-onstar2