Rest Sensor for Spritmonitor.de / Vehicle fuel and cost tracker

When I started to use HA missed out a implementation for the service Spritmonitor.
I created a rest sensor for the API to display the data via markdown card.

This sensor implementation is not perfect but can give you a startingpoint for your implementation or visualization. Feel free to share improvements or optimizations.

Overview about Spritmonitor Service
Spritmonitor calculates the fuel consumption of your vehicle and helps you manage your car costs.
The consumption and cost analysis as well as many other functions are available to you free of charge
after registration. In addition to the web interface, you can also use Spritmonitor with their smartphone apps.

Content:
Implementation of a REST-Sensor to access data from Spritmonitor Service via the API

Prerequisite:

  • Spritmonitor Account: Spritmonitor.de
    You can register for free over the portal

  • BEARER_TOKEN
    You can create a new access bearer token on the Spritmonitor Password Page.
    Format: “Bearer < your bearer token >”

  • APP_TOKEN
    The app token can be requested by the Spritmonitor support on the Spritmonitor Contact Page.
    Format: “< your app token >”

Sensor configuration in configuration.yaml
Replace < vehiclex > in the code with your naming/plate

Example: Access 3 vehicles with one API Request
rest:
  - resource: "https://api.spritmonitor.de/v1/vehicles.json"
    authentication: basic
    scan_interval: 3600
    headers:
      Content-Type: application/json
      User-Agent: Home Assistant REST Sensor
      Application-Id: !secret spritmonitor_apptoken
      Authorization: !secret spritmonitor_bearer

    sensor:
      - name: "vehicle_<vehicle1>_avgconsumption"
        value_template: "{{ value_json[0].consumption }}"
        device_class: volume
        unit_of_measurement: "l/100km"
        json_attributes_path: "$.[0]"
        json_attributes:
          - make
          - model
          - sign

      - name: "vehicle_<vehicle1>_trip"
        value_template: "{{ value_json[0].tripsum }}"
        device_class: distance
        unit_of_measurement: "km"
        json_attributes_path: "$.[0]"
        json_attributes:
          - make
          - model
          - sign

      - name: "vehicle_<vehicle2>_avgconsumption"
        value_template: "{{ value_json[1].consumption }}"
        device_class: volume
        unit_of_measurement: "l/100km"
        json_attributes_path: "$.[1]"
        json_attributes:
          - make
          - model
          - sign

      - name: "vehicle_<vehicle2>_trip"
        value_template: "{{ value_json[1].tripsum }}"
        device_class: distance
        unit_of_measurement: "km"
        json_attributes_path: "$.[1]"
        json_attributes:
          - make
          - model
          - sign

      - name: "vehicle_<vehicle3>_avgconsumption"
        value_template: "{{ value_json[2].consumption }}"
        device_class: volume
        unit_of_measurement: "l/100km"
        json_attributes_path: "$.[2]"
        json_attributes:
          - make
          - model
          - sign
		  
	  - name: "vehicle_<vehicle3>_trip"
        value_template: "{{ value_json[2].tripsum }}"
        device_class: distance
        unit_of_measurement: "km"
        json_attributes_path: "$.[2]"
        json_attributes:
          - make
          - model
          - sign

Visuailization with Markdown Card:

01-09-2024_09-29-41

Markdown card code
<table>
<tr><td>{{ state_attr('sensor.vehicle_<vehicle1>_avgconsumption','model') }}&ensp;</td>
<td>{{ states('sensor.vehicle_<vehicle1>_avgconsumption') }}l&ensp;</td>
<td>{{ states('sensor.vehicle_<vehicle1>_trip') }} km&ensp;</td>
</tr>
<tr><td>{{ state_attr('sensor.vehicle_<vehicle2>_avgconsumption','model') }}&ensp;</td>
<td>{{ states('sensor.vehicle_<vehicle2>_avgconsumption') }}l&ensp;</td>
<td>{{ states('sensor.vehicle_<vehicle2>_trip') }} km&ensp;</td>
</tr>
<tr><td>{{ state_attr('sensor.vehicle_<vehicle2>_avgconsumption','model') }}&ensp;</td>
<td>{{ states('sensor.vehicle_<vehicle3>_avgconsumption') }}l&ensp;</td>
<td>{{ states('sensor.vehicle_<vehicle3>_trip') }} km&ensp;</td>
</table>

More information you can find on their Github page:

2 Likes