marcokreeft87 / room-card

Show multiple entity states, attributes and icons in a single card in Home Assistant's Lovelace UI
MIT License
228 stars 38 forks source link

State ignores sensor‘s device_class #337

Closed snowy-18 closed 5 months ago

snowy-18 commented 5 months ago

Which version of Room Card? 1.08.04 but has always been like this

Describe the bug The device_class of a sensor is being ignored when showing the state of a sensor on the room card. In my example, a binary flood sensor has the state "dry" in the general Home Assistant UI, but on the Room Card it is shown as "off". That's technically correct, but ignored the global settings applied to the entity.

To Reproduce Take any sensor and modify its device_class in the entity's customize section: https://www.home-assistant.io/integrations/sensor/

Expected behavior The state shown on the room card should be the same as in the entity's settings.

Screenshots

image

Desktop (please complete the following information): Mac, Windows, Web

Smartphone (please complete the following information): iOS

Additional context Maybe related to #249? The state on the room card remains "off", even if I change the UI to another language than English.

YAML

type: custom:room-card
title: Waschküche
icon: mdi:washing-machine
show_icon: true
state_color: true
entity: sensor.waschkuche_waschmaschine_power
info_entities:
  - entity: sensor.waschkuche_wassersensor_temperature
    format: precision1
rows:
  - entities:
      - entity: sensor.washing_machine_current_state_translated
        name: Waschmaschine
        show_state: true
      - entity: sensor.dryer_current_state_translated
        name: Trockner
        show_state: true
      - entity: binary_sensor.waschkuche_wassersensor_flood
        name: Wasser
        show_state: true
marcokreeft87 commented 5 months ago

What is the state in the developer tools of HA?

snowy-18 commented 5 months ago

image

The state is "off", as displayed on the room card. According to the HA documentation, the Device Class influences how the entity is represented in the dashboard.

marcokreeft87 commented 5 months ago

Thats excepted behavior. You need to pass which attribute you want to show if you dont want to see the state there

``attribute: ``` in config

snowy-18 commented 5 months ago

Thanks for your help. Btw, great card!! Really the only one that I'm using on my main dashboard and probably the main reason why the whole family startet using HA 👍

So I tried adding: attribute: device_class

As I'd expect, then the label reads "moisture", and not "dry": image

I feel like I'm not getting how to use the attribute here?

In a normal entity card, the state is "dry" and not "off", just as it is configured in the entity's settings: image

marcokreeft87 commented 5 months ago

You need to use the flood entity apparently. State should give the wanted result with that entity

Take a look at the entities in developer tools. There you can see all the attributes

snowy-18 commented 5 months ago

Gave this another try on a fresh dashboard, where I added the same entity on different cards. The stock HA Entity, Entities and Glance cards, as well as custom Room, Bubble and Mushroom cards.

  - title: Test
    path: test
    cards:
      - type: custom:room-card
        title: Room-card
        rows:
          - entities:
              - entity: binary_sensor.waschkuche_wassersensor_flood
                show_state: true
      - type: entity
        entity: binary_sensor.waschkuche_wassersensor_flood
      - type: entities
        entities:
          - entity: binary_sensor.waschkuche_wassersensor_flood
      - type: glance
        show_name: true
        show_icon: true
        show_state: true
        entities:
          - entity: binary_sensor.waschkuche_wassersensor_flood
      - type: custom:mushroom-entity-card
        entity: binary_sensor.waschkuche_wassersensor_flood
      - type: custom:bubble-card
        card_type: button
        button_type: state
        entity: binary_sensor.waschkuche_wassersensor_flood

The room-card is the only one which displays the state as off instead of dry: image

Here are the entity's state and attributes in the developer tools: image

So yes, technically the state is off and not dry, but the entity is configured as the device_class: moisture / Show as: Moisture. image

If I change the device_class to anything else, e.g. Show as: Smoke, all cards on the dashboard above will show the state as Clear, or Show as: Safety, all cards on the dashboard above will show the state as Save ... ... but the Room-card will remain as Off.

I might be wrong but don't think this is an issue with the attribute of the entity, rather how the Room-card handles the device_class. Thoughts?

marcokreeft87 commented 5 months ago

I don't know how to explain haha. But you are doing it wrong xD