mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-08-13 19:29:52 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50b5eb9863 | ||
|
|
02793accfa | ||
|
|
4d8b5e5006 | ||
|
|
e8315ba0fd | ||
|
|
4fca54b19f | ||
|
|
a411a1a59d | ||
|
|
a51ba25061 | ||
|
|
1d37b3aca7 | ||
|
|
1574fa968c |
@@ -12,9 +12,12 @@ Maybe this component works also with other Volvo cars. Please try out the native
|
|||||||
- XC90 T8 PHEV (2023)
|
- XC90 T8 PHEV (2023)
|
||||||
- XC60 PHEV (2023)
|
- XC60 PHEV (2023)
|
||||||
- XC60 PHEV (2022)
|
- XC60 PHEV (2022)
|
||||||
- V90 PHEV T8 (2019)
|
- V90 PHEV T8 (2019)*
|
||||||
|
|
||||||
|
*only partly working
|
||||||
|
|
||||||
|
Please let me know if your car works with this addon so I can expand the list!<br>
|
||||||
|
|
||||||
Please let me know if your car works with this addon so I can expand the list!
|
|
||||||
|
|
||||||
## Supported features
|
## Supported features
|
||||||
- Lock/unlock car
|
- Lock/unlock car
|
||||||
@@ -41,7 +44,7 @@ NOTE: Energy status currently available only for cars in the Europe / Middle Eas
|
|||||||
Just install this addon with the following command.
|
Just install this addon with the following command.
|
||||||
Please note to fill in your settings inside the environment variables.
|
Please note to fill in your settings inside the environment variables.
|
||||||
|
|
||||||
`docker run -d --pull=always -e CONF_updateInterval=300 -e CONF_babelLocale='de' -e CONF_mqtt='@json {"broker": "", "username": "", "password": ""}' -e CONF_volvoData='@json {"username": "", "password": "", "vin": "", "vccapikey": "", "odometerMultiplier": 1}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest`
|
`docker run -d --pull=always -e CONF_updateInterval=300 -e CONF_babelLocale='de' -e CONF_mqtt='@json {"broker": "", "username": "", "password": "", "port": 1883}' -e CONF_volvoData='@json {"username": "", "password": "", "vin": "", "vccapikey": "", "odometerMultiplier": 1}' -e TZ='Europe/Berlin' --name volvo2mqtt ghcr.io/dielee/volvo2mqtt:latest`
|
||||||
|
|
||||||
<b>HA Add-On:</b><br>
|
<b>HA Add-On:</b><br>
|
||||||
|
|
||||||
@@ -53,7 +56,7 @@ Here is what every option means:
|
|||||||
| -------------------- | :-------: | :----------: | --------------------------------------------------------------- |
|
| -------------------- | :-------: | :----------: | --------------------------------------------------------------- |
|
||||||
| `CONF_updateInterval` | `int` | **required** | Update intervall in seconds. |
|
| `CONF_updateInterval` | `int` | **required** | Update intervall in seconds. |
|
||||||
| `CONF_babelLocale` | `string` | **required** | Select your country from this [list](https://www.ibm.com/docs/en/radfws/9.7?topic=overview-locales-code-pages-supported). "Locale name" is the column you need! |
|
| `CONF_babelLocale` | `string` | **required** | Select your country from this [list](https://www.ibm.com/docs/en/radfws/9.7?topic=overview-locales-code-pages-supported). "Locale name" is the column you need! |
|
||||||
| `CONF_mqtt` | `json` | **required** | Broker = Mqtt Broker IP / Username and Passwort are optional! |
|
| `CONF_mqtt` | `json` | **required** | Broker = Mqtt Broker IP / Username and Passwort are optional! Broker port can be changed. If no value is given, port 1883 will be used. |
|
||||||
| `CONF_volvoData` | `json` | **required** | Username and password are REQUIRED. Car vin can be a single vin or a list of multiple vins like `["vin1", "vin2"]`. If no vin is provided, <b>ALL</b> of your vehicles will be used. Vccapi key is REQUIRED. Get your Vccapi key from [here](https://developer.volvocars.com/account/). Odometer Multiplier is sometimes 10, sometimes 1. Try what's right for your car. If you leave it empty, the multiplier will be 1. |
|
| `CONF_volvoData` | `json` | **required** | Username and password are REQUIRED. Car vin can be a single vin or a list of multiple vins like `["vin1", "vin2"]`. If no vin is provided, <b>ALL</b> of your vehicles will be used. Vccapi key is REQUIRED. Get your Vccapi key from [here](https://developer.volvocars.com/account/). Odometer Multiplier is sometimes 10, sometimes 1. Try what's right for your car. If you leave it empty, the multiplier will be 1. |
|
||||||
| `CONF_debug` | `string` | | Debug option (true/false) - optional! |
|
| `CONF_debug` | `string` | | Debug option (true/false) - optional! |
|
||||||
| `TZ` | `string` | | Container timezone eg "Europe/Berlin" |
|
| `TZ` | `string` | | Container timezone eg "Europe/Berlin" |
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,6 @@
|
|||||||
name: "Volvo2Mqtt"
|
name: "Volvo2Mqtt"
|
||||||
description: "Volvo AAOS MQTT bridge"
|
description: "Volvo AAOS MQTT bridge"
|
||||||
version: "1.4.0"
|
version: "1.4.3"
|
||||||
slug: "volvo2mqtt"
|
slug: "volvo2mqtt"
|
||||||
init: false
|
init: false
|
||||||
url: "https://github.com/Dielee/volvo2mqtt"
|
url: "https://github.com/Dielee/volvo2mqtt"
|
||||||
@@ -11,6 +11,7 @@ options:
|
|||||||
debug: false
|
debug: false
|
||||||
mqtt:
|
mqtt:
|
||||||
broker: null
|
broker: null
|
||||||
|
port: 1883
|
||||||
username: ""
|
username: ""
|
||||||
password: ""
|
password: ""
|
||||||
volvoData:
|
volvoData:
|
||||||
@@ -25,6 +26,7 @@ schema:
|
|||||||
debug: bool
|
debug: bool
|
||||||
mqtt:
|
mqtt:
|
||||||
broker: str
|
broker: str
|
||||||
|
port: int(1,)
|
||||||
username: str?
|
username: str?
|
||||||
password: str?
|
password: str?
|
||||||
volvoData:
|
volvoData:
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,6 @@
|
|||||||
from config import settings
|
from config import settings
|
||||||
|
|
||||||
VERSION = "v1.4.0"
|
VERSION = "v1.4.3"
|
||||||
|
|
||||||
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
|
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
|
||||||
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
|
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
|
||||||
@@ -19,6 +19,8 @@ ENGINE_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/
|
|||||||
BATTERY_CHARGE_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/battery-charge-level"
|
BATTERY_CHARGE_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/battery-charge-level"
|
||||||
FUEL_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/fuel"
|
FUEL_STATE_URL = "https://api.volvocars.com/connected-vehicle/v2/vehicles/{0}/fuel"
|
||||||
|
|
||||||
|
availability_topic = "volvoAAOS2mqtt/availability"
|
||||||
|
|
||||||
charging_system_states = {"CHARGING_SYSTEM_CHARGING": "Charging", "CHARGING_SYSTEM_IDLE": "Idle",
|
charging_system_states = {"CHARGING_SYSTEM_CHARGING": "Charging", "CHARGING_SYSTEM_IDLE": "Idle",
|
||||||
"CHARGING_SYSTEM_FAULT": "Fault", "CHARGING_SYSTEM_UNSPECIFIED": "Unspecified"}
|
"CHARGING_SYSTEM_FAULT": "Fault", "CHARGING_SYSTEM_UNSPECIFIED": "Unspecified"}
|
||||||
|
|
||||||
|
|||||||
+26
-6
@@ -2,12 +2,13 @@ import time
|
|||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import json
|
import json
|
||||||
import volvo
|
import volvo
|
||||||
|
from util import keys_exists
|
||||||
from threading import Thread, Timer
|
from threading import Thread, Timer
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from babel.dates import format_datetime
|
from babel.dates import format_datetime
|
||||||
from config import settings
|
from config import settings
|
||||||
from const import CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
|
from const import CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
|
||||||
CAR_UNLOCK_URL
|
CAR_UNLOCK_URL, availability_topic
|
||||||
|
|
||||||
|
|
||||||
mqtt_client: mqtt.Client
|
mqtt_client: mqtt.Client
|
||||||
@@ -19,9 +20,16 @@ climate_timer = {}
|
|||||||
|
|
||||||
def connect():
|
def connect():
|
||||||
client = mqtt.Client("volvoAAOS2mqtt")
|
client = mqtt.Client("volvoAAOS2mqtt")
|
||||||
|
client.will_set(availability_topic, "offline", 0, False)
|
||||||
if settings["mqtt"]["username"] and settings["mqtt"]["password"]:
|
if settings["mqtt"]["username"] and settings["mqtt"]["password"]:
|
||||||
client.username_pw_set(settings["mqtt"]["username"], settings["mqtt"]["password"])
|
client.username_pw_set(settings["mqtt"]["username"], settings["mqtt"]["password"])
|
||||||
client.connect(settings["mqtt"]["broker"])
|
port = 1883
|
||||||
|
if keys_exists(settings["mqtt"], "port"):
|
||||||
|
conf_port = settings["mqtt"]["port"]
|
||||||
|
if isinstance(conf_port, int):
|
||||||
|
if conf_port > 0:
|
||||||
|
port = settings["mqtt"]["port"]
|
||||||
|
client.connect(settings["mqtt"]["broker"], port)
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
client.on_message = on_message
|
client.on_message = on_message
|
||||||
client.on_disconnect = on_disconnect
|
client.on_disconnect = on_disconnect
|
||||||
@@ -32,6 +40,7 @@ def connect():
|
|||||||
|
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, rc):
|
def on_connect(client, userdata, flags, rc):
|
||||||
|
mqtt_client.publish(availability_topic, "online")
|
||||||
if len(subscribed_topics) > 0:
|
if len(subscribed_topics) > 0:
|
||||||
for topic in subscribed_topics:
|
for topic in subscribed_topics:
|
||||||
mqtt_client.subscribe(topic)
|
mqtt_client.subscribe(topic)
|
||||||
@@ -70,10 +79,10 @@ def on_message(client, userdata, msg):
|
|||||||
elif "lock_status" in msg.topic:
|
elif "lock_status" in msg.topic:
|
||||||
if payload == "LOCK":
|
if payload == "LOCK":
|
||||||
volvo.api_call(CAR_LOCK_URL, "POST", vin)
|
volvo.api_call(CAR_LOCK_URL, "POST", vin)
|
||||||
update_car_data(True)
|
update_car_data(True, {"entity_id": "lock_status", "state": "LOCKED"})
|
||||||
elif payload == "UNLOCK":
|
elif payload == "UNLOCK":
|
||||||
volvo.api_call(CAR_UNLOCK_URL, "POST", vin)
|
volvo.api_call(CAR_UNLOCK_URL, "POST", vin)
|
||||||
update_car_data(True)
|
update_car_data(True, {"entity_id": "lock_status", "state": "UNLOCKED"})
|
||||||
elif "update_data" in msg.topic:
|
elif "update_data" in msg.topic:
|
||||||
if payload == "PRESS":
|
if payload == "PRESS":
|
||||||
update_car_data(True)
|
update_car_data(True)
|
||||||
@@ -88,7 +97,7 @@ def update_loop():
|
|||||||
time.sleep(settings["updateInterval"])
|
time.sleep(settings["updateInterval"])
|
||||||
|
|
||||||
|
|
||||||
def update_car_data(force_update=False):
|
def update_car_data(force_update=False, overwrite={}):
|
||||||
global last_data_update
|
global last_data_update
|
||||||
last_data_update = format_datetime(datetime.now(), format="medium", locale=settings["babelLocale"])
|
last_data_update = format_datetime(datetime.now(), format="medium", locale=settings["babelLocale"])
|
||||||
for vin in volvo.vins:
|
for vin in volvo.vins:
|
||||||
@@ -96,10 +105,19 @@ def update_car_data(force_update=False):
|
|||||||
if entity["domain"] == "button":
|
if entity["domain"] == "button":
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
ov_entity_id = ""
|
||||||
|
ov_state = ""
|
||||||
|
if bool(overwrite):
|
||||||
|
ov_entity_id = overwrite["entity_id"]
|
||||||
|
ov_state = overwrite["state"]
|
||||||
|
|
||||||
if entity["id"] == "climate_status":
|
if entity["id"] == "climate_status":
|
||||||
state = assumed_climate_state[vin]
|
state = assumed_climate_state[vin]
|
||||||
elif entity["id"] == "last_data_update":
|
elif entity["id"] == "last_data_update":
|
||||||
state = last_data_update
|
state = last_data_update
|
||||||
|
else:
|
||||||
|
if entity["id"] == ov_entity_id:
|
||||||
|
state = ov_state
|
||||||
else:
|
else:
|
||||||
state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update)
|
state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update)
|
||||||
|
|
||||||
@@ -126,7 +144,8 @@ def create_ha_devices():
|
|||||||
"icon": f"mdi:{entity['icon']}",
|
"icon": f"mdi:{entity['icon']}",
|
||||||
"state_topic": f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/state",
|
"state_topic": f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/state",
|
||||||
"device": device,
|
"device": device,
|
||||||
"unique_id": f"volvoAAOS2mqtt_{vin}_{entity['id']}"
|
"unique_id": f"volvoAAOS2mqtt_{vin}_{entity['id']}",
|
||||||
|
"availability_topic": availability_topic
|
||||||
}
|
}
|
||||||
if entity.get('unit'):
|
if entity.get('unit'):
|
||||||
config["unit_of_measurement"] = entity["unit"]
|
config["unit_of_measurement"] = entity["unit"]
|
||||||
@@ -146,3 +165,4 @@ def create_ha_devices():
|
|||||||
retain=True
|
retain=True
|
||||||
)
|
)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
mqtt_client.publish(availability_topic, "online")
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"babelLocale": "de",
|
"babelLocale": "de",
|
||||||
"mqtt": {
|
"mqtt": {
|
||||||
"broker": "",
|
"broker": "",
|
||||||
|
"port": 1883,
|
||||||
"username": "",
|
"username": "",
|
||||||
"password": ""
|
"password": ""
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ configuration:
|
|||||||
description: Enable Volvo API debug, normaly this can stay off
|
description: Enable Volvo API debug, normaly this can stay off
|
||||||
mqtt:
|
mqtt:
|
||||||
name: MQTT Broker settings
|
name: MQTT Broker settings
|
||||||
description: Broker is your mqtt broker IP eg "192.168.0.1". Mqtt username and password are optional.
|
description: Broker is your mqtt broker IP eg "192.168.0.1". Mqtt username and password are optional. Broker port can be changed. If no value is given, port 1883 will be used.
|
||||||
volvoData:
|
volvoData:
|
||||||
name: Volvo APP credentials
|
name: Volvo APP credentials
|
||||||
description: You have to enter your Volvo app credentials. The username is normally your email, and the password is the password you use for your Volvo app. The vin can stay empty. The Add-On will use any vin inside your Volvo account. VCCAPI key is required and comes from your Volvo developer account. Odometer multiplier is sometimes 10, sometimes 1. Leave it empty if you don't know what's right. Take a look at the GitHub repo for more information!
|
description: You have to enter your Volvo app credentials. The username is normally your email, and the password is the password you use for your Volvo app. The vin can stay empty. The Add-On will use any vin inside your Volvo account. VCCAPI key is required and comes from your Volvo developer account. Odometer multiplier is sometimes 10, sometimes 1. Leave it empty if you don't know what's right. Take a look at the GitHub repo for more information!
|
||||||
Reference in New Issue
Block a user