mirror of
https://github.com/Dielee/volvo2mqtt.git
synced 2026-08-12 18:59:53 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
71f03e505b | ||
|
|
2b6a2a4f4c | ||
|
|
38cca04473 |
@@ -3,6 +3,11 @@
|
|||||||
This component establishes a connection between the newer AAOS Volvo cars and Home Assistant via MQTT.<br>
|
This component establishes a connection between the newer AAOS Volvo cars and Home Assistant via MQTT.<br>
|
||||||
Maybe this component works also with other Volvo cars. Please try out the native Volvo [integration](https://www.home-assistant.io/integrations/volvooncall/) before using this component! If the native component doesn't work for your car, try this mqtt bridge.
|
Maybe this component works also with other Volvo cars. Please try out the native Volvo [integration](https://www.home-assistant.io/integrations/volvooncall/) before using this component! If the native component doesn't work for your car, try this mqtt bridge.
|
||||||
|
|
||||||
|
## Confirmed working with
|
||||||
|
- Volvo XC40 BEV (2023)
|
||||||
|
|
||||||
|
Please let me know if your car works with this addon so I can expand the list!
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
Just install this addon with the following command.
|
Just install this addon with the following command.
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
VERSION = "v1.0.4"
|
VERSION = "v1.0.5"
|
||||||
|
|
||||||
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"
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ def update_loop():
|
|||||||
while True:
|
while True:
|
||||||
print("Sending mqtt update...")
|
print("Sending mqtt update...")
|
||||||
update_car_data()
|
update_car_data()
|
||||||
|
print("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.")
|
||||||
time.sleep(settings["updateInterval"])
|
time.sleep(settings["updateInterval"])
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -115,18 +115,18 @@ def api_call(url, method, vin, sensor_id=None):
|
|||||||
# No API Data cached, get fresh data from API
|
# No API Data cached, get fresh data from API
|
||||||
print("Starting " + method + " call against " + url)
|
print("Starting " + method + " call against " + url)
|
||||||
response = session.get(url.format(vin), timeout=15)
|
response = session.get(url.format(vin), timeout=15)
|
||||||
recharge_response = response
|
recharge_response[vin] = response
|
||||||
recharge_last_update = datetime.now()
|
recharge_last_update = datetime.now()
|
||||||
else:
|
else:
|
||||||
if (datetime.now() - recharge_last_update).total_seconds() >= settings["updateInterval"]:
|
if (datetime.now() - recharge_last_update).total_seconds() >= settings["updateInterval"]:
|
||||||
# Old Data in Cache, updateing
|
# Old Data in Cache, updateing
|
||||||
print("Starting " + method + " call against " + url)
|
print("Starting " + method + " call against " + url)
|
||||||
response = session.get(url.format(vin), timeout=15)
|
response = session.get(url.format(vin), timeout=15)
|
||||||
recharge_response = response
|
recharge_response[vin] = response
|
||||||
recharge_last_update = datetime.now()
|
recharge_last_update = datetime.now()
|
||||||
else:
|
else:
|
||||||
# Data is up do date, returning cached data
|
# Data is up do date, returning cached data
|
||||||
response = recharge_response
|
response = recharge_response[vin]
|
||||||
elif method == "GET":
|
elif method == "GET":
|
||||||
print("Starting " + method + " call against " + url)
|
print("Starting " + method + " call against " + url)
|
||||||
response = session.get(url.format(vin), timeout=15)
|
response = session.get(url.format(vin), timeout=15)
|
||||||
@@ -147,7 +147,10 @@ def api_call(url, method, vin, sensor_id=None):
|
|||||||
else:
|
else:
|
||||||
print("API Call failed. Status Code: " + str(response.status_code) + ". Error: " + response.text)
|
print("API Call failed. Status Code: " + str(response.status_code) + ". Error: " + response.text)
|
||||||
return ""
|
return ""
|
||||||
|
return parse_api_data(url, data, sensor_id)
|
||||||
|
|
||||||
|
|
||||||
|
def parse_api_data(url, data, sensor_id=None):
|
||||||
if url == VEHICLE_DETAILS_URL:
|
if url == VEHICLE_DETAILS_URL:
|
||||||
return data["data"]
|
return data["data"]
|
||||||
elif sensor_id == "battery_charge_level":
|
elif sensor_id == "battery_charge_level":
|
||||||
|
|||||||
Reference in New Issue
Block a user