andyblac / UI-Minimalist-Custom-Cards

A modified version of Minimalist Room Card.
59 stars 3 forks source link

The humidity entity status is bad in room card #27

Open bimbopp opened 2 weeks ago

bimbopp commented 2 weeks ago

hello I use your custom room card. I noticed that the state of the humidity thermometers entity was incorrectly displaying humidity. This only happens with zigbee thermometers. Entity status is OK in HA. In Z2M, the condition is also ok. Only on the dashboard it is incorrect. Snímek obrazovky 2024-10-07 160550

andyblac commented 2 weeks ago

hi, lets try to investigate this, it can only show the state of what HA has stored, can you go to Developer Tools -> States, find your entity and click on it, what does the state display ?

This is my Aqara Humidity Sensor, it is reporting the correct value.

Screenshot 2024-10-07 at 15 22 33 Screenshot 2024-10-07 at 15 24 02
bimbopp commented 2 weeks ago

Snímek obrazovky 2024-10-07 164017

andyblac commented 2 weeks ago

it looks like it is detecting the temperature attribute from the sensor. can you post your room code please.

also what device is it?, as it does not seem to have a device_class or unit_of_measurement

bimbopp commented 2 weeks ago

Temperature value is correct. Code :

type: "custom:button-card"
template:
  - custom_card_andyblac_room
name: Pokojík
icon: mdi:chair-rolling
tap_action:
  action: call-service
  service: "input_select.select_option"
  service_data:
    option: "study"
    entity_id: "input_select.minimalist_ui_switch"
variables:
  ulm_custom_card_andyblac_room_use_label_icons: true
  ulm_custom_card_andyblac_room_color: red
  ulm_custom_card_andyblac_room_use_small_room_icon: true
  sensor_label_1: sensor.mi_teplomer_3_temperature
  sensor_label_2: sensor.mi_teplomer_3_humidity

Device: https://www.zigbee2mqtt.io/devices/LYWSD03MMC.html

andyblac commented 2 weeks ago

hmm, strange can you add the code to your room car, as a test

    label: > 
      [[[
        var entity = 'sensor.mi_teplomer_3_humidity'
        var entity_state = helpers.localize(states[entity], states[entity].state);
        return entity_state;
      ]]]

then refresh the dashboard, using the 3 dots in top right of screen.

bimbopp commented 2 weeks ago

Yes correct view Snímek obrazovky 2024-10-07 172206

andyblac commented 2 weeks ago

thats strange the card is using the same code.

here's a copy of the latest dev, just incase. custom_card_andyblac_room.yaml.zip

andyblac commented 2 weeks ago

can you also try with just using sensor_label_1, to see if it does the same. i.e sensor_label_1: sensor.mi_teplomer_3_humidity

bimbopp commented 2 weeks ago

Thank you for your interest and patience. Unfortunately, even with the latest dev when consuming sensor_label_1 does not have the correct value according to the entity in the developer tool states. It is interesting that it is only a device equipped with zigbee. WiFi devices display the correct value.

andyblac commented 2 weeks ago

are you using ZHA or Z2M, I'm using Z2M with no issues here.

bimbopp commented 2 weeks ago

I use Z2M. I still have these zigbee thermometers: https://www.zigbee2mqtt.io/devices/WSD500A.html with the same behavior.

andyblac commented 2 weeks ago

is this the sensor https://www.amazon.co.uk/dp/B09QMDZLF5?_encoding=UTF8&psc=1&linkCode=sl1&tag=smarthomescen-20&linkId=8cf5a0406193c5bbcfe0fe87dabd6ce6&language=en_GB&ref_=as_li_ss_tl ? if so I'll purchase one and see if I can reproduce the bug.

bimbopp commented 1 week ago

It is this device: https://www.aliexpress.com/item/1005005601289812.html?spm=a2g0o.order_list.order_list_main.216.2cd31802uS6jjz zigbee variant

bimbopp commented 1 week ago

I tried creating a new sensor with device sensor status. When using the new sensor, the display is correct.

bimbopp commented 1 week ago

One more note. In devices where there is temperature in the attributes, temperature will be displayed instead of humidity. In devices where there is neither temperature nor humidity in the attributes, humidity will be displayed. It would probably like the value of the humidity attribute to be in the entity_state variable.

andyblac commented 1 week ago

this is the code

  label: |-
    [[[
      var spacer = " | ";
      function getState(entity) {
        var entity_type = "";
        var entity_state = "";
        if (variables.andyblac_card_room_use_label_icons) {
          var entity_type = "| ";
          var spacer = " ";
          if (states[entity].attributes?.device_class == 'temperature') {
            var entity_type = "🌡️";
          } else if (states[entity].attributes?.device_class == 'humidity') {
            var entity_type = "💧";
          } else if (states[entity].attributes?.device_class == 'illuminance') {
            var entity_type = "🔆";
          }
        }
        if (states[entity].attributes?.brightness) {
          var bri = Math.round(states[entity].attributes?.brightness / 2.55);
          var entity_type = "💡";
          var entity_state = (bri ? bri : "0") + "%";
        } else if (states[entity].state) {
          var entity_state = helpers.localize(states[entity], states[entity].state);
        } 
        return entity_type + entity_state;
      }

      if (variables.sensor_label_1 && variables.sensor_label_2 && variables.sensor_label_3) {
        return getState(variables.sensor_label_1) + spacer + getState(variables.sensor_label_2) + spacer + getState(variables.sensor_label_3);
      } else if (variables.sensor_label_1 && variables.sensor_label_2) {
        return getState(variables.sensor_label_1) + spacer + getState(variables.sensor_label_2);
      } else if (variables.sensor_label_1 && variables.sensor_label_3) {
        return getState(variables.sensor_label_1) + spacer + getState(variables.sensor_label_3);
      } else if (variables.sensor_label_2 && variables.sensor_label_3) {
        return getState(variables.sensor_label_2) + spacer + getState(variables.sensor_label_3);
      } else if (variables.sensor_label_1) {
        return getState(variables.sensor_label_1);
      } else if (variables.sensor_label_2) {
        return getState(variables.sensor_label_2);
      } else if (variables.sensor_label_3) {
        return getState(variables.sensor_label_3);
      } else if (entity?.entity_id) {
        return getState(entity.entity_id);
      }
      return variables.ulm_translation_state;
    ]]]
bimbopp commented 1 week ago

Yes, but for some unknown reason the value of the temperature attribute is in entity_state and not the value of the entity state.