Converting percentage to value

Hi All,

I have a sensor that displays the badge in percentage of battery and I would like it to show in voltage

its a 12 volt battery so 0 to 12V at the moment is showing 0-100%. I would like to use a converter to show all in Volt ie 0%-0Volt and 100%-12Volt here is the current badge code which shows everything in %.

chart_type: line
period: hour
type: statistics-graph
entities:

  • sensor.one_battery_level
    stat_types:
  • mean
  • min
  • max
    title: 12V Battery Stats VOLT

Thank you

Please post code between ```
Then, using the regular card, you cannot (almost sure) so you would have to create another template sensor to cover the conversion
Alternatively, you can use Apexcharts which allows some calculations

EDIT: since you are using statistics, the new template will take some time to get data and only ‘from’ the moment it is active.

Are you sure the battery shows 0 volts at 0% and 6 volts at 50%?
I have never seen such a battery

1 Like

Assuming you want a simplistic linear conversion of percentage to voltage (which will be wrong, because that’s not how batteries work):

Template sensor (Helpers / Create Helper / Template / Template a sensor):

{{ states('sensor.one_battery_level')|float(0) / 12 * 100 }}

1 Like

image

:rofl:

And it also has to go into statistics on top :slight_smile:

Yes, exactly. The card should show:

entities:
  - sensor.super_wrong_inaccurate_sensor

or however the correctly-formatted YAML should look.

Try this.
You would need to have more info about the battery though, like if it says 50%, what voltage is it. Once you have at least 2 points, you can use it. (more points more accurate more better)

Thank you all for all your responce and feedback. it is appreciated.