sensor:
  - platform: mqtt
    name: "Desk switch battery"
    state_topic: "z2m_deconz/desk_switch"
    availability_topic: "z2m_deconz/bridge/state"
    unit_of_measurement: "%"
    device_class: "battery"
    value_template: "{{ value_json.battery }}"
  - platform: mqtt
    name: "Desk switch LQI"
    state_topic: "z2m_deconz/desk_switch"
    availability_topic: "z2m_deconz/bridge/state"
    icon: "mdi:signal"
    unit_of_measurement: "lqi"
    value_template: "{{ value_json.linkquality }}"


automation:
  - alias: Living room · Desk switch
    use_blueprint:
      path: aqara_switch.yaml
      input:
        z2m_topic: "z2m_deconz/desk_switch"
        click:
          - service: light.toggle
            data_template:
              entity_id: light.living_room_main
              brightness_pct: >-

                {% if is_state('input_select.house_mode', 'night') %}
                  40
                {% else %}
                  100
                {% endif %}

        double_click:
          - service: light.toggle
            data_template:
              entity_id: light.living_room_ambient
              brightness_pct: >-

                {% if is_state('input_select.house_mode', 'night') %}
                  40
                {% else %}
                  100
                {% endif %}

        hold:
          - service: media_player.media_play_pause
            entity_id: media_player.living_room
