Giter VIP home page Giter VIP logo

teslamate-abrp's Introduction

TeslaMate: MQTT to ABRP

amd64+arm64 :alpha build amd64+arm64 :beta build amd64+arm64 :latest build GitHub license

A slightly convoluted way of getting your vehicle data from TeslaMate to ABRP.

Setup and Usage

1. Use as Docker container

1.1 Requirements

For this to work, you need a working instance of TeslaMate with MQTT enabled. See the official TeslaMate doc as a reference on how this might look like.

1.2 Getting a USER TOKEN from ABRP

Inside the ABRP (web)app, navigate to your car settings and use the "generic" card (last one at the very bottom) to generate your user token. Make a note of that token and keep it to yourself.

1.3 Adding the service to docker-compose.yml

In your TeslaMate docker-compose.yml, add the teslamate-abrp service by adding the following lines in the "services:" section:

ABRP:
  container_name: TeslaMate_ABRP
  image: fetzu/teslamate-abrp:latest #NOTE: you can replace ":latest" with either ":beta" (pre-release version) or ":alpha" for the bleeding edge version (note: bleeding edge might be very unstable or even not work at all)
  restart: always
  # privileged: true
  # NOTE: un-comment the previous line to run the container in privilege mode (necessary on RaspberryPi)
  environment:
    - MQTT_SERVER=mosquitto
    - USER_TOKEN=y0ur-4p1-k3y
    - CAR_NUMBER=1
    - CAR_MODEL=s100d #NOTE: This is optional, see below

Make sure to adapt the following environment variables:

  • The first value MQTT_SERVER corresponds to the name of your MQTT service name ("mosquitto" in the doc).
  • The second values (USER_TOKEN) correspond to the value provided by ABRP.
  • The third value corresponds to your car number (1 if you only have a single car).
  • The last value corresponds to your car model. When this value is not set, the script will try to determine your car model automatically (this should work for Models S, X, 3 and Y with standard configs). The detection is very bare-bones and will not take into account factors such as wheel type, heat pump, LFP battery. It is recommended you take a moment to find your car model on https://api.iternio.com/1/tlm/get_carmodels_list and use the corresponding key as a value for CAR_MODEL (e.g. "tesla:m3:20:bt37:heatpump" for a 2021 Model 3 LR).
  • Additionally;
    • MQTT_PASSWORD and/or MQTT_USERNAME: can be set to use authentication on the MQTT server.
    • MQTT_TLS: will connect to the MQTT server with encryption, the server must have certificates configured.
    • MQTT_PORT: is the port the MQTT server is listening on, defaults to 1883 and if you are using TLS this probably should be set to 8883
    • STATUS_TOPIC: can be set to a MQTT topic where status messages will be sent, write permissions will be needed for this specific topic.
    • SKIP_LOCATION: If you don't want to share your location with ABPR (Iternio), give this environment variable a value and the lat and lon values will always be 0
    • TM2ABRP_DEBUG: set (to any value) sets logging level to DEBUG and give you a more verbose logging.

Then from the command line, navigate to the folder where your docker-compose.yml is located and run:

docker-compose pull ABRP
docker-compose up -d ABRP

If all goes well, your car should be shown as online in ABRP after a minute. Logging should show "YYYY-MM-DD HH:MM:SS: [INFO] Connected with result code 0. Connection with MQTT server established.".

1.4 Security

If you want to follow dockers recommendations regarding secrets, you should not provide them as ENVIRONMENT VARIABLE or command line parameters and instead use the build in secrets function. This will expose the secrets in the container to the file system at /run/secrets/. Read the documentation carefully if you wish to use docker's secrets feature.

This is an example of a part of a docker-compose.yml file using:

  • Secrets instead of environment variables
  • TLS enabled on the MQTT Server
  • A status topic provided
  • Flag set not to send latitude and longitude information to ABRP
  • Debug level logging activated
