Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erkr/a437ebcb98a2b5ba2deebabd02f5ffae to your computer and use it in GitHub Desktop.
Save erkr/a437ebcb98a2b5ba2deebabd02f5ffae to your computer and use it in GitHub Desktop.
Home Assistant Blueprints: ZHA version for controlling media players with an Ikea Symfonisk
blueprint:
# Author Eric Kreuwels, Copyright 2022, publices under the free MIT license conditions
# This blueprint was inspired by:
# https://community.home-assistant.io/t/zha-ikea-symfonisk-sound-controller-for-media-the-spinny-one/266130
# This version requires to recreate your automations that are based on the version above (new options and therefor not compatible)
# Changes compared to the one that inspired me:
# moved from raw ZHA events to ZHA Symfonisk Device events (raw event attributes changed to often to keep it working)
# added configuration inputs for changing the volume delay and number of volume steps
# added option to either pause (default) or mute for single press action
# restricted the player selection to entities only
name: ZHA - IKEA Symfonisk sound controller for media
description: 'Control media with an IKEA Symfonisk sound controller (the spinny
ones).
Single press will either toggle Play/Pause(default) of Mute/Unmute on your selected media player.
You can set functions for double press and triple press.
Rotating left/right will change the volume smoothly of the selected media player,
if that function is possible. Both a delay between volume changes and the number of volume steps can be configured'
domain: automation
input:
remote:
name: Remote
description: IKEA Symfonisk controller to use
selector:
device:
integration: zha
manufacturer: IKEA of Sweden
model: SYMFONISK Sound Controller
media_player:
name: Media Player
description: Media player which will be controlled with this automation.
selector:
entity:
domain: media_player
multiple: false
volume_delay:
name: Volume stepping delay
description: The minimal delay in milliseconds between sending new volume adjustments.
default: 500
selector:
number:
min: 100
max: 1000
step: 100
unit_of_measurement: "msec"
mode: slider
volume_steps:
name: Volume number of steps
description: The number of steps for volume adjustments.
default: 10
selector:
number:
min: 5
max: 50
step: 5
unit_of_measurement: "Num"
mode: slider
single_press:
name: Single press
description: Pause(default) or Mute on single press
default: Pause
selector:
select:
options:
- Pause
- Mute
double_press:
name: Double press
description: Action to run on double press
default: []
selector:
action: {}
triple_press:
name: Triple press
description: Action to run on triple press
default: []
selector:
action: {}
mode: single
max_exceeded: silent
trigger:
- device_id: !input 'remote'
id: press_single
domain: zha
platform: device
type: remote_button_short_press
subtype: turn_on
- device_id: !input 'remote'
id: press_double
domain: zha
platform: device
type: remote_button_double_press
subtype: turn_on
- device_id: !input 'remote'
id: press_triple
domain: zha
platform: device
type: remote_button_triple_press
subtype: turn_on
- device_id: !input 'remote'
id: rotate_right
domain: zha
platform: device
type: device_rotated
subtype: right
- device_id: !input 'remote'
id: rotate_left
domain: zha
platform: device
type: device_rotated
subtype: left
action:
- variables:
steps: !input volume_steps
stepsize: '{{ 1.0 / steps }}'
player: !input 'media_player'
single_mode: !input 'single_press'
- choose:
- conditions:
- condition: trigger
id: press_single
- "{{ single_mode == 'Pause' }}"
sequence:
- service: media_player.media_play_pause
entity_id: !input 'media_player'
- delay: 0.5
- conditions:
- condition: trigger
id: press_single
- "{{ single_mode == 'Mute' }}"
- "{{ state_attr(player, 'is_volume_muted') is not none }}"
sequence:
- service: media_player.volume_mute
data:
is_volume_muted: "{{ state_attr(player, 'is_volume_muted') == false }}"
entity_id: !input 'media_player'
- delay: 0.5
- conditions:
- condition: trigger
id: press_double
sequence: !input 'double_press'
- conditions:
- condition: trigger
id: press_triple
sequence: !input 'triple_press'
- conditions:
- condition: trigger
id: rotate_right
- "{{ state_attr(player, 'volume_level') is not none }}"
sequence:
- service: media_player.volume_set
data:
volume_level: >-
{% set volume = state_attr(player, 'volume_level') + stepsize %}
{{ 1.0 if volume > 1.0 else volume }}
entity_id: !input 'media_player'
- delay:
milliseconds: !input 'volume_delay'
- conditions:
- condition: trigger
id: rotate_left
- "{{ state_attr(player, 'volume_level') is not none }}"
sequence:
- service: media_player.volume_set
data:
volume_level: >-
{% set volume = state_attr(player, 'volume_level') - stepsize %}
{{ 0.0 if volume < 0.0 else volume }}
entity_id: !input 'media_player'
- delay:
milliseconds: !input 'volume_delay'
@Mysli0210
Copy link

Hi Eric
I tried your blueprint, i however had 2 problems with it, one i needed single press to be configurable, as i use mopidy/mpd for playing music, but snapcast for streaming, hence i need to send play/pause to mpd, but volume control to the snapcast client i want to control.

Second i couldn't get it to actually send more than one volume set command, as zha (or the remote) only created an event when starting spinning.
So i made the automation restart and just loop the volume set until it stops turning (adding a stop trigger just to be sure)

