benct / lovelace-multiple-entity-row

Show multiple entity states and attributes on entity rows in Home Assistant's Lovelace UI
MIT License
804 stars 61 forks source link

Numbers are formatted not accordingly to global settings #220

Open ildar170975 opened 2 years ago

ildar170975 commented 2 years ago

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

This card contains:

Note that:

изображение

  - 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: изображение

bcutter commented 2 years ago

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.

benct commented 2 years ago

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

ildar170975 commented 2 years ago

Anything else?

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

ildar170975 commented 2 years ago

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

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

bcutter commented 2 years ago

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.

ildar170975 commented 2 years ago

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

There are 2 sensors from systemmonitor:

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: изображение

benct commented 2 years ago

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:

ildar170975 commented 2 years ago

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 commented 1 year ago

2023.5.4, still same issue with a template sensor:

image

bcutter commented 2 months ago

Wow, it's been only 3 years. Let's wait another 3 to fix this. Maybe.

bcutter commented 2 months ago

Bump