Closed kegelmeier closed 3 years ago
Hi @kegelmeier,
Interesting! Looks to me that there is something related to MQTT then.
What type of setup of TeslaMate are you running.. Basic Docker or Advanced Traefik? Or something custom made?
Does MQTT container log say something similar to an attempt to connect?
Could you please share the configuration of your MQTT section in docker-compose.yml
file?
It should look similar to something like this:
mosquitto:
image: eclipse-mosquitto:1.6
restart: always
ports:
- 127.0.0.1:1883:1883
volumes:
- mosquitto-conf:/mosquitto/config
- mosquitto-data:/mosquitto/data
In addition, please set DEBUG_MODE
environmental variable to true
so that we can get more output from the log.
Regards, Tobias
Hi @tobiasehlert
Thanks for the quick reply. I am using the Traefik setup.
Regarding the MQTT part, I also have a Home Assistant setup running on the network that serves as the broker.
Therefore the MQTT settings within the docker-compose.yml
are custom as the following:
- MQTT_HOST=192.168.178.197
- MQTT_USERNAME=k***
- MQTT_PASSWORD=k***
Could it be that the HA does not allow two connections from the same host? Or does the API container rely on the mosquitto instance within teslamate?
Best, Jens
Here, additionally the output of the container logs in DEBUG_MODE
teslamateapi_1 | 2021/03/16 13:43:47.581394 [debug] initDBconnection - successfully completed (connected to postgres).
teslamateapi_1 | 2021/03/16 13:44:07.025670 TeslaMateAPICarsStatus successfully connected to mqtt.
teslamateapi_1 | 2021/03/16 13:44:07.135052 [debug] getTimeInTimeZone - UTC 0001-01-01T00:00:00Z time converted to Europe/Berlin is 0001-01-01T00:53:28+00:53
teslamateapi_1 | 2021/03/16 13:44:07.135207 [debug] getTimeInTimeZone - UTC 0001-01-01T00:00:00Z time converted to Europe/Berlin is 0001-01-01T00:53:28+00:53
teslamateapi_1 | 2021/03/16 13:44:07.135322 [debug] TeslaMateAPICarsStatusV1 /api/v1/cars/1/status returned data:
teslamateapi_1 | [GIN] 2021/03/16 - 13:44:07 | 200 | 783.093968ms | 192.168.178.178 | GET "/api/v1/cars/1/status"
teslamateapi_1 | 2021/03/16 13:44:07.136668 [debug] {"data":{"car":{"car_id":1,"car_name":"MJ3"},"status":{"display_name":"","state":"","state_since":"0001-01-01T00:53:28+00:53","odometer":0,"car_status":{"healthy":false,"locked":false,"sentry_mode":false,"windows_open":false,"doors_open":false,"trunk_open":false,"frunk_open":false,"is_user_present":false},"car_details":{"model":"","trim_badging":""},"car_exterior":{"exterior_color":"","spoiler_type":"","wheel_type":""},"car_geodata":{"geofence":"","latitude":0,"longitude":0},"car_versions":{"version":"","update_available":false,"update_version":""},"driving_details":{"shift_state":"","speed":0,"heading":0,"elevation":0},"climate_details":{"is_climate_on":false,"inside_temp":0,"outside_temp":0,"is_preconditioning":false},"battery_details":{"est_battery_range":0,"rated_battery_range":0,"ideal_battery_range":0,"battery_level":0,"usable_battery_level":0},"charging_details":{"plugged_in":false,"charge_energy_added":0,"charge_limit_soc":0,"charge_port_door_open":false,"charger_actual_current":0,"charger_phases":0,"charger_power":0,"charger_voltage":0,"scheduled_charging_start_time":"0001-01-01T00:53:28+00:53","time_to_full_charge":0}},"units":{"unit_of_length":"km","unit_of_temperature":"C"}}}
teslamateapi_1 | 2021/03/16 13:44:07.136708 [info] TeslaMateAPICarsStatusV1 /api/v1/cars/1/status executed successful.
Hi @kegelmeier,
Alright, so your HA does provide the MQTT functionality in your setup? That would mean that TeslaMateApi would need to connect to HA to get the information published by TeslaMate to HA.
Is this what you are using? https://www.home-assistant.io/docs/mqtt/service/
When thinking of MQTT and multiple clients, that should be no problem. The question is more, why HA doesn't send back the last information published on a topic so that it can be consumed.. but it seems that you have not configured HA to retain the messages.
If you enable retain, the MQTT broker will stores the last retained message. Each client (e.g. TeslaMateApi) that subscribes to a topic pattern that matches the topic of the retained message receives the retained message immediately after they subscribe. The broker stores only one retained message per topic and no history.
Regards, Tobias
Hi @tobiasehlert,
I am running Mosquitto on Home Assistant with this add-on (https://github.com/home-assistant/addons/blob/master/mosquitto/DOCS.md)
I checked the set-up with an MQTT Explorer and find that the messages are already retained.
Any other idea? Best, Jens
I have a theory/suspicion...
Mosquitto is not returning results within 100 milliseconds.
I am running Mosquitto on Home Assistant with this add-on (https://github.com/home-assistant/addons/blob/master/mosquitto/DOCS.md)
I checked the set-up with an MQTT Explorer and find that the messages are already retained.
Alright, then we know that it's retained already.
I have a theory/suspicion...
Mosquitto is not returning results within 100 milliseconds.
Was thinking about the same thing @LelandSindt.. let's make it customizable to see if this can solve the problem for Jens.
@kegelmeier, created a separate branch (bug-14) and you can test the image bug-14 to see, if it works.
Set the MQTT_SLEEPTIME
to 500 (default is 100) to see, if that works better for you.
Great, thanks @LelandSindt and @tobiasehlert! The image seems to work. The first try did not work but every request after that worked out.
Awesome @kegelmeier Then I'll go ahead and merge it with main.
Don't forget to switch image to latest to don't miss out on new stuff =D
Hello,
I have an issue with the teslamateapi. I do not get valid responses from the
/api/v1/cars/1/status
, however, the response of/api/v1/cars/1
is fine. How can this be?The logs also look fine.
Response /api/v1/cars/1/status
Response /api/v1/cars
Logs
Thank you in advance!