The code could probably be optimized further, please take a look at my fork :)

@erkr
Copy link
Author

erkr commented Sep 14, 2022

hi @Mysli0210
First thanks for your feedback, appreciated!

Hi Eric I tried your blueprint, i however had 2 problems with it, one i needed single press to be configurable, as i use mopidy/mpd for playing music, but snapcast for streaming, hence i need to send play/pause to mpd, but volume control to the snapcast client i want to control.

Main goal for this blueprint is simplicity for the average user. But I have a similar player where volume and pause need to control a different device (amplifier). I solved that by using the universal mediaplayer template that allows to control multiple devices as one media player.

Second i couldn't get it to actually send more than one volume set command, as zha (or the remote) only created an event when starting spinning. So i made the automation restart and just loop the volume set until it stops turning (adding a stop trigger just to be sure)

The code could probably be optimized further, please take a look at my fork :)

That sounds interesting, will have a look later
Curious how you have done that.

@Mysli0210
Copy link

You're welcome, thanks for the blueprint!

Main goal for this blueprint is simplicity for the average user. But I have a similar player where volume and pause need to control a different device (amplifier). I solved that by using the universal mediaplayer template that allows to control multiple devices as one media player.

Ahh, that makes sense, gotta take a look at that template, but i think it may not be for me.

That sounds interesting, will have a look later
Curious how you have done that.

I'm, by no means an expert, especially when it comes to home assistant language, just cant wrap my head around it. C++ and Gcode are where my skills are at.
But basically ZHA for me at least only creates one event when i start turning (No clue if it detects how far it actually goes)
So i just make the automation restart when another trigger is met, thus breaking the loop that sets the volume.
I wanted to have a timer as a safeguard, so it cant get stuck if the automation would for any reason stay in the loop and causing it to infinitely turn up the volume.

@marcelK0
Copy link

Hi Eric,
thanks for this Blueprint, works much better for me than the original one in terms of controlling the volume.

One question, I'm trying to control the volume of a group of Sonos speakers at once. With the original blueprint that worked by just adding multiple entities. Also with your re-write of the original code you posted in the chat it seems to work.
However, your new submission here can only select a single entity. I tried the group add-on to group the Sonos speakers and use that group as the target entity, but then the volume control doesn't seem to work at all. Is there any other way to achieve this?
Thanks!

@erkr
Copy link
Author

erkr commented Nov 14, 2022

Maybe the universal media player template can be used. Prerequisite to use this blue print is that the volume_set command is supported by you players.
An example of configuring the command part of the universal template:

    commands:
      turn_on:
        service: media_player.turn_on
        data:
          entity_id: 
          - media_player.serre
          - media_player.woonkamer
          - media_player.keuken
      turn_off:
        service: media_player.turn_off
        data:
          entity_id: 
          - media_player.serre
          - media_player.woonkamer
          - media_player.keuken
      volume_up:
        service: media_player.volume_up
        data:
          entity_id: 
          - media_player.serre
          - media_player.woonkamer
          - media_player.keuken
      volume_down:
        service: media_player.volume_down
        data:
          entity_id: 
          - media_player.serre
          - media_player.woonkamer
          - media_player.keuken
      volume_set:
        service: media_player.volume_set
        data:
          entity_id: media_player.everywhere_57
          volume_level: '{{ volume_level }}'
      volume_mute:
        service: media_player.volume_mute
        data_template:
          entity_id: media_player.everywhere_57
          is_volume_muted: '{{ is_volume_muted }}'
    attributes:
      is_volume_muted: media_player.everywhere_57|is_volume_muted
      volume_level: media_player.everywhere_57|volume_level
    device_class: speaker
    unique_id: universal_everywhere 

I have chromecast devices, en the everywhere is the group of the one 3 devices

@broekhuijsen
Copy link

Hoi / hey Eric,

I recently discovered your great blueprint. It rendered one of my controlers from useless (too big increments) to almost perfect.

Would it be possible to add an extra option for press and hold? This way the controler would be even better.

I don't think this is possible, but would it be possible to change the behaviour when you turn the dial while it is being pressed?

For instance. If I turn the dial, the volume goes up and down, but when I press and turn the dial, it skips songs backwards and forwards.

I guess this is not possible but if it would, it would be fantastic. Because then I could use double and tripple press to start radio stations or so :D

@erkr
Copy link
Author

erkr commented May 24, 2023

@broekhuijsen
Nice to hear that the blueprint is useful for you. Very nice idea, but I’m limited by the events that the symfonisk produces. Things like Rotate while pressed is not available. You can easily check it yourself. Create an automation, choose device as trigger and select your symfonisk. Then you will see the really limited list of events.
Best Eric

@broekhuijsen
Copy link

Thanks for your response. This is just stupid, I didn't even think of trying that.

Well thanks for the great work you did on this :D

In this case I promote your blueprint to the PERFECT status :D

@erkr
Copy link
Author

erkr commented May 25, 2023

☺️

@bertybassett
Copy link

This worked a treat. Is there any way to have it self discovery in HA like other blueprint. Took me weeks before I stumbled upon your github page.

@erkr
Copy link
Author

erkr commented Nov 17, 2023

@bertybassett
Officially publishing blueprints is also a commitment for support I don't have time for. Gist is great way to share things, as they are.
I hope it fulfills your needs 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment