lovelace-multiple-entity-row icon indicating copy to clipboard operation
lovelace-multiple-entity-row copied to clipboard

Numbers are formatted not accordingly to global settings

Open ildar170975 opened this issue 2 years ago • 9 comments

The card should use global format settings: изображение

This card contains:

  • conventional input_number row;
  • multiple-entity-row with the same row with different formats.

Note that:

  • the conventional row displays WRONG format (frontend issue);
  • multiple-entity-row displays WRONG format in some cases.

изображение

  - type: entities
    entities:
      - entity: input_number.test_negative_1
        name: test value
      - type: custom:multiple-entity-row
        entity: sun.sun
        entities:
          - entity: input_number.test_negative_1
            name: unformatted
        show_state: false
      - type: custom:multiple-entity-row
        entity: sun.sun
        entities:
          - entity: input_number.test_negative_1
            name: invert
            format: invert
        show_state: false
      - type: custom:multiple-entity-row
        entity: sun.sun
        entities:
          - entity: input_number.test_negative_1
            name: kilo
            format: kilo
        show_state: false
      - type: custom:multiple-entity-row
        entity: sun.sun
        entities:
          - entity: input_number.test_negative_1
            name: precision
            format: precision4
        show_state: false
      - type: custom:multiple-entity-row
        entity: sun.sun
        entities:
          - entity: input_number.test_negative_1
            name: position
            format: position
        show_state: false

Now, lets choose "None" format: изображение

The card now shows RIGHT format: изображение

ildar170975 avatar Dec 23 '21 14:12 ildar170975

See https://github.com/benct/lovelace-multiple-entity-row/pull/212#issuecomment-997214320 and following. Might be related to the same root cause.

Introduced with v4.3.0 I think.

bcutter avatar Dec 23 '21 14:12 bcutter

Guess I missed numberFormat on invert and position. Anything else?

benct avatar Dec 23 '21 15:12 benct

Anything else?

No, I think only these two options are with problems.

ildar170975 avatar Dec 23 '21 15:12 ildar170975

Confirm (Win10x64, Chrome): изображение

The conventional entity-row has wrong format (frontend issue).

ildar170975 avatar Dec 23 '21 19:12 ildar170975

Have a look at https://community.home-assistant.io/t/multiple-entity-row-card-local-number-formatting-update-broke-view/370718 for examples when this local number awareness feature is going too far.

bcutter avatar Dec 24 '21 11:12 bcutter

Here is one more issue - again formatting does not work.

There are 2 sensors from systemmonitor:

  • sensor.memory_free
  • sensor.memory_use

This sensor is a sum of those sensors:

  - platform: template
    sensors:
      memory_total:
        unit_of_measurement: MB
        icon_template: mdi:chip
        value_template: >-
          {% set FREE = 'sensor.memory_free' -%}
          {%- set USE = 'sensor.memory_use'-%}
          {{ ((states(FREE)|float) + (states(USE)|float)) | round(1) }}

And here is a card:

  - type: entities
    entities:
      - entity: sensor.memory_free
      - entity: sensor.memory_use
      - entity: sensor.memory_total
      - type: custom:multiple-entity-row
        entity: sun.sun
        entities:
          - entity: sensor.memory_free
            name: free
          - entity: sensor.memory_free
            name: free
            unit: false
          - entity: sensor.memory_use
            name: use
          - entity: sensor.memory_total
            name: total
            unit: false
          - entity: sensor.memory_total
            name: total
        show_state: false

The same value is displayed differently if it is w/o unit: изображение

My guess that it could be connected to using round(...) function in value_template.

Current settings: изображение

ildar170975 avatar Dec 25 '21 10:12 ildar170975

Not quite sure how to fix this, as the problem lies in HA's compute_state_display function which uses formatNumber on states that have a unit_of_measurement or state_class. Removing or having no unit prevents it from running the formatting.

Potential workaround while I figure this out:

  • unit: false if you dont want the value formatted
  • unit: ' ' if you need the formatting

benct avatar Dec 28 '21 14:12 benct

I think that unit: false is not the same as "no unit_of_measurement is specified": the 1st is a frontend setting (display the unit or not), the 2nd is a core system stuff. Probably this function should not depend on frontend setting...

ildar170975 avatar Dec 28 '21 14:12 ildar170975

2023.5.4, still same issue with a template sensor:

  • with UoM
  • when this UoM is not displayed (unit: false)
  • round(1) is used in a sensor.

image

ildar170975 avatar May 30 '23 22:05 ildar170975