Python Plugin: Toyota Topic is solved

Python and python framework

Moderator: leecollings

mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

MQTT for domoticz is integrated. current sensors are:
Odomoter
Fuel Consumption
Fuel Level
Lock Status
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

mxpwr wrote: Friday 08 August 2025 21:33
manjh wrote: Tuesday 05 August 2025 13:33 No other errors found! Aside from these two typo's in the installation instruction, the setup went very smoothly.

I am impressed with this plugin!
Will be playing with it some more.

Already see one change request: in "historical data" the options are 7, 30 or 90 days. Could you add "all"?
i added "all" option and some other things (heatmap and histogram plot).
I did the docker compose update. But don't see the difference on the screens. Do I need to manually restart something?
Hans
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

Mentioned this before: "docker-compose" does not work, "docker compose" does. Same thing for the update instructions.
Hans
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

mxpwr wrote: Thursday 07 August 2025 18:56
manjh wrote: Thursday 07 August 2025 18:34 Missing on the dashboard panel: battery level (%), and EV consumption (kWh/100).
Perhaps because the author has a hybrid, not a PHEV?
If you want, I can do the testing!
Yes, I have a hybrid. I was wondering if this will work with other types of cars. If you get me your logs, I can probably fix this.
Can you describe location and name of the log you need?
Hans
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

I sent you a pm with the instructions.
After the update, you should have mqtt settings on the settings page.
Screenshot_20250809-095840.png
Screenshot_20250809-095840.png (184.17 KiB) Viewed 771 times
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

Got it, update done.
Now going into MQTT work.

I did the settings as described, added a source node to Node-Red. Nothing comes in.
Hans
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

Checked the log:

Code: Select all

2025-08-09 10:19:01,331 - app.mqtt - INFO - Preparing to publish MQTT data for VIN: (removed VIN)
2025-08-09 10:19:01,331 - app.mqtt - DEBUG - Using MQTT base topic: mytoyota
2025-08-09 10:19:01,332 - app.mqtt - INFO - Finished publishing data for (removed VIN)
So it looks like it is sending data, but my MQTT does not receive. Tried this with both my test and prod MQTT/NodeRed setup.

It seems the app skips sending info to the broker when nothing has changed. This makes it a bit difficult to test...
I tried to unlock the car and then refresh the data, it show the status OK on the dashboard. But no change to MQTT.

I remember you mentioned there are only a few items at this point sent to MQ, perhaps I shoould wait for that?
Last edited by manjh on Saturday 09 August 2025 12:53, edited 1 time in total.
Hans
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

Just to make sure the settings are OK, I changed the IP address of the MQTT server to a non-existing server.
This throws some error messages. Basically it is OK, since there is no server. But perhaps it is more user friendly to catch this error and display a simple error message, including the IP address that was used.
For instance: "Non existing path to MQTT server, using IP 10.0.0.123"

These are the errors I see now:

Code: Select all

[/code2025-08-09 10:22:54,996 - app.mqtt - ERROR - Failed to connect to MQTT broker: [Errno 113] No route to host
Traceback (most recent call last):
  File "/app/app/mqtt.py", line 29, in get_client
    client.connect(host, port)
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1435, in connect
    return self.reconnect()
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 1598, in reconnect
    self._sock = self._create_socket()
                 ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 4609, in _create_socket
    sock = self._create_socket_connection()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/paho/mqtt/client.py", line 4640, in _create_socket_connection
    return socket.create_connection(addr, timeout=self._connect_timeout, source_address=source)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/socket.py", line 863, in create_connection
    raise exceptions[0]
  File "/usr/local/lib/python3.11/socket.py", line 848, in create_connection
    sock.connect(sa)
OSError: [Errno 113] No route to host]
Hans
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

You need to have the mqtt server set up. See instructions here.

https://wiki.domoticz.com/MQTT

I updated the readme with mqtt instructions, but this part is still missing.
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

mxpwr wrote: Saturday 09 August 2025 12:30 You need to have the mqtt server set up. See instructions here.

https://wiki.domoticz.com/MQTT

I updated the readme with mqtt instructions, but this part is still missing.
I have a working MQ setup, it interfaces to Domoticz...
I use the Aedes broker in Node-Red. When I attach a debug node to the output, I can see the connection with the Toyota app.

