Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numbers are formatted not accordingly to global settings #220

Open
ildar170975 opened this issue Dec 23, 2021 · 9 comments
Open

Numbers are formatted not accordingly to global settings #220

ildar170975 opened this issue Dec 23, 2021 · 9 comments
Labels
bug Something isn't working

Comments

@ildar170975
Copy link

ildar170975 commented Dec 23, 2021

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

@bcutter
Copy link

bcutter commented Dec 23, 2021

See #212 (comment) and following. Might be related to the same root cause.

Introduced with v4.3.0 I think.

@benct benct added the bug Something isn't working label Dec 23, 2021
@benct
Copy link
Owner

benct commented Dec 23, 2021

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

@ildar170975
Copy link
Author

Anything else?

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

@ildar170975
Copy link
Author

ildar170975 commented Dec 23, 2021

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

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

@bcutter
Copy link

bcutter commented Dec 24, 2021

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
Copy link
Author

ildar170975 commented Dec 25, 2021

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

@benct
Copy link
Owner

benct commented Dec 28, 2021

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 benct reopened this Dec 28, 2021
@ildar170975
Copy link
Author

ildar170975 commented Dec 28, 2021

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants