Driving speed

Im trying to make a graph that will show driving speed based on the device tracker, but getting nowhere. Could anyone offer some advice please.

Heres what ive tried, but its not working

  - platform: template
    sensors:
    digi_speed:
      value_template: "{{ state_attr('device_tracker.digi', 'speed') }}"
      attribute_templates:
        speed: >

what id like to end up with, is a gauge on my home screen tablet, next to what i already have, which is a small map with a pin of my current location, my distance from home, and ETA

tia

Does device_tracker.digi have an attribute called speed?

Check in Developer Tools States. What does the attribute contain?

If speed is not an option, do you have Lat & Long? What is the update interval?
You could do an estimate assuming straight line from current position to last position over the update interval. I have that calculation (for distance based on Lat & Long) somewhere (you may need to reformat for yaml) if you need it, I used to use it for determining distance between APRS contacts. Just get the distance and divide by update interval to get speed, then convert to miles/hour or km/min or m/sec or mm/msec or AU/epoch (this might not be too useful).

Yes, it does contain speed. I also have the life360 integration, which I use for the map with pin to show my location, which if possible, I’d also like an icon to light up when it detects that im driving

Remove this:

      attribute_templates:
        speed: >

And add:

      unit_of_measurement: 'km/h' # or 'mph', whatever you use.

Thats sorted it, thank you so much

Ive now got a gauge that will show my speed, as well as a colour, 8-30 mph will be green, 31-70 will be yellow, and 71 and above red. Anything below 8mph should mean im either walking or out running

1 Like

OK, so after using it, the speed part of the tracker never updates, so I’ll try using the speed part of the life360 integration, which does update. I’ll need to see if I can change it from km to miles as well

value_template: "{{ ( state_attr('device_tracker.life360', 'speed')|float * 0.621371 )|round(1) }}"
1 Like

thank you so much, this works

if i change the round(1) to round (0) will it remove the decimal place?

Yes that is correct.

1 Like

I can’t figure out how to put it on Lovelace!

Old thread, I know. I’m working on doing something similar. I tried with the android app but the speed doesn’t ever change. I set up Owntracks, this works well using the velocity attribute. But the numbers are a little off. For ex, it says I’m doing 165mph when I’m only doing 100mph.

I’m wondering if there’s a way to make that more accurate.

YAML Code

###############################
# Speed Sensors
  - platform: template
    sensors:
      bmws9_speed:
        friendly_name: "BMW S9 Speed"
        unit_of_measurement: 'mph'
        icon_template: mdi:speedometer
        value_template: "{{ state_attr('device_tracker.galaxy_s9_bmw', 'speed') }}"
  - platform: template
    sensors:
      bmws9_velocity:
        friendly_name: "BMW S9 Velocity"
        unit_of_measurement: 'mph'
        icon_template: mdi:speedometer
        value_template: "{{ state_attr('device_tracker.kiosk_bmws9', 'velocity') }}"
###############################

Dashboard YAML if you’re curious.

type: horizontal-stack
cards:
  - type: custom:mini-graph-card
    entities:
      - sensor.bmws9_velocity
    name: BMW Speed
    hours_to_show: 24
    line_width: 5
    color_thresholds:
      - value: 0
        color: '#60d2ff'
      - value: 50
        color: '#b1ff60'
      - value: 80
        color: '#ffb010'
      - value: 130
        color: '#ff0000'
    show:
      legend: true
      icon: true
      labels: false
      state: true
      labels_secondary: false
  - type: custom:mini-graph-card
    entities:
      - entity: sensor.galaxy_s9_bmw_battery_state
    name: Charge State
    hours_to_show: 48
    points_per_hour: 60
    update_interval: 30
    aggregate_func: max
    line_width: 5
    smoothing: false
    show:
      legend: false
      icon: true
      labels: false
      state: true
      labels_secondary: false
    state_map:
      - value: discharging
        label: discharging
      - value: charging
        label: charging

Update: I was experiencing an issue with the kmh to mph conversion. Sorted that and its good now using owntracks.

Hey, I’m new to templates, where do you put the yaml code for the sensors?

Directly in the main config file for HA.

Apologies for bringing up an old thread, but I am at a loss.

How would I go by adding this to a button card?

Currently I have a style with nothing in it yet for the speed

Speed:
- position: absolute
- right: 4%
- bottom: 4%

And then for the sensor I have this

        [[[
          return `<ha-icon
            icon="mdi:speedometer"
            style="width: 25px; height: 25px;"></ha-icon
            <span>${states'device_tracker.pixel_8_pro', 'speed''].state}KM</span>`
        ]]]</sub>

No matter what I try I can not get it to work. There is sensor.pixel_8_pro_car_speed, but it looks like it never updates even though it is active