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
a) You can create a new access bearer token on the Spritmonitor Password Page.
Format: “Bearer < your bearer token >”
b) !secret configuration:
The code example is set up with the !secret configuration. Find the official documentation here:
Storing secrets - Home Assistant -
APP_TOKEN
Spritmonitor assigned meanwhile an dedicated APP-Token, so you can use it directly. No individual request needed anymore.
Token: 190e3b1080a39777f369a4e9875df3d7
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: 190e3b1080a39777f369a4e9875df3d7
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:
Markdown card code
<table>
<tr><td>{{ state_attr('sensor.vehicle_<vehicle1>_avgconsumption','model') }} </td>
<td>{{ states('sensor.vehicle_<vehicle1>_avgconsumption') }}l </td>
<td>{{ states('sensor.vehicle_<vehicle1>_trip') }} km </td>
</tr>
<tr><td>{{ state_attr('sensor.vehicle_<vehicle2>_avgconsumption','model') }} </td>
<td>{{ states('sensor.vehicle_<vehicle2>_avgconsumption') }}l </td>
<td>{{ states('sensor.vehicle_<vehicle2>_trip') }} km </td>
</tr>
<tr><td>{{ state_attr('sensor.vehicle_<vehicle2>_avgconsumption','model') }} </td>
<td>{{ states('sensor.vehicle_<vehicle3>_avgconsumption') }}l </td>
<td>{{ states('sensor.vehicle_<vehicle3>_trip') }} km </td>
</table>
More information you can find on their Github page:
Update 02.02.2025: Requesting of APP-Token is not necessary anymore. Dedicated Token available, see text. Code example updated as well.
Update 06.02.2025: Added remark fĂĽr the !secret configuration which is used in the code example.