forked from peter/volvo2mqtt
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d01174e213 | ||
|
|
c87a3cb2d7 | ||
|
|
f6a26e5a41 | ||
|
|
42d07f1a4c | ||
|
|
71f03e505b | ||
|
|
2b6a2a4f4c | ||
|
|
38cca04473 | ||
|
|
fbb98481f4 | ||
|
|
dad5f9aaaa | ||
|
|
c404356ee0 |
@@ -11,7 +11,7 @@ name: Create and publish a Docker image
|
||||
|
||||
on:
|
||||
release:
|
||||
types: [created]
|
||||
types: [created, edited]
|
||||
workflow_dispatch:
|
||||
|
||||
env:
|
||||
|
||||
@@ -3,6 +3,11 @@
|
||||
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.
|
||||
|
||||
## 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
|
||||
|
||||
Just install this addon with the following command.
|
||||
@@ -17,7 +22,7 @@ Here is what every option means:
|
||||
| `updateInterval` | `int` | **required** | Update intervall in seconds. |
|
||||
| `babelLocale` | `string` | **required** | Locale for date Format |
|
||||
| `mqtt` | `json` | **required** | Broker = Mqtt Broker IP / Username and Passwort are optional! |
|
||||
| `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 your api key from [here](https://developer.volvocars.com/account/). |
|
||||
| `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/). |
|
||||
| `TZ` | `string` | | Container timezone eg "Europe/Berlin" |
|
||||
|
||||
If you like my work:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
VERSION = "v1.0.2.1"
|
||||
VERSION = "v1.0.7"
|
||||
|
||||
OAUTH_URL = "https://volvoid.eu.volvocars.com/as/token.oauth2"
|
||||
VEHICLES_URL = "https://api.volvocars.com/connected-vehicle/v1/vehicles"
|
||||
|
||||
@@ -6,7 +6,7 @@ import threading
|
||||
from datetime import datetime
|
||||
from babel.dates import format_datetime
|
||||
from config import settings
|
||||
from const import VEHICLE_DETAILS_URL,CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
|
||||
from const import VEHICLE_DETAILS_URL, CLIMATE_START_URL, CLIMATE_STOP_URL, CAR_LOCK_URL, \
|
||||
CAR_UNLOCK_URL, supported_sensors, supported_buttons, supported_switches, supported_locks
|
||||
|
||||
|
||||
@@ -42,27 +42,28 @@ def on_disconnect(client, userdata, rc):
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
if msg.topic in subscribed_topics:
|
||||
vin = msg.topic.split('/')[2].split('_')[0]
|
||||
payload = msg.payload.decode("UTF-8")
|
||||
if "climate_status" in msg.topic:
|
||||
global assumed_climate_state
|
||||
if payload == "ON":
|
||||
api_thread = threading.Thread(target=volvo.api_call, args=(CLIMATE_START_URL, "POST", ))
|
||||
api_thread = threading.Thread(target=volvo.api_call, args=(CLIMATE_START_URL, "POST", vin))
|
||||
api_thread.start()
|
||||
assumed_climate_state = "ON"
|
||||
# Starting timer to disable climate after 30 mins
|
||||
threading.Timer(30 * 60, volvo.disable_climate).start()
|
||||
update_car_data()
|
||||
elif payload == "OFF":
|
||||
api_thread = threading.Thread(target=volvo.api_call, args=(CLIMATE_STOP_URL, "POST", ))
|
||||
api_thread = threading.Thread(target=volvo.api_call, args=(CLIMATE_STOP_URL, "POST", vin))
|
||||
api_thread.start()
|
||||
assumed_climate_state = "OFF"
|
||||
update_car_data()
|
||||
elif "lock_status" in msg.topic:
|
||||
if payload == "LOCK":
|
||||
volvo.api_call(CAR_LOCK_URL, "POST")
|
||||
volvo.api_call(CAR_LOCK_URL, "POST", vin)
|
||||
update_car_data()
|
||||
elif payload == "UNLOCK":
|
||||
volvo.api_call(CAR_UNLOCK_URL, "POST")
|
||||
volvo.api_call(CAR_UNLOCK_URL, "POST", vin)
|
||||
update_car_data()
|
||||
elif "update_data" in msg.topic:
|
||||
if payload == "PRESS":
|
||||
@@ -74,6 +75,7 @@ def update_loop():
|
||||
while True:
|
||||
print("Sending mqtt update...")
|
||||
update_car_data()
|
||||
print("Mqtt update done. Next run in " + str(settings["updateInterval"]) + " seconds.")
|
||||
time.sleep(settings["updateInterval"])
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
requests~=2.29.0
|
||||
dynaconf~=3.1.12
|
||||
paho-mqtt~=1.6.1
|
||||
pytz~=2023.3
|
||||
Babel~=2.12.1
|
||||
@@ -8,7 +8,7 @@ from const import charging_system_states, CLIMATE_START_URL, \
|
||||
|
||||
session = requests.Session()
|
||||
session.headers = {
|
||||
"vcc-api-key": "",
|
||||
"vcc-api-key": settings["volvoData"]["vccapikey"],
|
||||
"content-type": "application/json",
|
||||
"accept": "*/*"
|
||||
}
|
||||
@@ -17,7 +17,7 @@ token_expires_at: datetime
|
||||
refresh_token = None
|
||||
vins = []
|
||||
recharge_response = {}
|
||||
recharge_last_update = None
|
||||
recharge_last_update = {}
|
||||
|
||||
|
||||
def authorize():
|
||||
@@ -42,7 +42,6 @@ def authorize():
|
||||
token_expires_at = datetime.now() + timedelta(seconds=(data["expires_in"] - 30))
|
||||
refresh_token = data["refresh_token"]
|
||||
|
||||
session.headers.update({"vcc-api-key": settings["volvoData"]["vccapikey"]})
|
||||
get_vehicles()
|
||||
else:
|
||||
message = auth.json()
|
||||
@@ -112,22 +111,22 @@ def api_call(url, method, vin, sensor_id=None):
|
||||
global recharge_response, recharge_last_update
|
||||
if url == RECHARGE_STATUS_URL:
|
||||
# Minimize API calls for recharge API
|
||||
if not bool(recharge_response):
|
||||
# No API Data cached, get fresh data from API
|
||||
if not vin in recharge_response:
|
||||
# No API Data for vin cached, get fresh data from API
|
||||
print("Starting " + method + " call against " + url)
|
||||
response = session.get(url.format(vin), timeout=15)
|
||||
recharge_response = response
|
||||
recharge_last_update = datetime.now()
|
||||
recharge_response[vin] = response
|
||||
recharge_last_update[vin] = datetime.now()
|
||||
else:
|
||||
if (datetime.now() - recharge_last_update).total_seconds() >= settings["updateInterval"]:
|
||||
# Old Data in Cache, updateing
|
||||
if (datetime.now() - recharge_last_update[vin]).total_seconds() >= settings["updateInterval"]:
|
||||
# Old Data in Cache, updating
|
||||
print("Starting " + method + " call against " + url)
|
||||
response = session.get(url.format(vin), timeout=15)
|
||||
recharge_response = response
|
||||
recharge_last_update = datetime.now()
|
||||
recharge_response[vin] = response
|
||||
recharge_last_update[vin] = datetime.now()
|
||||
else:
|
||||
# Data is up do date, returning cached data
|
||||
response = recharge_response
|
||||
response = recharge_response[vin]
|
||||
elif method == "GET":
|
||||
print("Starting " + method + " call against " + url)
|
||||
response = session.get(url.format(vin), timeout=15)
|
||||
@@ -148,7 +147,10 @@ def api_call(url, method, vin, sensor_id=None):
|
||||
else:
|
||||
print("API Call failed. Status Code: " + str(response.status_code) + ". Error: " + response.text)
|
||||
return ""
|
||||
return parse_api_data(url, data, sensor_id)
|
||||
|
||||
|
||||
def parse_api_data(url, data, sensor_id=None):
|
||||
if url == VEHICLE_DETAILS_URL:
|
||||
return data["data"]
|
||||
elif sensor_id == "battery_charge_level":
|
||||
|
||||
Reference in New Issue
Block a user