ZHA - REMOTE: Tradfri Wireless Dimmer (ICTC-G-1) for media player control

REMOTE Tradfri Wireless Dimmer (ICTC-G-1) for media player control

Blueprint to support the IKEA Tradfri Wireless Dimmer (ICTC-G-1) and allow it to control a media player device.

The following features are implemented:

  • rotation right/left and player is playing: media_player.volume_set up/down (to configured max/min volume)
  • rotation right and player is paused: media_player.media_play
  • rotation right with stop and player is playing: media_player.media_next_track
  • rotation left with stop and player is playing: media_player.media_play_pause

IMPORT

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

BLUEPRINT

blueprint:
  name: 'REMOTE: Tradfri Wireless Dimmer for media player'
  description: |
    Control media player with IKEA ICTC-G-1 Tradfri Wireless Dimmer
    Usage:
    rotation right/left and music is playing: media_player.volume_set up/down to configured max/min volume
    rotation right and music is paused: media_player.media_play
    rotation right with stop and music is playing: media_player.media_next_track
    rotation left with stop and music is playing: media_player.media_play_pause
  domain: automation
  input:
    remote:
      name: Tradfri Wireless Dimmer
      description: 'ZHA: Tradfri Wireless Dimmer to use (IKEA ICTC-G-1)'
      selector:
        device:
          integration: zha
          manufacturer: IKEA of Sweden
          model: TRADFRI wireless dimmer
          multiple: false
    media_player:
      name: Media player
      description: Media player to control with Tradfri Wireless Dimmer
      selector:
        entity:
          domain: media_player
          multiple: false
    volume_min:
      name: Min volume
      description: Minimum volume of media player.
      default: 0.1
      selector:
        number:
          min: 0.0
          max: 0.2
          unit_of_measurement: '%'
          step: 0.05
          mode: slider
    volume_max:
      name: Max volume
      description: Maximum volume of media player.
      default: 0.8
      selector:
        number:
          min: 0.2
          max: 1.0
          step: 0.05
          unit_of_measurement: '%'
          mode: slider
mode: restart
max_exceeded: silent
variables:
  MEDIA_PLAYER:
    entity_id: !input media_player
    volume_min: !input volume_min
    volume_max: !input volume_max
trigger:
  - platform: event
    event_type: zha_event
    event_data:
      device_id: !input remote
action:
  - choose:
      - alias: Fast rotation right with stop - next track
        conditions:
          - '{{ trigger.event.data.command == ''move_to_level_with_on_off'' }}'
          - '{{ trigger.event.data.params.level == 255 }}'
          - '{{ is_state(MEDIA_PLAYER.entity_id, ''playing'') }}'
        sequence:
          - service: media_player.media_next_track
            target:
              entity_id: '{{ MEDIA_PLAYER.entity_id }}'
      - alias: Fast rotation right with stop - play
        conditions:
          - '{{ trigger.event.data.command == ''move_to_level_with_on_off'' }}'
          - '{{ trigger.event.data.params.level == 255 }}'
          - '{{ is_state(MEDIA_PLAYER.entity_id, ''paused'') }}'
        sequence:
          - service: media_player.media_play
            target:
              entity_id: '{{ MEDIA_PLAYER.entity_id }}'
      - alias: Rotation right - play
        conditions:
          - '{{ trigger.event.data.command == ''move_with_on_off'' }}'
          - '{{ is_state(MEDIA_PLAYER.entity_id, ''paused'') }}'
        sequence:
          - service: media_player.media_play
            target:
              entity_id: '{{ MEDIA_PLAYER.entity_id }}'
      - alias: Rotation right - volume up
        conditions:
          - '{{ trigger.event.data.command == ''move_with_on_off'' }}'
          - '{{ is_state(MEDIA_PLAYER.entity_id, ''playing'') }}'
        sequence:
          - repeat:
              while: '{{ state_attr(MEDIA_PLAYER.entity_id, ''volume_level'') | float < MEDIA_PLAYER.volume_max and repeat.index < 8 }}'
              sequence:
              - service: media_player.volume_set
                target:
                  entity_id: '{{ MEDIA_PLAYER.entity_id }}'
                data:
                  volume_level: '{{ [(state_attr(MEDIA_PLAYER.entity_id, ''volume_level'') | float + trigger.event.data.params.rate | float / 4500), MEDIA_PLAYER.volume_max] | min }}'
              - delay:
                  milliseconds: 450
      - alias: Rotation left - volume down
        conditions:
          - '{{ trigger.event.data.command == ''move'' }}'
          - '{{ is_state(MEDIA_PLAYER.entity_id, ''playing'') }}'
        sequence:
          - repeat:
              while: '{{ state_attr(MEDIA_PLAYER.entity_id, ''volume_level'') | float > MEDIA_PLAYER.volume_min and repeat.index < 8 }}'
              sequence:
              - service: media_player.volume_set
                target:
                  entity_id: '{{ MEDIA_PLAYER.entity_id }}'
                data:
                  volume_level: '{{ [(state_attr(MEDIA_PLAYER.entity_id, ''volume_level'') | float - trigger.event.data.params.rate | float / 4500), MEDIA_PLAYER.volume_min] | max }}'
              - delay:
                  milliseconds: 450
      - alias: Fast rotation left with stop - pause
        conditions:
          - '{{ trigger.event.data.command == ''move_to_level_with_on_off'' }}'
          - '{{ trigger.event.data.params.level == 0 }}'
          - '{{ is_state(MEDIA_PLAYER.entity_id, ''playing'') }}'
        sequence:
          - service: media_player.media_play_pause
            target:
              entity_id: '{{ MEDIA_PLAYER.entity_id }}'
    default: []