Car telemetry and Torque data

There are a few solutions for getting car telemetry into home assistant , but they have various problems. I have created a solution which uses REST and does not need an mqtt broker to be exposed to the internet. It also supports ssl connection to home assistant and choice of an API password or long lived access tokens. Finally, this method allows for you to capture other metrics from your car (outside of Torque data) if you wish to develop it further. You can see my method at

Comments welcome.

13 Likes

You write up looks very thorough. Thank you for making that effort.

1 Like

Thanks for this! I was starting to work out an approach for this myself. Thanks for doing the hard work!

no problem.

You welcome. It is a project with a fair few pitfalls, so I hope it benefits you.

Hi are you based in the UK? I have a qashqai too and was wondering which radio/media system would be best from the link you provided ?

Hi. Yes I’m in uk and drive Quashqai +2 with 360 entertainment system. The model i would advise is this one.

If you want the steering wheel controls to work you will need an add on for that also. My video feed from the car cameras wouldnt trigger the joying screen when i put it in reverse because the car signal was only 6v and the joying radio needed a 12v signal. I solved this with a couple of transistors to bump the signal to 12v.

I think the steering wheel controller was this one. https://rover.ebay.com/rover/0/0/0?mpre=https%3A%2F%2Fwww.ebay.co.uk%2Fulk%2Fitm%2F250904540472

1 Like

@cunninr2

I was able to get data into my HA using your instructions on your blog; however, I get the escape characters being sent via MQTT (see below)

{
“payload”: “{\”_type\”:\”location\”,\”tid\”:\”me\”,\”acc\”:,\”batt\”:77,\”conn\”:\”m\”,\”doze\”:false,\”lat\”:,\”lon\”:,\”tst\”:}”,
“topic”: “owntracks/homeassistant/mercedes”,
“retain”: “True”
}

And when I create a MQTT sensor in HA in never triggers. (see below)

owntracks:
max_gps_accuracy: 100
mqtt_topic: “owntracks/homeassistant/mercedes”

sensor:
– platform: mqtt
name: “Test Battery”
state_topic: “owntracks/homeassistant/mercedes”
unit_of_measurement: ‘%’
value_template: “{{ value_json.batt }}”

Are you having similar issues and do you think it’s related to the escape characters? I also receive the following error in HA about unsupported message type.

Logger: homeassistant.components.owntracks.messages
Source: components/owntracks/messages.py:391
Integration: OwnTracks (documentation, issues)
First occurred: 3:59:36 PM (2 occurrences)
Last logged: 3:59:46 PM

Received unsupported message type: None.

In your mqtt topic it should look something like this:

{"_type":“location”,“tid”:“RM”,“acc”:1,“batt”:53,“conn”:“m”,“doze”:false,“lat”:53.65138,“lon”:-1.06001,“tst”:1588627043}

If your getting the escape characters, I would check the http post block in the llamalab automate script. There is most likely a misplaced \ or " which means it is being posted incorrectly. My advise is start with a small string and then add further. It can be a bit of a headache to get the escape characters in the correct places.

Also check you have selected the Content-Type as JSON in the http post block

Thanks for the response. The escape characters are in the “request content body” of your v8 llamalab automate script. They only rear its ugly head when I send data using MQTT. If I look at the JSON object I don’t see it.

Now my configuration is a bit different in that I’m send everything to my HA system over a SSL webhook into a node-red which doesn’t require the Bearer Token authentication. I can see all the data move it between nodes, but as soon as I send it out via MQTT I see the escape characters when I listen for the topic. This is also my first exposure to MQTT, so that could be an issue as well. :slight_smile:

Thanks again and I guess I’ll keep fiddling with it because I am able to get the data from my phone into HA, but I just need to figure how to format and use it!

FYI - I got it to work! Thanks again for the great code!

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.