forked from peter/volvo2mqtt
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50b5eb9863 | ||
|
|
02793accfa | ||
|
|
4d8b5e5006 |
@@ -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
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
name: "Volvo2Mqtt"
|
name: "Volvo2Mqtt"
|
||||||
description: "Volvo AAOS MQTT bridge"
|
description: "Volvo AAOS MQTT bridge"
|
||||||
version: "1.4.1"
|
version: "1.4.3"
|
||||||
slug: "volvo2mqtt"
|
slug: "volvo2mqtt"
|
||||||
init: false
|
init: false
|
||||||
url: "https://github.com/Dielee/volvo2mqtt"
|
url: "https://github.com/Dielee/volvo2mqtt"
|
||||||
|
|||||||
+3
-1
@@ -1,6 +1,6 @@
|
|||||||
from config import settings
|
from config import settings
|
||||||
|
|
||||||
VERSION = "v1.4.1"
|
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"}
|
||||||
|
|
||||||
|
|||||||
+19
-6
@@ -8,7 +8,7 @@ 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
|
||||||
@@ -20,6 +20,7 @@ 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"])
|
||||||
port = 1883
|
port = 1883
|
||||||
@@ -39,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)
|
||||||
@@ -77,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)
|
||||||
@@ -95,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:
|
||||||
@@ -103,12 +105,21 @@ 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:
|
else:
|
||||||
state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update)
|
if entity["id"] == ov_entity_id:
|
||||||
|
state = ov_state
|
||||||
|
else:
|
||||||
|
state = volvo.api_call(entity["url"], "GET", vin, entity["id"], force_update)
|
||||||
|
|
||||||
if entity["domain"] == "device_tracker":
|
if entity["domain"] == "device_tracker":
|
||||||
topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/attributes"
|
topic = f"homeassistant/{entity['domain']}/{vin}_{entity['id']}/attributes"
|
||||||
@@ -133,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"]
|
||||||
@@ -153,3 +165,4 @@ def create_ha_devices():
|
|||||||
retain=True
|
retain=True
|
||||||
)
|
)
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
mqtt_client.publish(availability_topic, "online")
|
||||||
|
|||||||
Reference in New Issue
Block a user