Code: Select all

9-8-2025, 12:50:51node: debug 31
client : msg : Object
{ topic: "client", payload: object, _msgid: "44843fdb118ce35a" }
9-8-2025, 12:50:51node: debug 31
clientReady : msg : Object
{ topic: "clientReady", payload: object, _msgid: "a08a65a7ec844676" }
9-8-2025, 12:50:54node: debug 31
clientDisconnect : msg : Object
{ topic: "clientDisconnect", payload: object, _msgid: "b21b327f330f
But no actual data messages, probably because they are skipped.

Would it be possible to (temporarily) remove that check on changed data, so it will always send data to MQTT after a refresh?
Hans
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

Yes, I'll add some debug options later tonight.
It might also be connected to some of yours values not being fetched. I'll look into it.
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

I added more debugging prints to the mqtt integration, and you can now select which "sensors" should be created and you can also send a test message from your cached data (requires that you have data in the cache file).

For me, this looks now like this when I enable all sensors (i included EV level and EV range, which does not exist for my car).

Listen to the mqtt stream:

Code: Select all

mosquitto_sub -h 192.168.1.200 -p 1883 -t "mytoyota/#" -v
mytoyota/car/odometer {"value": 11088}
mytoyota/car/lock_status LOCKED
mytoyota/car/fuel_level {"value": 67}
mytoyota/car/fuel_consumption {"value": 5.16}
mytoyota/car/total_range {"value": 449}
No data is published for the EV parameters.

If i check the mytoyota logs now, i can find this:

Code: Select all

2025-08-09 20:06:49,025 - app.mqtt - DEBUG - Skipping MQTT publish for 'battery_level' because its value is missing from the API data.
2025-08-09 20:06:49,025 - app.mqtt - DEBUG - Skipping MQTT publish for 'ev_range' because its value is missing from the API data.
My best guess is that the API is not able to get the values since you have a different type of car. I will now look into the logs you send me and try to fix that as well.
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

I added the missing battery stats to the dashboard. you can now select in the settings page what you want to display on there.
The only item missing is " EV consumption (kWh/100)". I couldnt find any information about this in your logs.
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

Some error messages when I do a git pull:

Code: Select all

sudo git pull
Updating dadc566..6f53759
error: Your local changes to the following files would be overwritten by merge:
        data/mytoyota_config.yaml
Please commit your changes or stash them before you merge.
Aborting
What am I missing here??
Hans
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

I removed the whole directory and installed from fresh. It seems your git clone line is mixed up somehow.
Also, I still find docker-compose, which does not work for me, I have to manually remove the "-" so it runs "docker compose".

Anyway, got there at some point and filled the mqtt parameters. topic as "toyota/out". Still nothing.
Then I tried to check the output of the broker, and I found the MQTT topic in the data to be "toyota/out/ev_range".
I had specified "toyota/out" as topic, so the name of the value was added...

Checked my Domoticz setup: all data comes in as "domoticz/out", for all individual values.

So I think the topic should not include the name of the value!
Add the name of the value in the payload as a field "name" for instance.
Hans
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

First of all, thanks for test and your patience, much appreciated.

1. I looked into the docker compose command. If you ran the older version of docker the correct command is

Code: Select all

docker-compose up -d --build
if you run docker compose v2 (rewritten in rust or something) the command drops the hyphen

Code: Select all

docker compose up -d --build
Ill see how I can add this to the readme better.

2. Regarding your merge message on the git pull.

Code: Select all

sudo git pull
Updating dadc566..6f53759
error: Your local changes to the following files would be overwritten by merge:
        data/mytoyota_config.yaml
Please commit your changes or stash them before you merge.
Aborting
this happens when you have made changes to the config file and git cannot merge them, because the conflict. I noticed a stupid typo in one of my earlier commits where the "Auto Discovery Prefix" was
homeassitant
instead of
homeassistant
. so when you tried a git pull, git didnt know what to do. In this case, you should do a

Code: Select all

git stash
which will dump your changes into a stash file and then do a git pull. You can than either manually try to enter the settings back directly into the yaml file or just restart the webserver and use the setting page. Your car history is still there, that is stored in the mytoyota.db file in the same folder (/data).

3. Regarding the MQTT topic. I'm no expert with MQTT, so i m not sure what the exact behaviour should be, but to my understanding you set the base topic to domoticz/car (or whatever), and then all sensors are created as domoticz/car/sensor_name. If you dont add the sensor_name, Domoticz does not know to which sensor it should add the value. How do the sensor in Domoticz look for you? Are they created at all? Or is just the naming off?
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

Thanks, and I must apologize if I am a bit "pushy" or looking for details, I used to be software test manager for a major IT company, and I guess old habits never die... ;)

As for the docker-compose: we got that clear. I guess it's now a matter of adding some words to the install instructions to point out the difference.

Speaking of instructions: the "git clone" line in the instructions is does not work, it looks like it was garbled somehow.

Then the issue about the MQTT topic.
When I look at the way it is setup for Domoticz, this is how I understand the setting should be:
Topic can be seen as a group name. So when I define "toyota/out" in the settings panel, all sensors will be sent to MQTT with exactly that topic. Nothing should be added or appended.
There is then a single listener in Node Red that picks up all sensor data coming in under that topic name.
The way to determine which sensor it is, can be done via a field in the payload.
For Domoticz there is usually a field "idx" with the unique key.
For toyota-dashboard it could be a field like "name"in the payload, with the name of the sensor as data.

Does this make sense?

The autodiscovery in Domoticz and Homeassistant are not used by me, so I cannot shed any light on that.

One last thing: data from my car is not read completely. For instance, I know for a fact that the car is fully locked, but in toyota-dashboard it show up as unlocked.
I will do a more detailed compare of the data.
Hans
manjh
Posts: 783
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Python Plugin: Toyota

Post by manjh »

I checked the data against the official Toyota app, looks OK (except for the lock status).

Fields "total fuel" and "time driven" don't make much sense to me.
Hans
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

No worries, I'm myself working in SW development for over a decade. This turned into a rather large project, and detail is important :)

I think I understand the issue now with your MQTT integration (with some help of Gemini 8-) ).

You're describing a common "manual" way to handle MQTT, where all data goes to one topic and requires a script to process it.

However, this application uses the modern "Auto-Discovery" method, which works differently and is an easier integration method with Domoticz and Home Assistant.

Manual Method (what you described): You send all data to one topic (e.g., toyota/out). You then have to manually create virtual sensors in Domoticz and write a script (in Node-RED) to read the payload, figure out which sensor it is (e.g., "odometer"), and then send a special command to Domoticz to update the device by its idx.

Auto-Discovery Method (what this app uses): The application sends data to a separate, unique topic for each sensor (e.g., mytoyota/VIN/odometer). It first sends a special "config" message that automatically creates the device in Domoticz with the correct name, units, and tells it exactly which topic to listen to for its values. No manual setup or scripting in Node-RED is needed for the Domoticz integration to work.

This method is fully automatic and requires zero scripting for the end-user in Domoticz.

Solution for your Node-RED setup:

If you still want a single entry point in Node-RED to get all the data, you can easily do this by using a wildcard. In your "MQTT In" node, set the Topic to:
mytoyota/#

This will subscribe to all sensor topics at once. You can then use a "Switch" node to route the messages based on msg.topic to handle the specific sensors. This gives you the workflow you want without breaking the automatic Domoticz integration.

This is how my domoticz setup looks like
Untitled.png
Untitled.png (12.72 KiB) Viewed 502 times
mxpwr
Posts: 31
Joined: Sunday 19 July 2015 10:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Python Plugin: Toyota

Post by mxpwr »

manjh wrote: Sunday 10 August 2025 9:01 I checked the data against the official Toyota app, looks OK (except for the lock status).

Fields "total fuel" and "time driven" don't make much sense to me.
There seem to be issues sometimes with the pytoyoda API and reading the lock status.
I had issues as well and it seems that pytoyoda sometimes fills door or lock status as None and sometimes as True/False, which makes it difficult to understand what is happening. I could add some debug prints to figure out what is happening in your case and then we can try to implement a better way to interpret the message.

Regarding the fields:
Total Fuel: Amount of fuel you used over the lifetime of your account on this car
Time Driven: Total time you drove your car over the lifetime of your account on this car
(data from previous owners is not available)

But you can disable those fields now in the settings page :)
Post Reply

Who is online

Users browsing this forum: Filip and 1 guest