sensor:
  - platform: mqtt
    name: "Bedroom Opple action"
    state_topic: "z2m_deconz/opple_1"
    availability_topic: "z2m_deconz/bridge/state"
    icon: "mdi:gesture-double-tap"
    value_template: "{{ value_json.action }}"
  - platform: mqtt
    name: "Bedroom Opple battery"
    state_topic: "z2m_deconz/opple_1"
    availability_topic: "z2m_deconz/bridge/state"
    unit_of_measurement: "%"
    device_class: "battery"
    value_template: "{{ value_json.battery }}"
  - platform: mqtt
    name: "Bedroom Opple LQI"
    state_topic: "z2m_deconz/opple_1"
    availability_topic: "z2m_deconz/bridge/state"
    icon: "mdi:signal"
    unit_of_measurement: "lqi"
    value_template: "{{ value_json.linkquality }}"

automation:
  - alias: Bedroom · Opple
    use_blueprint:
      path: oppo_6_btn_switch.yaml
      input:
        opple_z2m_name: "z2m_deconz/opple_1"
        action_sensor: sensor.bedroom_opple_action

        button_1_single:
          - service: light.turn_off
            entity_id: light.master_bedroom

        button_2_single:
          - service: light.turn_on
            data_template:
              entity_id: light.master_bedroom
              brightness_pct: >-
                {% if not is_state('input_select.house_mode', 'day') %} 40 {% else %} 100 {% endif %}
          - service: script.bed_led_on
            data_template:
              brightness_pct: >-
                {% if not is_state('input_select.house_mode', 'day') %} 40 {% else %} 100 {% endif %}

        button_1_double:
          - service: light.turn_off
            entity_id: light.master_bedroom_main

        button_2_double:
          - service: light.turn_on
            data_template:
              entity_id: light.master_bedroom_main
              brightness_pct: >-

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

        button_1_triple:
          - service: light.turn_off
            entity_id:
              - light.bedside
              - light.bed_led

        button_2_triple:
          - service: light.turn_on
            data_template:
              entity_id:
                - light.bedside
              brightness_pct: >-

                {% if not is_state('input_select.house_mode', 'day') %}
                  40
                {% else %}
                  100
                {% endif %}
          - service: script.bed_led_on

        button_3_single:
          - service: media_player.media_play_pause
            entity_id: media_player.master_bedroom

        button_3_double:
          - service: script.sonos_join_tv

        button_3_triple:
          - service: script.sonos_join_bedroom

        button_3_release:
          - service: media_player.play_next
            entity_id: media_player.master_bedroom

        button_4_single:
          - service: script.music_play

        button_4_double:
          - service: script.music_play
            data:
              playlist: 'Starred'

        button_4_triple:
          - service: script.music_play
            data:
              playlist: 'Retro'

        button_5_single:
          - service: fan.turn_off
            entity_id: fan.philips_airpurifier

        button_6_single:
          - service: fan.turn_on
            entity_id: fan.philips_airpurifier
