Float with decimal: in DevTools works but not in config

The sensor (scrape) give me the string of fuel price “1,975”, I need to convert it to a understeandable number to HA so I convert it with this template:
value_template: '{{ value.replace("," , ".") | float | round(3)}}'
or
value_template: '{{ "{:.3f}".format(value.replace("," , ".") | float) }}'

but it gave me only 1.98 in each case. What I’m doing wrong? I follow this solution and with DevTools works:

{{ "{:.3f}".format("1,975".replace("," , ".") | float) }}

result:

1.975

Note that apparently it give me the wanted number but inside history I see 1.98 instead of 1.975
2022-03-17_20-15

history display is maybe limited to 2 decimals ?

Wow, I didn’t think it was that since I hadn’t seen any mention of the decimals in the documentation. Indeed it is so … how can I change it?

Don’t know how to change that…

I have the same behavior with my gas consumption sensor (5 decimals but only two displayed with history)…

You can use the “mini-graph-card” to display history values, in this lovelace add-on card you can specify the decimals you want to see in the graph…

Combine with browser_mod, you can replace the pop-up window showing history with the “mini-graph-card” customized to your needs…

Here is an example using “button-card” with entities card, what is important is the “tap_action” part to get the pop-up window:

  - type: custom:button-card
    entity: sensor.eclairage_hall_etage
    name: 'Hall'
    label: 'Etage'
    variables:
      icon_on: "mdi:lightbulb-on"
      icon_off: "mdi:lightbulb-off-outline"
      color_background: "var(--button-card-light-background)"
    template:
      - card_light
    tap_action:
      action: fire-dom-event
      browser_mod:
        command: popup
        deviceID: this
        title: Eclairage Hall Etage
        card:
          type: entities
          entities:
            - switch.ac_157564a_10
            - type: divider
            - input_boolean.interrupteur_hall_etage_channel_1
            - switch.2_interrupteur_hall_etage_channel_1
            - type: divider
            - input_boolean.interrupteur_hall_etage_channel_2
            - switch.2_interrupteur_hall_etage_channel_2
            - type: divider
            - sensor.2_interrupteur_hall_etage_channel_1_power
            - sensor.2_interrupteur_hall_etage_channel_2_power
1 Like

A fairly easy fix is to multiply with 10 and you get the price per 10 liters instead