We have several Sonos smart speakers around the house, and some are turned off at night via smart plugs to save power.
The downside of this is they forget the media such as local files or a remote radio station that they previously played and this needs to be selected via the Sonos app every day to resume playback.
The Sonos apps allow you to save favourite media sources and we can use these in Home Assistant to play your favourite stations with the " media_player.play_media” service using Home Assistant Automations.
Finding a suitable remote controller
As Home Assistant allows virtually any input to trigger an automation, we looked for a handheld button which communicates via Zigbee or Bluetooth to control a speaker’s functions.
We found a simple remote control from Ikea called STYRBAR which has four buttons, is powered by a pair of AAA batteries and only costs £12 in the UK.
The STYRBAR measures 72 mm x 72 mm x 18mm thick and has a metal mounting bracket for wall mounting with the button being held in place with magnets making it easy to remove.
Ikea sells a range of smart home devices that use their smart hub and they use Zigbee to communicate; many can be controlled using Home Assistant.
Paring with Zigbee2MQTT
We use Zigbee2MQTT and a Conbee II Zigbee stick for our smart home with Home Assistant and after using the “Permit Join(All)” button in Zigbee2MQTT we tried to pair the STYRBAR remote.
The instructions show pressing a pairing button under the battery cover for 10 seconds, but this did not put the controller into pairing mode.
After some research online I found a post saying you need to quickly press the button four times which then put it into pairing mode, and it was quickly detected in Zigbee2MQTT. I then renamed the button in Zigbee2MQTT and once this was saved, I opened Home Assistant to check the integration was working.
The MQTT devices show under Settings > Devices and Services > Integrations tab then MQTT which lists available devices.
Adding the Automation in Home Assistant
First, you must add your media or radio stations as a favourite in the Sonos App to be used by Home Assistant. Also, you must have a Sonos media player configured in Home Assistant.
Play Radio Station Automation
Under the Settings button, select Automations & Scenes, then + Create Automation.
This will start the Create Automation wizard.
- Select Create new automation, Start with an empty automation from scratch.
- Click Add Trigger
- Select Device
- Select the Ikea button device and set the trigger as “on” action.
- Click + Add Action
- Select “Play Media”
- Click the “Select media player” dropdown and choose your media player.
- Click the large plus icon and a modal will show options for Favourites, Music Library, Camera, DLNA Servers, My Media and Text-to-Speech.
- Click Favourites
- Click Radio
- Select the radio feed you wish to use.
- Click Save, enter a name for your automation such as “Ikeabutton-sonos-play” and click Save to confirm.
Your new automation will now be added to Home Assistant.
Stop Payback Radio Station Automation
Under the Settings button, select Automations & Scenes, then + Create Automation.
This will start the Create Automation wizard.
- Select Create new automation, Start with an empty automation from scratch.
- Click Add Trigger
- Select Device
- Select the ikea button device and set the trigger as an “off” action.
- Click + Add Action
- Select “Call a service”
- Select “Media Player: Stop” in the dropdown.
- Click the blue “+ Choose device” button and select your media player.
- Click Save, enter a name for your automation such as “Ikeabutton-sonos-stop” and click Save to confirm.
Your new automation will now be added to Home Assistant.
Volume Down Automation
Repeat the steps from the “Stop Payback Radio Station Automation” with the following changes:
Under Triggers, set the trigger as an "arrow_left_click" action.
Under Actions set the service as: “Media Player: Turn down volume”.
Volume Up Automation
Repeat the steps from the “Stop Payback Radio Station Automation” with the following changes:
Under Triggers, set the trigger as an "arrow_right_click" action.
Under Actions set the service as: “Media Player: Turn up volume”.
With the new automations added to Home Assistant, you can now use the Ikea STYRBAR buttons to control your Sonos speaker.
Comments