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

room_card separate temperature entity #656

Closed
jarrah31 opened this issue May 11, 2022 · 2 comments
Closed

room_card separate temperature entity #656

jarrah31 opened this issue May 11, 2022 · 2 comments

Comments

@jarrah31
Copy link

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

lk-dll commented Aug 7, 2023

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}%`; 
          ]]]

@wilbiev
Copy link
Collaborator

wilbiev commented Dec 14, 2024

Cleaning up issue list

@wilbiev wilbiev closed this as completed Dec 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants