artem-sedykh / mini-climate-card

Minimalistic climate card for Home Assistant Lovelace UI
MIT License
262 stars 19 forks source link

Battery display depending on charge #146

Closed a1ex-ak closed 4 months ago

a1ex-ak commented 4 months ago

Tell me how to do it correctly so that the correct state of the battery is displayed depending on the charge. This is how I feel now.

entities:
  - entity: climate.kitchen_chalet
    type: custom:mini-climate
    name: 'Кухня '
    icon: mdi:countertop
    swap_temperatures: true
    group: true
    secondary_info:
      type: hvac-action
      source:
        heating:
          icon: mdi:fire
          name: 'Обогрев '
        'off':
          icon: mdi:power
          name: 'Выключено '
        idle:
          icon: mdi:fire-off
          name: 'Бездействие '
    toggle:
      hide: true
    hvac_mode:
      style: >-
        (value, entity) => ({ color: value !== 'off' ? '#FFA500 !important' :
        '#808080' })
      source:
        heat:
          icon: mdi:thermometer
          name: 'режим: Обогрев '
        'off':
          icon: mdi:thermometer-low
          name: 'режим: Выключено '
      change_action: >
        (selected, entity) => this.call_service('climate', 'set_hvac_mode', {
        entity_id: entity.entity_id, hvac_mode: selected })
    indicators:
      humidity:
        icon:
          template: () => 'mdi:water-percent'
          style: |
            (value) => (value > 0 ? { color: '#2980b9'} : {})
        unit: '%'
        round: 1
        source:
          entity: sensor.sonoff_a480072e16_humidity
      power_consumption:
        icon:
          template: >
            (value) => (value > 90 ? 'mdi:battery' : {}),(value) => (value < 60
            ? 'mdi:battery-50' : 'mdi:battery'),(value) => (value < 74 ?
            'mdi:battery-60' : 'mdi:battery'),(value) => (value < 88 ?
            'mdi:battery-70' : 'mdi:battery')
          style: >
            (value) => (value > 90 ? { color: '#70a03c'} : {}),(value) => (value
            < 60 ? { color: '#b83829'} : { color: '#70a03c'}),(value) => (value
            < 74 ? { color: '#b58e31'} : { color: '#70a03c'}),(value) => (value
            < 88 ? { color: '#b58e31'} : { color: '#70a03c'})
        unit: '%'
        round: 1
        source:
          entity: sensor.sonoff_a480072e16_battery
regevbr commented 4 months ago

The functions you gave are not valid javascript. For icons:

(value) =>
  (value > 90 ? 'mdi:battery' : (value > 80 ? 'mdi:battery-80' : (value > 70 ? 'mdi:battery-70' : (value > 60 ? 'mdi:battery-60' : (value > 50 ? 'mdi:battery-50' : (value > 40 ? 'mdi:battery-40' : (value > 30 ? 'mdi:battery-30' :(value > 20 ? 'mdi:battery-20' : 'mdi:battery-10'))))))))

You can adpat the same for style by changing each icon name to { color: '#70a03c'}

a1ex-ak commented 4 months ago

Указанные вами функции не являются допустимым JavaScript. Для иконок:

(value) =>
  (value > 90 ? 'mdi:battery' : (value > 80 ? 'mdi:battery-80' : (value > 70 ? 'mdi:battery-70' : (value > 60 ? 'mdi:battery-60' : (value > 50 ? 'mdi:battery-50' : (value > 40 ? 'mdi:battery-40' : (value > 30 ? 'mdi:battery-30' :(value > 20 ? 'mdi:battery-20' : 'mdi:battery-10'))))))))

Вы можете применить то же самое к стилю, изменив имя каждого значка на { color: '#70a03c'}

thanks, I'll try