Current and last month distance travelled by car

Hi.

I am looking for an easy way to create a sensor or helper which gives me the current total amount of driven km of my car of the current and the amount of last month.

I have a sensor which shows me the current total km and any change via history. I already tried history stats - but I have no specific state - and utility meter doesn’t seem to work either.

Any help is highly appreciated.

Best w.

P.S. the sensor with the total amount

The utility meter should work for this months kilometers. It does not read history before its creation date, so you’d need to wait until next month to get the first full months worth. It will start at unavailable until the car (or the odometer to be presise) moves as well.

The history of the utility meter should show a sawtooth kind of graph, the highest peak of last month should be the total for that month. If you want it in a separate sensor, you could create a trigger based sensors that triggers just before the new month starts to copy the current month sensor value.

Thx. I will try that.

Utility meter helper just created. I will check with more patience. Some with the trigger event.

I will keep you posted.

It works.

As recommended I created a utility meter, called volvo_km_current_month

On the last day of the month at 23:59 I take the value and save it:

template:
  - trigger:
      - platform: time
        at: "23:59:00"
    condition:
      - condition: template
        value_template: "{{ (now() + timedelta(days=1)).day == 1 }}"  
    sensor:
      - name: "Volvo KM last month"
        state: "{{ states('sensor.volvo_km_current_month') }}"
        unit_of_measurement: "km"
        icon: mdi:map-marker-distance