version: '3'
services:
  # [...Other services such as TeslaMate, postgres, Grafana and the MQTT broker go here...]
  MQTT2ABRP:
    container_name: TeslaMate_ABRP
    image: fetzu/teslamate-abrp:latest #NOTE: you can replace ":latest" with ":beta" to use the bleeding edge version, without any guarantees.
    restart: always
    environment:
      CAR_NUMBER: 1
      MQTT_SERVER: your.server.tld # Replace with your server's service name or IP address
      MQTT_PORT: 8883 # This is a TLS enabled server, and usually that is enabled on a different port than the default 1883
      MQTT_USERNAME: myMQTTusername # Replace with your actually mqtt username
      MQTT_TLS: True # Connect to the MQTT server encrypted
      STATUS_TOPIC: teslamate-abrp # This will send status messages and a copy of the ABRP data to the topic "teslamate-abrp/xxx"
      TM2ABRP_DEBUG: True # This will enable debug level logging
      SKIP_LOCATION: True # Don't send location info to ABRP
      TZ: "Europe/Stockholm"
    secrets:
      - USER_TOKEN # Instead of having your token in clear text, it's found in the file below
      - MQTT_PASSWORD # Instead of having your password in clear text, it's found in the file below

secrets:
# These text files contains the token/passwords, and nothing else. 
# They can be placed "anywhere" on the host system and protected by appropriate file permissions.
  USER_TOKEN:
    file: ./path/to/abrp-token.txt 
  MQTT_PASSWORD:
    file: ./path/to/abrp-mqtt-pass.txt

To run it:

docker compose up -d

2. Use as python script

The script can also be run directly on a machine with Python 3.x. Please note that the machine needs to have access to your MQTT server on port 1883.

2.1 Installing requirements

To install the requirements, run

pip install -r requirements.txt

2.2 Running

To run, you can either use the CLI. Please note that USER_TOKEN, CAR_NUMBER, CAR_MODEL and MQTT_SERVER are required arguments.

If you are using a MQTT server with username or authentication, pass the -l (to use MQTT_USERNAME only) or -p (for authentication with MQTT_USERNAME and MQTT_PASSWORD) options. Be aware that passing a username and password on an MQTT server not set for it will cause the connection to fail.

Usage: 
    teslamate_mqtt2abrp.py [-hdlpsx] [USER_TOKEN] [CAR_NUMBER] [MQTT_SERVER] [MQTT_USERNAME] [MQTT_PASSWORD] [MQTT_PORT] [--model CAR_MODEL] [--status_topic TOPIC]

Arguments:
    USER_TOKEN            User token generated by ABRP.
    CAR_NUMBER            Car number from TeslaMate (usually 1).
    MQTT_SERVER           MQTT server address (e.g. "192.168.1.1").
    MQTT_PORT             MQTT port (e.g. 1883 or 8883 for TLS).
    MQTT_USERNAME         MQTT username, use with -l or -p.
    MQTT_PASSWORD         MQTT password, use with -p.

Options:
    -h                    Show this screen.
    -d                    Debug mode (set logging level to DEBUG)
    -l                    Use username to connect to MQTT server.
    -p                    Use authentication (user and password) to connect to MQTT server.
    -s                    Use TLS to connect to MQTT server, environment variable: MQTT_TLS
    -x                    Don't send LAT and LON to ABRP, environment variable: SKIP_LOCATION
    --model CAR_MODEL     Car model according to https://api.iternio.com/1/tlm/get_CARMODELs_list
    --status_topic TOPIC  MQTT topic to publish status messages to, if not set, no publish will be done.

Note:
    All arguments can also be passed as corresponding OS environment variables.

Note: All arguments can also be passed as corresponding OS environment variables. Arguments passed through the CLI will always supersede OS environment variables and docker secrets (in that order).

Credits

Based on/forked from letienne's original code, with improvement by various contributors (see commit history).

License

Licensed under the MIT license.

teslamate-abrp's People

Contributors

0ff avatar dependabot[bot] avatar feralbob avatar fetzu avatar gummigroda avatar jheredianet avatar letienne avatar pleasanthill17 avatar pyjamasam avatar rawdigits avatar sirsheik avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

teslamate-abrp's Issues

Car is (unknown state), not sending any update to ABRP.

Hi,
I've setup your container through portainer, passing the mentioned env variables. The container runs stable but the container logs keep on spamming the message ":Car is (unknown state), not sending any update to ABRP." Teslamate is also setup through Portainer and both containers share the same network. Can you please help me to find the issue?

MQTT client seems to succesfully connect to the MQTT server created through TeslaMate docker setup.
grafik

Cheers

ABRP API issue?

Hi, I was going to start using teslamate-abrp to maintain a single source of truth (being TeslaMate). I was able to start the script and it connects to MQTT topics without problems. However, there seems to be some connection issue:

