Car telemetry and Torque data

EDIT: Found the issue, the Torque app is actually called org.prowl.torquefree

Trying to get this to work, but I keep getting the below error:

android.content.ActivityNotFoundException: No Activity found to handle Intent { flg=0x10040000 pkg=org.prowl.torque }

Anyone had this before or know how to fix it?

Thanks in advance

Jonathan

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?

1 Like

If anyone is interested in getting the individual sensors to show up here’s some samples of my code for template sensors:

# in sensors.yaml
- platform: mqtt
  name: "Car Torque"
  state_topic: "devices/car/torque"
  value_template: "{{ state_attr('sensor.car_torque', 'GPS Time') }}"
  json_attributes_topic: "devices/car/torque"

# templates for individual sensors
- platform: template
  sensors:
    car_acceleratorpedalposition:
      value_template: "{{ state_attr('sensor.car_torque', 'Accelerator PedalPosition D(%)') }}"
      friendly_name: Car Accelerator Pedal Position
      unit_of_measurement: '%'
            
    car_ambientairtemp:
      value_template: "{{ state_attr('sensor.car_torque', 'Ambient air temp(°F)') }}"
      friendly_name: Car Ambient air temp
      unit_of_measurement: '°F'

# For sensors that return time in seconds we can make it more readable
    car_runtimesinceenginestart:
      value_template: "{{ state_attr('sensor.car_torque', 'Run time since engine start(s)') }}"
      friendly_name: Car Run time since start
      unit_of_measurement: 's'
      
    car_runtimesinceenginestart_formatted:
      friendly_name: 'Car Run time since start Formatted'
      value_template: >-
        {% set etime = states.sensor.car_runtimesinceenginestart.state | int %}
        {% set seconds = etime % 60 %}
        {% set minutes = ((etime % 3600) / 60) | int %}
        {% set hours = ((etime % 86400) / 3600) | int %}
        {% set days = (etime / 86400) | int %}
        {%- if days > 0 -%}
          {%- if days == 1 -%}
            1 day
          {%- else -%}
            {{ days }} days
          {%- endif -%}
          {{ ', ' }}
        {%- endif -%}
        {%- if hours > 0 -%}
          {%- if hours == 1 -%}
            1 hour
          {%- else -%}
            {{ hours }} hours
          {%- endif -%}
          {{ ', ' }}
        {%- endif -%}
        {%- if minutes > 0 -%}
          {%- if minutes == 1 -%}
            1 minute
          {%- else -%}
            {{ minutes }} minutes
          {%- endif -%}
        {%- endif -%}
1 Like

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.

1 Like

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.

1 Like

Hi @cunninr2 Kudos on this. Must have been a lot of work!

I’m currently trying to build a plugin for the Torque Android app that will grab the logs and send them to HA as they’re created.

I was wondering if you’d be able to give me some information about what needs to be done to the CSV files when sending them to HA.

Here’s my post for the project:

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 %}
1 Like

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

:slightly_smiling_face: that was going to be my suggestion.

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.

nobody has any idea?

I changed to a newer android phone and got rid of the sslhandshake issue but now I am getting owntracks post failure :persevere:

@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

If relevant, created a new docker image for Torque API that publishes MQTT message,
you can find it in:

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.

I’ve also updated the automate script to give a warning when the log file is not being populated.

Thanks for the affirmation. I’ll message the dev asap.