Docker Container with gateway between Polestar API and MQTT
Credits to Niklas Vieth (@hniklasvieth) for the great work on the Polestar SoC iOS Medium Widget (https://github.com/niklasvieth/polestar-ios-medium-widget).
This Software is based on this work and partly made with ChatGPT 4.0.
The initial prompt for ChatGPT was taken from @demichve on the German Polestar Forum (https://polestar.fans/t/soc-medium-homescreen-widget-ios/17121/41?u=consulitas). Just because this was currently running on my phone. :-)
If ChatGPT has been involved in development steps here, this will be shown in the comments to corresponding commits in this repository.
Heads up: This is work in progress, but now usable.
- Pull requests welcome!
- Issues welcome!
This project now uses two local env files:
.env: shared credentials and sensitive values for Docker Compose andrun_local.sh.env_local: local runtime values used byrun_local.sh
Both files are ignored by git. Versionable templates are provided as .env.example and .env_local.example.
Used by:
docker compose./run_local.sh
Typical content:
POLESTAR_EMAIL="you@example.com"
POLESTAR_PASSWORD="your-polestar-password"
POLESTAR_VIN="your-vin-without-spaces"
MQTT_USER=""
MQTT_PASSWORD=""Notes:
- keep
MQTT_USERandMQTT_PASSWORDempty if your broker has no login POLESTAR_VINmust not contain spaces
Used by:
./run_local.sh
Typical content:
TZ="Europe/Berlin"
POLESTAR_CYCLE="270"
MQTT_BROKER="mqtt.example.local"
MQTT_PORT="1883"
MQTT_BASE_TOPIC="polestar2"
OPENWB_HOST="openwb.example.local"
OPENWB_PUBLISH="True"
OPENWB_PORT="1883"
OPENWB_LP_NUM="1"Notes:
- this file is only needed for local non-container execution
- adjust
OPENWB_*values only if you want direct forwarding to OpenWB v1
The container now mounts ./local-files to /local-files.
If /local-files/graphql_queries.py exists inside the container, the app prefers that file over the built-in src/graphql_queries.py. This lets you customize GraphQL queries without modifying the shipped source code.
Included template:
Usage:
- copy
local-files/graphql_queries.py_sampletolocal-files/graphql_queries.py - adjust the queries or payload builders as needed
- restart the container
Keep the function names build_getconsumercarsv2_payload() and build_cartelematicsv2_payload(vin) unchanged, because the main program imports exactly these names.
- install Docker: https://docs.docker.com/engine/install/
- download
docker-compose_example.yml - rename it to
docker-compose.yml(remove_example) - create
.envfrom.env.example - optionally create
local-files/graphql_queries.pyfromlocal-files/graphql_queries.py_sample - edit the remaining values under
environment:indocker-compose.yml - start the container with
docker compose upordocker compose up -d
The compose setup mounts ./local-files into the container automatically.
- create
.envfrom.env.example - create
.env_localfrom.env_local.example - adjust both files to your environment
- run
./run_local.sh
run_local.sh creates .venv if needed, installs Python dependencies, and then starts the app locally.
Discussions (in german ) here: https://polestar.fans/t/polestar-api-zu-mqtt-im-container/18589
- set
OPENWB_HOST: "ip/dns name of openWB" - set
OPENWB_PUBLISH: True - optionally set
OPENWB_PORTandOPENWB_LP_NUM- if not set it defaults to port 1883 and 1 (which results in topicopenWB/set/lp/1/%Soc)