2023-11-01 09:02:29: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:03:04: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:03:39: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:04:14: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:04:49: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:05:24: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:05:59: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:06:34: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:07:09: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:07:44: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:08:19: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>
2023-11-01 09:08:54: [CRITICAL] Unexpected exception while POSTing to ABRP API: <class 'requests.exceptions.ConnectionError'>

Did ABRP API change/down or is the request malformed?

Thanks for looking into it.

ABRP API status - Not authorized

This is not an issue of this repository, but I wanted to report it in order to know if you all are having this issue.
I've been watching that the ABRP API status is Not authorized as you can see in the following screen shot, although it's still receiving data as usual, but it's curious to have that warming.

image

Connection refused for MQTT

I tried to deploy via docker-compose. However, I'm getting connection error with MQTT it appears.

Here's the error message:

{'--model': None,
 '-a': False,
 '-h': False,
 '-l': False,
 '-p': False,
 'CAR_NUMBER': None,
 'MQTT_PASSWORD': None,
 'MQTT_SERVER': None,
 'MQTT_USERNAME': None,
 'USER_TOKEN': None}
Traceback (most recent call last):
  File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 110, in <module>
    client.connect(MQTTSERVER)
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 914, in connect
    return self.reconnect()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1044, in reconnect
    sock = self._create_socket_connection()
  File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
    return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
  File "/usr/local/lib/python3.10/socket.py", line 845, in create_connection
    raise err
  File "/usr/local/lib/python3.10/socket.py", line 833, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

My mosquitto service is configured as below:

  mosquitto:
    image: eclipse-mosquitto:2
    container_name: teslamate_mosquitto
    restart: always
    ports:
      - 1883:1883
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

Because the config is asking for MQTT_SERVER I suppose it's the service name (thus mosquitto)? It's interesting that the error message seems to have None for a lot of params, not sure what gives.

Better handling of MQTT connection response codes

Handle the paho-mqtt response codes a little better.

0: Connection successful 1: Connection refused - incorrect protocol version 2: Connection refused - invalid client identifier 3: Connection refused - server unavailable 4: Connection refused - bad username or password 5: Connection refused - not authorised 6-255: Currently unused.

Car is in unknown state

When I restart ABRP it won't send any updates, because it has an unknown state.

TeslaMate_ABRP | Connected with result code 0
TeslaMate_ABRP | Car model automatically determined as:
TeslaMate_ABRP | 2022-03-23 21:45:30: Car is  (unknown state), not sending any update to ABRP.

The logs are the same, even when I specify the model in via CAR_MODEL in the docker-compose environment.
I'm using Teslamate 1.26.1.

SoC 0%

Hey,

I've just installed as per the instructions and the connection is working, yet I can see the SoC is being sent as 0 in the logs, even after reversing the car and parking again it is always 0.

Any thing I can do to check why this is?

