Sensor Maximum Value Reading

Hi,

I have my vehicles speed as a sensor pulled in from traccar and formatted into mph.

I want to be able to read the maximum speed of my car from history and show it as a sensor in mph.
I have tried with the min_max and history_statistics to no avail.

Take a look at this topic:

Thanks, but i tried this also.

That is for when there are multiple sensors and it is working out an average using min/max sensor.
It can then pull the min value and max value from that sensor.

I am only getting data from 1 sensor so i cannot use the min/max sensor since it requires 2 or more different values.

The topic I posted is about one sensor. You create a statistics sensor for this sensor, which then has some attributes like “min_value”, “max_value” etc… Afterwards you create a template sensor to extract the attribute “max_value” from the statistic sensor.

Something like this:

sensor:
  # this creates a sensor "sensor.car_speed_statistics_mean"
  - platform: statistics
    entity_id: sensor.speed_measurment #entity_id of your speed sensor
    name: Car Speed Statistics

  # this extracts the attribute "max_value" from "sensor.car_speed_statistics_mean"
  - platform: template
    sensors:
      car_speed_max:
        value_template: "{{ state_attr('sensor.car_speed_statistics_mean', 'max_value') }}"

Wow yes thanks, i added this to my config:

  - platform: template
    sensors:
       speed_car:
        friendly_name: Speed
        unit_of_measurement: 'mph'
        value_template: '{{ (states.device_tracker.car.attributes.speed | float * 1.15078) | round(2) }}'

#MIN AND MAX READINGS OF CAR SPEED
      car_speed_max:
        value_template: "{{ state_attr('sensor.car_speed_stats', 'max_value') }}"
      car_speed_min:
        value_template: "{{ state_attr('sensor.car_speed_stats', 'min_value') }}"
#STATISTCS SENSOR FOR CAR SPEED
  - platform: statistics
    entity_id: sensor.speed_car
    name: Car Speed Stats
    sampling_size: 144

Will it only start tracking it from now? Highes value is currently 0.09mph (car is still)

Don’t know to be honest, I assume it starts from the first time you added the sensor.

Thanks for your help, guess i’ll find out when i leave work. Also what is the sampling_size for? I’ve left it in at 144 but not sure what it actually does…

Read this topic regarding sampling size:

Thanks, is showing my top speed now :slight_smile:

My tracker reports every 10 seconds so

86,400 seconds in 24hrs
86400/10 = 8,640
sampling_size: 8640

Now to see how i can get it to report weekly. I cant use Start and End on a statistics sensor so need to scratch my head now :confused:

If you want to do it for a week, it should be like this I think:

86’400 seconds/day * 7 days = 604’800 seconds/week
604’800 seconds / 10 seconds = 60’480

sampling_size: 65'000 # bit higher to be on the safe side
max_age:
  days: 7

I know i would be able to do it that way but i mean so that it starts fresh every Monday. This is how all my other sensors work. I use this on my history sensors:

    start: '{{ as_timestamp( now().replace(hour=0).replace(minute=0).replace(second=0) ) - now().weekday() * 86400 }}'
    end: '{{ now() }}'
1 Like