benct / lovelace-xiaomi-vacuum-card

Simple card for various robot vacuums in Home Assistant's Lovelace UI
MIT License
264 stars 37 forks source link

Support binary sensors #89

Open TTLucian opened 3 years ago

TTLucian commented 3 years ago

Certain attributes show as unavailable on the card. The sensors are enabled and working. mop_attached water_box_attached I think this happens because they are binary_sensors and currently the card only reads "sensor" values, but not "binary_sensor" values.

dizzad commented 3 years ago

Same for me Update to 4.4.0 right now image

benct commented 3 years ago

Have look at #84, things changed in 2021.11.0. The binary sensors are not supported as of now, I'll see if I can do something about that soon.

If the card still does not work, try this.

TTLucian commented 3 years ago

Thanks. I've seen #84. Card works for ok "sensor" state but not for "binary_sensor" state (like mop_attached and water_box_attached). As a workaround, template sensors can be manually created with binary_sensor state, like so:

template:
  - sensor:
      name: Robot Mop Attached
      unique_id: sensor.robot_mop_attached
      state: >
        {% if is_state('binary_sensor.robot_mop_attached', 'off') %}
        No
        {% elif is_state('binary_sensor.robot_mop_attached', 'on') %}
        Yes
        {% endif %}
      availability: >
        {% if is_state('vacuum.robot', 'unavailable') %}
          false
        {% else %}
          true
        {% endif %}
      icon: >
        {% if is_state('binary_sensor.robot_water_box_attached', 'on') %}
          mdi:square
        {% else %}
          mdi:square-off
        {% endif %}

  - sensor:
      name: Robot Water Box Attached
      unique_id: sensor.robot_water_box_attached
      state: >
        {% if is_state('binary_sensor.robot_water_box_attached', 'off') %}
        No
        {% elif is_state('binary_sensor.robot_water_box_attached', 'on') %}
        Yes
        {% endif %}
      availability: >
        {% if is_state('vacuum.robot', 'unavailable') %}
          false
        {% else %}
          true
        {% endif %}
      icon: >
        {% if is_state('binary_sensor.robot_water_box_attached', 'on') %}
          mdi:water
        {% else %}
          mdi:water-off
        {% endif %}
  - type: custom:xiaomi-vacuum-card
    entity: vacuum.robot
    name: Robot
    vendor: xiaomi
    image: /local/community/lovelace-xiaomi-vacuum-card/vacuum.png
    attributes:
      main_brush:
        key: main_brush_left
      side_brush:
        key: side_brush_left
      filter:
        key: filter_left
      sensor:
        key: sensor_dirty_left
      mop_attached:
        label: 'Mop attached: '
        key: mop_attached
      water_box_attached:
        label: 'Water box attached: '
        key: water_box_attached

Result: Untitled