-
Notifications
You must be signed in to change notification settings - Fork 20
Template Sensor for Fuel Percentage
Wayne Drescher edited this page Oct 16, 2024
·
1 revision
This guide will help you create a template sensor in Home Assistant that converts an entity representing the remaining fuel into a percentage (0-100 range). This will allow the Ultra Vehicle Card
to display fuel percentage based on the remaining fuel data.
-
Open Home Assistant UI:
- Navigate to Settings > Devices & Services > Helpers.
- Click on Create Helper in the bottom-right corner.
-
Select the Template Option:
- Choose Template > Template a sensor from the list.
-
Configure the Template Sensor:
- Name: Enter a name for your sensor (e.g., "Fuel Percentage").
- State Template: Use the following template code:
{% set max_volume = 100 %} {# Replace 100 with the max volume of your tank in liters #} {% set current_fuel = states('sensor.your_fuel_entity') | float(0) %} {# Replace 'sensor.your_fuel_entity' with your actual fuel entity #} {{ ((current_fuel / max_volume) * 100) | round(0) }}
-
max_volume: Replace
100
with the maximum capacity of your fuel tank in liters (or gallons). -
current_fuel: Replace
'sensor.your_fuel_entity'
with your actual entity that tracks the remaining fuel.
- Set Unit of Measurement to
%
.
- Set Device Class to Volume (optional but recommended for categorizing the entity).
- Set State Class to Measurement.
- Click Create to save the new template sensor.
Once created, the new template sensor will appear in your entity list. It will dynamically calculate the fuel percentage based on the provided values.
You can now use this sensor in the Ultra Vehicle Card by referencing the newly created fuel_percentage
entity.