reptilex / tesla-style-solar-power-card

Home assistant power card mimicking the one tesla provides for the powerwall app.
221 stars 59 forks source link

Request: decimal place configuration #142

Open melvanderwal opened 1 year ago

melvanderwal commented 1 year ago

It would be nice to be able to round kW text to a selected number of decimal places within the icon bubbles. This would mitigate overlap with the bubble perimeter and would increase readability. Could be universal, or perhaps per-device would let people choose more detail for specific devices when it is logical. For myself, I don't need to see more than 1 decimal. I do like the auto-display where it drops trailing zeroes from the number - perhaps a max number of digits following the decimal point would be an option?

Thanks very much for this card - I've been able to clean up so much clutter from gauges and glance cards into a clean, intuitive UX. It was simple to adjust the Power Wall sample code to a Goodwe inverter.

djfanatix commented 1 year ago

Yes one up for this! Since HA 2023.3, decimals are configured in the UI, and some are messed up. (such as my battery %)

PierreScerri commented 1 year ago

That would be nice. It would save having duplicate template sensors.

melvanderwal commented 1 year ago

I figured out something that works for me - rounding the APF xxxx Entities to the nearest 100 Watts. In the card, the entity is then shown as an integer when it is watts, and to 1 decimal place when it is kilowatts (and maintains the trimming of the trailing zero, like the grid entity shown below). You could similarly round to 10 Watts or 1000 Watts for different levels of decimal precision. e.g. For the APF House Entity: state: "{{ (states('sensor.load')|float / 100)|round(0) * 100 }}"

Would still be handy to do it via the config, but this also works.

image

mkanet commented 11 months ago

I figured out something that works for me - rounding the APF xxxx Entities to the nearest 100 Watts. In the card, the entity is then shown as an integer when it is watts, and to 1 decimal place when it is kilowatts (and maintains the trimming of the trailing zero, like the grid entity shown below). You could similarly round to 10 Watts or 1000 Watts for different levels of decimal precision. e.g. For the APF House Entity: state: "{{ (states('sensor.load')|float / 100)|round(0) * 100 }}"


@melvanderwal I hope you're still watching this thread. Could you please do me a huge favor and copy and paste all your template sensors related to tesla-style-solar-power-card as tesla-style-solar-power-card lovelace code?

I think something must have changed in Home Assistant or the Integration to make your example not correct anymore. When I use your example above, all my AFP values show as 0. It looks like your suggested code is presuming that my tesla powerwall Entities are in Watts. They are actually in Kilowatts for me.

Below are my template sensors:

      - name: APF Grid Entity
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: "{{ ((0 - states('sensor.powerwall_site_power')|float * 1000) / 100)|round(0) * 100 }}"
      - name: APF House Entity
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: "{{ (states('sensor.powerwall_load_power')|float * 1000 / 100)|round(0) * 100 }}"
      - name: APF Generation Entity
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: "{{ (states('sensor.powerwall_solar_power')|float * 1000 / 100)|round(0) * 100 }}"
      - name: APF Battery Entity
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: "{{ ((0 - states('sensor.powerwall_battery_power')|float * 1000) / 100)|round(0) * 100 }}"
      - name: APF Grid Import
        device_class: power
        state_class: measurement
        unit_of_measurement: W
        state: >
          {% if states('sensor.apf_grid_entity')|int(default=0) < 0 %}
            {{ states('sensor.apf_grid_entity')|int(default=0)|abs }}
          {% else %}
            0
          {% endif %}