UI-Lovelace-Minimalist / UI

UI-Lovelace-Minimalist is a "theme" for HomeAssistant
https://ui-lovelace-minimalist.github.io/UI/
Other
1.63k stars 430 forks source link

room_card separate temperature entity #656

Open jarrah31 opened 2 years ago

jarrah31 commented 2 years ago

Is your enhancement request related to a problem? Please describe. I have a general room status group that I assign as the main entity for the room_card so that the button is red if something is left on, or green if all is ok. This group entity isn't compatible with either label_use_temperature or label_use_brightness variables, so I would like to specify another entity to display the room temperature in the label field when the main entity doesn't contain any temperature attributes.

Describe the solution you'd like I propose the ability to specify a different entity variable to display the temperature in the label field. I have worked out the following code to do this: (label field from card_room.yaml)

  label: |-
      [[[
        if (variables.label_use_temperature) {
          if (variables.label_temperature_entity != null){
            var temp = Math.round(states[variables.label_temperature_entity].state);
            return temp + '°C';
          } else {
            return (entity.attributes.current_temperature || entity.attributes.temperature || entity.state || '-') + (entity.attributes.unit_of_measurement || '°C');
          }
        } else if (variables.label_use_brightness) {
          if (entity.state){
            if (entity.state == "off"){
              return variables.ulm_off;
            } else if (entity.state == "on"){
              if (entity.attributes.brightness != null){
                var bri = Math.round(entity.attributes.brightness / 2.55);
                return (bri ? bri : "0") + "%";
              } else {
                return variables.ulm_on
              }
            }
          } else {
            return variables.ulm_unavailable;
          }
        } else if (entity.state == "on") {
            return variables.ulm_on
        } else if (entity.state == "off") {
            return variables.ulm_off
        } else {
          return entity.state
        }
      ]]]

Specifying the variable in the card:

      - type: 'custom:button-card'
        template:
          - card_room
          - red_on
          - green_off
        name: Kitchen
        entity: group.rm_status_kitchen
        icon: mdi:countertop
        tap_action:
          action: navigate
          navigation_path: '/ui-lovelace-minimalist/kitchen'
        variables:
          label_use_temperature: true
          label_use_brightness: false
          label_temperature_entity: sensor.climate_kitchen_temperature
          entity_1:
            entity_id: group.lights_kitchen
            templates:
              - yellow_on
            tap_action:
              action: toggle
image
lk-dll commented 1 year ago

I'm using this in label for showing temperature and humidity

label: >
          [[[ 
            const temperature = Math.round(states['sensor.multisensor_temperature'].state * 10) / 10;
            const humidity = Math.round(states['sensor.multisensor_humidity'].state);

            return `🌡️${temperature}°C 💧${humidity}%`; 
          ]]]