Lovelace: Button card

Dear all,

I’ve been breaking my head now for a while without success, and so I reach out. I don’t have power information for all ACs. In the case I leave it blanc, the card doesn’t show which obviously not the desired effect.

If some code can be improved, please don’t hesitate.

button_card_templates:
  AC_template:
    triggers_update:
      - sun.sun
    icon: "mdi:fan"
    variables:
      sensor_humidity: " "
      sensor_power: " "
      AC_entity: " "
    state:
      - value: "off"
        color: rgba(0,0,0,0)
      - value: "cool"
        color: deepskyblue
        spin: true
      - value: "heat"
        color: rgba(255,0,0,0.6)
        spin: true
      - value: "heat_cool"
        color: orange
        spin: true
    styles:
      card:
        - width: 110px
        - height: 110px
        - margin: 3px
        - padding: 3px
        - border-radius: 15px
        - background-color: var(--primary-background-color)
        - box-shadow: >
            [[[
              if (states['sun.sun'].state == "below_horizon")
                return '-5px -5px 15px #2c2c2c, 5px 5px 15px #191919';
              else if (states['sun.sun'].state == "above_horizon")
                return '-5px -5px 15px #ffffff, 5px 5px 15px #ebebeb';
            ]]]
      grid:
        - grid-template-areas: '"i i temp" "i i humidity" "i i power" " set set mode" "n n n"'
        - grid-template-columns: 1fr 1fr 1fr
        - grid-template-rows: 1fr 1fr 1fr 3fr 2fr
      name:
        - font-weight: bold
        - font-size: 13px
        - color: var(--primary-text-color)
        - align-self: middle
        - justify-self: left
      img_cell:
        - justify-content: start
        - align-items: start
        - margin-top: -5px 
      icon:
        - width: 70%
      custom_fields:
        temp:
          - align-self: start
          - justify-self: end
          - font-size: 10px
        humidity:
          - margin-top: 10px
          - align-self: middle
          - justify-self: end
          - font-size: 10px
        power:
          - margin-top: 15px
          - align-self: middle
          - justify-self: end
          - font-size: 10px
        set:
          - margin-top: 15px
          - align-self: middle
          - justify-self: end
          - font-size: 30px
        mode:
          - justify-content: end
          - align-items: end
          - font-size: 30px

    custom_fields:
      temp: >
        [[[
          return `<ha-icon
            icon= "mdi:thermometer"
            style="width: 14px; height: 14px; color: green;">
            </ha-icon><span> <span>${entity.attributes.current_temperature}°C</span></span>`
        ]]]
      humidity: >
        [[[
          return `<ha-icon
            icon= "mdi:water-percent"
            style="width: 18px; height: 18px; color: deepskyblue;">
            </ha-icon><span><span>${states[variables.sensor_humidity].state}%</span></span>`
        ]]]
      power: >
        [[[
          return `<ha-icon
            icon= "mdi:power-plug"
            style="width: 18px; height: 18px; color: red;">
            </ha-icon><span><span>${states[variables.sensor_power].state}kWh</span></span>`
        ]]]
      set: >
        [[[
          return `
            </ha-icon><span><span>${entity.attributes.temperature}°</span></span>`
        ]]]
      mode: >
        [[[
          if (entity.state =="cool")
            return `<ha-icon
              icon= "mdi:snowflake"
              style="width: 25px; height: 18px; color: rgba(0,0,255,0.6);">
              </ha-icon>`
          else if (entity.state =="heat")
            return `<ha-icon
              icon= "mdi:fire"
              style="width: 25px; height: 18px; color: rgba(255,0,0,0.6);">
              </ha-icon>`
        ]]]

image
Regards,
Jens

1 Like