This is fantastic and the only option I’ve found so far that works for me. Thank you for all the work, the code is very thorough!
I’m working on it now but before I dive in, perhaps you’ve figured out a way to template or automate frequent car occupants so it’s a more readable string?
Glad it was of use to you. It’s always nice to see someone making use of my efforts. The head unit in my car has a problem scanning for new bluetooth mac addresses. It’s one of those issues I have not got round to resolving yet. If you do get it working it should not be too difficult to create a txt file in home assistant that stores names against mac addresses, so you can then display who is currently in the car.
On this note the ha companion app now reports what bluetooth devices the phone is coonected to. So you can know when a phone connects to the car. Not quite the same as knowing the driver.
Hi. Happy to help where I can. I think the cleanest way to export torgue log file is to convert the file to a JSON format. You can then http post each line in the log file as a payload directly into HA. I think I used the https://(server)/api/services/mqtt/publish method with a long lived access token for authentication. This places the data in your MQTT broker, but if you are not using an mqtt broker, I’m pretty sure you could post it directly to a sensor on HA. Looks like using `/api/states/<entity_id> would be the best direct method. Make sure to use the timestamp as your state, so that HA sees the sensor always being updated. Lastly, I think Torque has limited options in how many scans/log file lines it creates each second. I choose to poll the bottom line of the log file every X seconds and use the data in each next post.
Thanks for getting back to me. That’s been a big help in setting me off in the right direction.
From what you say you just publish right to the MQTT broker and not to the Torque integration, is that right? I’m trying to stick as close to Torque as possible, I think I might be able to do so.
Great post. It worked nicely for me. I even managed to make InfluxDB and Grafana add-ons work including World Map plug-in for Grafana following your instructions in this post. The only issue I seem to grapple with is separating individual car journeys from each other. How do you do that, please? Thank you in advance for your reply.
Since the data is all on a timeline, I’m not sure you can separate out the individual journeys (or at least I haven’t tried.) What I do do in home assistant is created a template sensor to determine if the car is transmitting data and by this method I can save the car journey data at the end of transmission.
Example:
platform: template
sensors:
quashqai_engine_status:
entity_id: sensor.time
friendly_name: Engine status
value_template: >-
{% if as_timestamp(now())|int > (state_attr(‘sensor.quashqai_automate’, ‘timestamp’)|int +60) %}
off
{% else %}
on
{% endif %}
Edit 1: I had “Rotate logfiles” enabled. Fixed now.
Edit 2: Still getting an empty object in MQTT. Digging deeper.
I’m getting an empty message in MQTT in Home Assistant. These are the messages that come through:
Message 85 received on devices/skoda/torque at 21:30:
{}
Message 84 received on devices/skoda at 21:30:
{
"time": "31 Aug 2021 18:40:50",
"occupants": "F4:92:BF:79:D5:5E, B4:88:94:4A:60:69",
"speed": "0"
}
Message 81 received on owntracks/homeassistant/skoda at 21:30:
{
"_type": "location",
"tid": "sk",
"acc": 12,
"batt": 15,
"conn": "m",
"doze": false,
"lat": 50.41355865121038,
"lon": 20.701180741338348,
"tst": 1630424427
}
Block 1541 looks for /sdcard/torqueLogs/trackLog.csv, but my device has files named like trackLog-2021-Aug-31_17-24-46.csv etc… As Torque is creating those files - was there a rename going on somewhere? Currently, there’s no trackLog.csv for the script to find. Does the script still work or should I replace the block where it looks for trackLog.csv and search for the most recent file? Or am I missing something? Some setting in Torque, perhaps?
Edit: Yup, I had “Rotate logfiles” enabled. Fixed now.
Logs for the whole loop:
08-31 17:24:59.597 U 3440@1373: Rest Post Success : Torque data :200
08-31 17:24:59.598 I 3440@0: Stopped at end
08-31 17:25:02.877 U 500@1541: Torque log file not found
08-31 17:25:02.877 I 500@1494: File exists?
08-31 17:25:02.881 I 500@1495: Delay
08-31 17:25:07.800 I 496@766: Fork
08-31 17:25:07.842 I 496@1050: Delay
08-31 17:25:07.848 I 3441@717: Go to
08-31 17:25:07.849 I 3441@1350: Label
08-31 17:25:07.849 I 3441@1360: Failure catch
08-31 17:25:07.850 I 3441@1684: Atomic load
08-31 17:25:07.850 I 3441@1686: Variable set
08-31 17:25:07.851 I 3441@1576: Atomic load
08-31 17:25:07.851 I 3441@1565: Atomic load
08-31 17:25:07.852 I 3441@1566: Atomic load
08-31 17:25:07.853 I 3441@1567: Battery level?
08-31 17:25:07.853 I 3441@1568: Atomic load
08-31 17:25:07.854 I 3441@1358: Variable set
08-31 17:25:07.854 I 3441@1359: HTTP request
08-31 17:25:07.868 I 502@1548: Location get
08-31 17:25:07.870 I 502@1549: Expression true?
08-31 17:25:07.870 I 502@1569: Variable set
08-31 17:25:07.870 I 502@1560: Atomic store
08-31 17:25:07.875 I 502@1561: Variable set
08-31 17:25:07.875 I 502@1562: Atomic store
08-31 17:25:07.879 I 502@1602: Atomic store
08-31 17:25:07.885 I 502@1603: Atomic store
08-31 17:25:07.890 I 502@1604: Variable set
08-31 17:25:07.890 I 502@1605: Atomic store
08-31 17:25:07.895 U 502@1550: GPS Position obtained: 4m:0 mph:gps
08-31 17:25:07.895 I 502@1693: Delay
08-31 17:25:07.898 U 500@1541: Torque log file not found
08-31 17:25:07.898 I 500@1494: File exists?
08-31 17:25:07.904 I 501@1275: Ping
08-31 17:25:07.908 I 500@1495: Delay
08-31 17:25:07.937 I 501@1502: Variable set
08-31 17:25:07.938 I 501@1507: Atomic store
08-31 17:25:07.943 I 501@1503: Expression true?
08-31 17:25:07.943 I 501@1692: Delay
08-31 17:25:08.424 I 3441@1353: Expression true?
08-31 17:25:08.426 U 3441@1356: Rest Post Success : owntracks : 200
08-31 17:25:08.427 I 3441@1579: Atomic load
08-31 17:25:08.428 I 3441@1571: Variable set
08-31 17:25:08.429 I 3441@1572: Variable set
08-31 17:25:08.429 I 3441@1573: Atomic load
08-31 17:25:08.437 I 3441@1382: HTTP request
08-31 17:25:08.939 I 3441@1363: Expression true?
08-31 17:25:08.939 U 3441@1365: Rest Post Success : device data :200
08-31 17:25:08.940 I 3441@1574: Atomic load
08-31 17:25:08.942 I 3441@1379: HTTP request
08-31 17:25:09.416 I 3441@1371: Expression true?
08-31 17:25:09.416 U 3441@1373: Rest Post Success : Torque data :200
I keep getting this error ” http post failure at block 1359 javax.net.ssl.sslhandshakeexception: connection closed by peer”
any idea what might cause this error?
I have HA external URL setup with duckdns. latest firmware on both supervisor and core.
mqtt also setup and checked with mqtt explorer.
I changed to a newer android phone and got rid of the sslhandshake issue but now I am getting owntracks post failure
@1303: Shell command 10-13 08:23:50.827 I 218@1553: Failure catch 10-13 08:23:50.831 I 218@1548: Location get 10-13 08:23:50.837 I 218@1549: Expression true? 10-13 08:23:50.838 I 218@1569: Variable set 10-13 08:23:50.838 I 218@1560: Atomic store 10-13 08:23:50.850 I 218@1561: Variable set 10-13 08:23:50.851 I 218@1562: Atomic store 10-13 08:23:50.869 I 218@1602: Atomic store 10-13 08:23:50.885 I 218@1603: Atomic store 10-13 08:23:50.899 I 218@1604: Variable set 10-13 08:23:50.902 I 218@1605: Atomic store 10-13 08:23:50.922 U 218@1550: GPS Position obtained: 5m:0 mph:gps 10-13 08:23:50.923 I 218@1693: Delay 10-13 08:23:50.967 I 216@1142: Variable set 10-13 08:23:50.968 I 216@1138: File monitor 10-13 08:23:50.994 I 217@1502: Variable set 10-13 08:23:50.994 I 217@1507: Atomic store 10-13 08:23:51.040 I 217@1503: Expression true? 10-13 08:23:51.045 I 217@1506: Expression true? 10-13 08:23:51.045 I 217@1280: Toast show 10-13 08:23:51.047 I 217@1505: Variable set 10-13 08:23:51.047 I 217@1692: Delay 10-13 08:23:51.136 I 215@1353: Expression true? 10-13 08:23:51.137 U 215@1355: Owntracks Post failure : discarding data: 401: 10-13 08:23:51.137 I 215@0: Stopped at end 10-13 08:23:51.895 I 216@1132: Shell command 10-13 08:23:51.928 I 216@1500: Variable set 10-13 08:23:51.929 I 216@1497: Expression true? 10-13 08:23:51.930 I 216@1501: Expression true? 10-13 08:23:51.931 I 216@1133: Variable set
There is also a login failed notification on my home assistant around the same time I run the script.
Any ideas why I am getting the owntracks post failure
Anyone have any insight as to why the csv file no longer seems to be going into the torquelogs folder that was created? I did some digging and the csv file is staying in the app’s data file. The problem with that is Android doesn’t allow outside access to that folder so I can’t do anything with this script. I hope it’s something I’m overlooking and doesn’t have anything to do with the Android 12 update.
I think the latest version of Torque has broken Data logging to a file. I noticed logging to file had stopped immediately after Google play updated the app. I’ve sent a message to the developer. Would recommend you send one too to get the problem noticed.