{'utc': 1641142723, 'soc': 0, 'power': 2, 'speed': 0, 'lat': 'XXX', 'lon': 'XXX', 'elevation': '78', 'is_charging': 0, 'is_dcfc': 0, 'is_parked': '0', 'battery_range': '387.98', 'ideal_battery_range': '472.17', 'ext_temp': '10.0', 'model': '', 'trim_badging': '', 'car_model': 'tesla:m3:20:bt37_21:heatpump', 'tlm_type': 'api', 'heading': '312', 'odometer': '1408.34'}`

Docker update?

Will you also update the docker container with the newest commits?

KeyError in some cases

I just noticed that the script is throwing some KeyErrors for two messages. Have to take a look at this later.

TeslaMate_ABRP | unexpected exception while processing message: <class 'KeyError'> teslamate/cars/1/charger_actual_current b'0'
TeslaMate_ABRP | unexpected exception while processing message: <class 'KeyError'> teslamate/cars/1/charger_voltage b'0'

State: car is parked, plugged in but not charging.

docker-compose setup: needs privileged mode on raspberry pi

I had to add privileged: true to my docker-compose.yml file running on a raspberry pi.

Without this addition, I am getting an error like this and the containers stops/restarts:

teslamate-abrp     | Traceback (most recent call last):
teslamate-abrp     |   File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 30, in <module>
teslamate-abrp     |     import paho.mqtt.client as mqtt
teslamate-abrp     |   File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 18, in <module>
teslamate-abrp     |     import logging
teslamate-abrp     |   File "/usr/local/lib/python3.10/logging/__init__.py", line 57, in <module>
teslamate-abrp     |     _startTime = time.time()
teslamate-abrp     | PermissionError: [Errno 1] Operation not permitted

ERROR: No such service: -d

Hello,

If you meet this error : ERROR: No such service: -d
Whit this command : sudo docker-compose up ABRP -d

Write it like that : sudo docker-compose up -d ABRP

;)

Improve findCarModel()

Make the auto car model detection feature a little better (currently only handles a very limited/easy set of cars).

  • Get some data needed for better classification ("trim_badging" and "wheel_type" probably).
  • Implement better classification according to these additional data points.

Suggestion to change the initial temperature of the vehicle

Hello.
I would like to make a suggestion, I don't know if it is correct but I think it is better for ABRP calculations.
I think that we should send to ABRP the actual temperature inside the cabin, so that the ABRP field "Initial vehicle temperature" takes it into account.
This temperature is available in the following MQTT topic.
teslamate/cars/1/inside_temp
I attach some screenshots where you can see that the actual room temperature was 20ºC, however ABRP was receiving in the field "Initial vehicle temperature" 27,7ºC.
Thank you very much for this great work
Kind regards,
Iván

IMG_0499
IMG_0500
IMG_0501

SoC is at 0% in ABRP

Since upgrade to 2.0 via docker my SoC on ABRP website and app is always at 0%.
Log output shows no obvious problem:

2023-12-13 12:55:05: [INFO] Data object successfully sent: {'utc': 1702472104, 'soc': 0, 'power': 0, 'speed': 0, 'lat': XXX, 'lon': XXX, 'elevation': 0, 'is_charging': False, 'is_dcfc': False, 'is_parked': True, 'est_battery_range': 130.55, 'ideal_battery_range': 136.73, 'ext_temp': 6.0, 'model': '', 'trim_badging': '', 'car_model': 'tesla:my:22:mylr_22:perf:heatpump', 'tlm_type': 'api', 'voltage': 0, 'current': 0, 'heading': 330}

API Timeouts stop data being uploaded to ABRP

Hi,

It looks like if there is any form of timeout on the connection to api.iternio.com server the app terminates. What's the best option here? Improve the logic or is it expected that - putting a restart/restart-policy in the compose file will be sufficient?

Running on Raspberry Pi.

TeslaMate_ABRP | Traceback (most recent call last):
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 174, in _new_conn
TeslaMate_ABRP |     conn = connection.create_connection(
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 95, in create_connection
TeslaMate_ABRP |     raise err
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/util/connection.py", line 85, in create_connection
TeslaMate_ABRP |     sock.connect(sa)
TeslaMate_ABRP | TimeoutError: [Errno 110] Operation timed out
TeslaMate_ABRP | 
TeslaMate_ABRP | Unexpected exception while calling ABRP API: <class 'requests.exceptions.ConnectTimeout'>
TeslaMate_ABRP | During handling of the above exception, another exception occurred:
TeslaMate_ABRP | 
TeslaMate_ABRP | Traceback (most recent call last):
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
TeslaMate_ABRP |     httplib_response = self._make_request(
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 386, in _make_request
TeslaMate_ABRP |     self._validate_conn(conn)
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 1040, in _validate_conn
TeslaMate_ABRP |     conn.connect()
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 358, in connect
TeslaMate_ABRP |     conn = self._new_conn()
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connection.py", line 179, in _new_conn
TeslaMate_ABRP |     raise ConnectTimeoutError(
TeslaMate_ABRP | urllib3.exceptions.ConnectTimeoutError: (<urllib3.connection.HTTPSConnection object at 0x75f16748>, 'Connection to api.iternio.com timed out. (connect timeout=None)')
TeslaMate_ABRP | 
TeslaMate_ABRP | During handling of the above exception, another exception occurred:
TeslaMate_ABRP | 
TeslaMate_ABRP | Traceback (most recent call last):
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 439, in send
TeslaMate_ABRP |     resp = conn.urlopen(
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen
TeslaMate_ABRP |     retries = retries.increment(
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 592, in increment
TeslaMate_ABRP |     raise MaxRetryError(_pool, url, error or ResponseError(cause))
TeslaMate_ABRP | urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='api.iternio.com', port=443): Max retries exceeded with url: /1/tlm/send?token=<REDACTED> (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x75f16748>, 'Connection to api.iternio.com timed out. (connect timeout=None)'))
TeslaMate_ABRP | 
TeslaMate_ABRP | During handling of the above exception, another exception occurred:
TeslaMate_ABRP | 
TeslaMate_ABRP | Traceback (most recent call last):
TeslaMate_ABRP |   File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 250, in updateABRP
TeslaMate_ABRP |     requests.post("https://api.iternio.com/1/tlm/send?token="+USERTOKEN, headers=headers, json=body)
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 117, in post
TeslaMate_ABRP |     return request('post', url, data=data, json=json, **kwargs)
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 61, in request
TeslaMate_ABRP |     return session.request(method=method, url=url, **kwargs)
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 542, in request
TeslaMate_ABRP |     resp = self.send(prep, **send_kwargs)
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 655, in send
TeslaMate_ABRP |     r = adapter.send(request, **kwargs)
TeslaMate_ABRP |   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 504, in send
TeslaMate_ABRP |     raise ConnectTimeout(e, request=request)
TeslaMate_ABRP | requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.iternio.com', port=443): Max retries exceeded with url: /1/tlm/send?token=<REDACTED> (Caused by ConnectTimeoutError(<urllib3.connection.HTTPSConnection object at 0x75f16748>, 'Connection to api.iternio.com timed out. (connect timeout=None)'))
TeslaMate_ABRP | 
TeslaMate_ABRP | During handling of the above exception, another exception occurred:
TeslaMate_ABRP | 
TeslaMate_ABRP | Traceback (most recent call last):
TeslaMate_ABRP |   File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 275, in <module>
TeslaMate_ABRP |     updateABRP()
TeslaMate_ABRP |   File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 253, in updateABRP
TeslaMate_ABRP |     print(message.topic)
TeslaMate_ABRP | NameError: name 'message' is not defined. Did you mean: 'on_message'?
TeslaMate_ABRP exited with code 1

Not having any luck using external mqtt server

Hi, thanks for this. Exactly what I was looking for.

I run my homelab MQTT server on a different machine than teslamate. Teslamate is writing to the MQTT server but I can't get the ABRP container to read from it:

{'--model': None,
 '-a': False,
 '-h': False,
 '-l': False,
 '-p': False,
 'CAR_NUMBER': None,
 'MQTT_PASSWORD': None,
 'MQTT_SERVER': None,
 'MQTT_USERNAME': None,
 'USER_TOKEN': None}
3long_awd19
Connected with result code 5
2022-04-05 17:38:39: Car is  (unknown state), not sending any update to ABRP.
Connected with result code 5
2022-04-05 17:38:40: Car is  (unknown state), not sending any update to ABRP.
2022-04-05 17:38:41: Car is  (unknown state), not sending any update to ABRP.
Connected with result code 5
2022-04-05 17:38:42: Car is  (unknown state), not sending any update to ABRP.
2022-04-05 17:38:43: Car is  (unknown state), not sending any update to ABRP.
2022-04-05 17:38:44: Car is  (unknown state), not sending any update to ABRP.
Connected with result code 5

Response code 5 = 0x05 Connection Refused, not authorized

Here's my scrubbed docker-compose:

  ABRP:
    container_name: TeslaMate_ABRP
    image: fetzu/teslamate-abrp:latest
    restart: always
    environment:
      - MQTT_SERVER=192.168.1.20
      - MQTT_USERNAME=bob
      - MQTT_PASSWORD=bobspassword
      - USER_TOKEN=XXXABC
      - CAR_NUMBER=1
      - CAR_MODEL=3long_awd19 #NOTE: This is optional, see below

The Teslamate container itself successfully connects and sends updates to MQTT with the following env variables in docker compose - which values are identical to the values passed to the ABRP container:

      - MQTT_HOST=192.168.1.20
      - MQTT_USERNAME=bob
      - MQTT_PASSWORD=bobspassword

took a stab at just running in python, but getting an error there too. Would prefer docker so only including this in case (again) I misconfigured something obvious:

john@teslamate:~/teslamate-abrp$ python teslamate_mqtt2abrp.py -a XXXABC 1 192.16.1.20 bob bobspassword --model 3long_awd19
  File "teslamate_mqtt2abrp.py", line 90
    "car_model":f"{CARMODEL}",
                            ^
SyntaxError: invalid syntax

Anything stick out that I might have messed up?

Losing connection + issue in error handling

This happened twice in a few days; container seems to be losing connection to ABRP's API and error handling seems to be broken.

NameError: name 'message' is not defined. Did you mean: 'on_message'?
    print(message.topic)
  File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 277, in updateABRP
Unexpected exception while calling ABRP API: <class 'requests.exceptions.ConnectionError'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 449, in _make_request
    six.raise_from(e, None)
  File "<string>", line 3, in raise_from
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 444, in _make_request
    httplib_response = conn.getresponse()
    response.begin()
  File "/usr/local/lib/python3.10/http/client.py", line 1374, in getresponse
  File "/usr/local/lib/python3.10/http/client.py", line 318, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python3.10/http/client.py", line 287, in _read_status
    raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response
During handling of the above exception, another exception occurred:
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 439, in send
    resp = conn.urlopen(
  File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py", line 785, in urlopen
    retries = retries.increment(
    raise six.reraise(type(error), error, _stacktrace)
  File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line 550, in increment
  File "/usr/local/lib/python3.10/site-packages/urllib3/packages/six.py", line 769, in reraise
    raise value.with_traceback(tb)
urllib3.exceptions.ProtocolError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
  File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 274, in updateABRP
    requests.post("https://api.iternio.com/1/tlm/send?token="+USERTOKEN, headers=headers, json=body)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 117, in post
    return request('post', url, data=data, json=json, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 61, in request
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 542, in request
    return session.request(method=method, url=url, **kwargs)
    resp = self.send(prep, **send_kwargs)
    r = adapter.send(request, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line 655, in send
  File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line 498, in send
    raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response'))
  File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 304, in <module>
    updateABRP()

Look into this.

ABRP shows offline

Since 2-3 days ABRP shows "offline" for my Tesla despite the Teslamate extension updates regularly every 10 minutes or so and the charging state is reflected correctly.

How to check if this actually works?

I can see the message in ABRP about the last Live-Dataconnection with a timestamp (sorry for the screenshot in german).
However, what confuses me is that the blue button says "connect live data".
Just wanted to check if this is the way it is supposed to look?

abrp

Not sending updates to ABRP

Hi, I have a problem. Don't know what am I doing wrong. Here is my (censored) composer file:

version: "3"

services:
  teslamate:
    image: teslamate/teslamate:latest
    restart: always
    environment:
      - ENCRYPTION_KEY=xxx
      - DATABASE_USER=xxx
      - DATABASE_PASS=xxx
      - DATABASE_NAME=xxx
      - DATABASE_HOST=xxx
      - MQTT_HOST=${MQTT_HOST}
      - MQTT_PORT=${MQTT_PORT}
      - MQTT_USERNAME=${MQTT_USERNAME}
      - MQTT_PASSWORD=${MQTT_PASSWORD}
    ports:
      - XXXX:XXXX
    volumes:
      - ./import:/opt/app/import
    cap_drop:
      - all

  database:
    image: postgres:14
    restart: always
    environment:
      - POSTGRES_USER=xxx
      - POSTGRES_PASSWORD=xxx
      - POSTGRES_DB=xxx
    volumes:
      - teslamate-db:/var/lib/postgresql/data

  grafana:
    image: teslamate/grafana:latest
    restart: always
    environment:
      - DATABASE_USER=xxx
      - DATABASE_PASS=xxx
      - DATABASE_NAME=xxx
      - DATABASE_HOST=xxx
    ports:
      - XXXX:XXXX
    volumes:
      - teslamate-grafana-data:/var/lib/grafana

  mosquitto:
    image: eclipse-mosquitto:2
    restart: always
    command: mosquitto -c /mosquitto-no-auth.conf
    #ports:
    #  - XXXX:XXXX
    volumes:
      - mosquitto-conf:/mosquitto/config
      - mosquitto-data:/mosquitto/data

  ABRP:
    container_name: TeslaMate_ABRP
    image: fetzu/teslamate-abrp:latest
    restart: always
    # privileged: true
    # NOTE: un-comment the previous line to run the container in privilege mode (necessary on RaspberryPi)
    environment:
      - MQTT_SERVER=mosquitto
     # - MQTT_HOST=${MQTT_HOST}
     # - MQTT_PORT=${MQTT_PORT}
      - MQTT_USERNAME=${MQTT_USERNAME}
      - MQTT_PASSWORD=${MQTT_PASSWORD}
      - USER_TOKEN=afff38c7-d220-40c3-88e0-60146f9e1d24
      - CAR_NUMBER=1
      - CAR_MODEL=tesla:m3:22:60lfp:heatpump #NOTE: This is optional, see below
     
volumes:
  teslamate-db:
  teslamate-grafana-data:
  mosquitto-conf:
  mosquitto-data:

Everything builds without any issues, telamate is working fine. I can see when I am subscribing MQTT topic that the data is being published by MQTT correctly.
In the Teslamate-ABRP logs I have this:

$ sudo docker-compose logs ABRP
Attaching to TeslaMate_ABRP
TeslaMate_ABRP | {'--model': None,
TeslaMate_ABRP | '-a': False,
TeslaMate_ABRP | '-h': False,
TeslaMate_ABRP | '-l': False,
TeslaMate_ABRP | '-p': False,
TeslaMate_ABRP | 'CAR_NUMBER': None,
TeslaMate_ABRP | 'MQTT_PASSWORD': None,
TeslaMate_ABRP | 'MQTT_SERVER': None,
TeslaMate_ABRP | 'MQTT_USERNAME': None,
TeslaMate_ABRP | 'USER_TOKEN': None}
TeslaMate_ABRP | Connected with result code 0. Connection with MQTT server established.
TeslaMate_ABRP | Car model manually set to: tesla:m3:22:60lfp:heatpump
TeslaMate_ABRP | 2023-02-07 11:03:31: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:32: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:33: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:34: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:35: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:36: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:37: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:38: Car is (unknown state), not sending any update to ABRP.
TeslaMate_ABRP | 2023-02-07 11:03:39: Car is (unknown state), not sending any update to ABRP.

Do you see any wrong inputs in my docker-compose file above?

SoC not the usable SoC is sent to the Iternio API

I live in a cold climate. My vehicle is often cold and there can be a significant difference between the SoC and the usable SoC that is actually displayed in the vehicle.

The documentation states

soc [SoC %]: State of Charge of the vehicle (what's displayed on the dashboard of the vehicle is preferred)

Teslamate shows the difference between the SOC and usable SOC

Image 2022-02-16 at 10 14 PM

Which matches the data shown in the vehicle

IMG_2364

Whereas ABRP shows

Screen Shot 2022-02-16 at 10 13 12 PM

Name does not resolve

I tried to run it but it stops with the following issue, any idea?:

David@Synology:/volume1/docker/TeslaLogger$ sudo docker-compose pull ABRP
Pulling ABRP ... done
David@Synology:/volume1/docker/TeslaLogger$ sudo docker-compose up ABRP
Creating TeslaMate_ABRP ... done
Attaching to TeslaMate_ABRP
TeslaMate_ABRP | {'--model': None,
TeslaMate_ABRP | '-a': False,
TeslaMate_ABRP | '-h': False,
TeslaMate_ABRP | '-l': False,
TeslaMate_ABRP | '-p': False,
TeslaMate_ABRP | 'CAR_NUMBER': None,
TeslaMate_ABRP | 'MQTT_PASSWORD': None,
TeslaMate_ABRP | 'MQTT_SERVER': None,
TeslaMate_ABRP | 'MQTT_USERNAME': None,
TeslaMate_ABRP | 'USER_TOKEN': None}
TeslaMate_ABRP | Traceback (most recent call last):
TeslaMate_ABRP | File "/usr/src/teslamate-abrp/./teslamate_mqtt2abrp.py", line 110, in
TeslaMate_ABRP | client.connect(MQTTSERVER)
TeslaMate_ABRP | File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 914, in connect
TeslaMate_ABRP | return self.reconnect()
TeslaMate_ABRP | File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 1044, in reconnect
TeslaMate_ABRP | sock = self._create_socket_connection()
TeslaMate_ABRP | File "/usr/local/lib/python3.10/site-packages/paho/mqtt/client.py", line 3685, in _create_socket_connection
TeslaMate_ABRP | return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
TeslaMate_ABRP | File "/usr/local/lib/python3.10/socket.py", line 824, in create_connection
TeslaMate_ABRP | for res in getaddrinfo(host, port, 0, SOCK_STREAM):
TeslaMate_ABRP | File "/usr/local/lib/python3.10/socket.py", line 955, in getaddrinfo
TeslaMate_ABRP | for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
TeslaMate_ABRP | socket.gaierror: [Errno -2] Name does not resolve

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.