Sonos coordinator widget

Hello Openhab community,
today i’d like to share with you my sonos controller widget which, in combination with my Zero configuration sonos-coordinator rule , is capable of controlling your sonos system without the need for any configurations. Just copy the rule in the ./automation/js folder, place the widget onto your desired page and start controlling your sonos system.
The source code for the widget and for the rule can also be found on github: sonos-coordinator

Requirements:

  • At least OpenHAB 3.2 or higher
  • OpenHAB Sonos binding
  • The JSScripting plugin needs to be installed

Features

  • Automatically display all Zone Players within an oh-swiper card.
  • Control the volume of the zone as well as the individual volume of all grouped players within the zone.
  • Control the mute state of the zone as well as the individual mute state of all grouped players within the zone.
  • Add or remove players from/to the the current zone player
  • Control the state of the zone player (Play/Pause/Next/Previouse)
  • Display the cover art of the currently played track of the zone player
  • Display title, artist and album information of the currently played track of the zone player
  • If the title or artist information is lacking (e.g. when listening to a radio station), the widget tries to parse the information from the track item
    (although not 100% reliable, this works for the german radio stations i am listening to).
  • Change the caption for title, artist, album, volume configuration and group configuration (for internationalization) in the configuration of the widget (default is english)
  • Responsive design of the widget (works well on tablets, mobile phones and desktop browsers)
  • Display and select the favorites defined in the sonos app

Changelog

Version 0.1

  • initial release

Version 0.1.1

  • replaced hardcoded vinyl url with embedded image

Version 0.1.2

  • added favorites button to widget

Resources

https://raw.githubusercontent.com/sichelz1/sonos-coordinator/master/sonos_coordinator_widget.yaml

4 Likes

hello maybe a feature request ?? what would complete this widget is a sonos favorite list button to choose from and also the automatic creation of the proxy item for the favorite channel. Otherwise great work very nicely done.

To be honest, i never was aware of this Sonos feature since your post. But it sounds like a nice addon. I’ll try to add it to the widget next week (i already figured out, how to enumerate the favorites in openhab but honestly, i haven’t really understood how to add those favorites in the sonos app)

Great news. a little googling around found this on sonos website.
https://support.sonos.com/s/article/3547?language=en_US
Its very easy once you have all your favorites its much convenient to do it this way plus the favorite item can be used in automations to start something automagically :slight_smile:

I have added your feature request for a favorites button. The latest widget is able to display and select the favorites defined in the sonos app

1 Like

Hi. Thank you very much for this great looking widget. I tried to copy the sonos_coordinator_rule.js in the conf/automation/js folder. I’m using a MacBook and I tried id to open this folder in Finder with my openhabian-password. Unfortunately the permission to write in the folder is not given. How can I copy the .js-file in the folder? I have to say that I am a newby in using a Pi…

I assume that you are using openhabian on the Pi. The reason why you can’t copy the rule is that you are lacking permissions on the folder (this is default on linux). Login to the pi via ssh. In the commandline, navigate to the conf/automation/js folder via the “cd” command. The easiest thing now is to use the command “sudo chmod 777” (this will grant everyone full access to the folder). As you are using the command “sudo”, the commandline will prompt you for your admin password.
After this, you should be able to copy the file.

1 Like

Thank you very much! Now it works… Great widget!

HI @sichelz
I have slightly the same issue as @fabianschoeni but to behonest - and I feel quit stupid - but I do not find the folder :face_with_peeking_eye: to place the skript.

Same as before. Openhab is running as Openhabian on my Pi.

Best Regards
björn

Hi Björn

I used Terminal from my MacBook and logged into openhabian with ssh (ssh openhabian@IP-ADDRESS. Then I had to go to the main-folder with the command "cd … " twice. The folder is then in “srv” (cd srv) → cd openhab-conf → cd automation. Then I had to write “sudo chmod -R 777 /js”. Then it worked…

Best regards, Fabian

Hi @fabianschoeni
thanks, that helped

Best Regards

Good Day,

I would appreciate a little guidance if possible. I have just rebuilt my Openhab system and now using veersion 3. I have installed the coordinator widget and rule using the guidelines, but my speakers (groups) are showing up as undefined except for one. I have included a screen shot. Have a missed something in the setup.

Cheers

Stuart

do you have a description of the item ?

Hi @sichelz,

today I wanted to install your very nice looking widget. Unfortunately I get an error message in the logs and can not get the widget to run …

2023-01-07 22:29:56.573 [INFO ] [rulesupport.loader.ScriptFileWatcher] - Loading script ‘/openhab/conf/automation/js/sonos_coordinator_rule.js’
2023-01-07 22:29:57.533 [INFO ] [org.openhab.automation.script ] - Sonos coordinator rule load
2023-01-07 22:29:57.547 [ERROR] [b.automation.script.javascript.stack] - Failed to execute script:
org.graalvm.polyglot.PolyglotException: TypeError: s.replace is not a function
at .safeItemName(webpack://openhab/./node_modules/openhab/items/managed.js?:443) ~[?:?]
at .createItem(webpack://openhab/./node_modules/openhab/items/managed.js?:264) ~[?:?]
at .addItem(webpack://openhab/./node_modules/openhab/items/managed.js?:325) ~[?:?]
at .addItem(sonos_coordinator_rule.js:73) ~[?:?]
at .SonosCoordinator(sonos_coordinator_rule.js:90) ~[?:?]
at .scriptLoaded(sonos_coordinator_rule.js:530) ~[?:?]
at org.graalvm.polyglot.Value.execute(Value.java:841) ~[?:?]
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.invokeFunction(GraalJSScriptEngine.java:556) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.invokeFunction(DelegatingScriptEngineWithInvocable.java:116) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.invokeFunction(InvocationInterceptingScriptEngineWithInvocable.java:119) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.DelegatingScriptEngineWithInvocable.invokeFunction(DelegatingScriptEngineWithInvocable.java:116) ~[?:?]
at org.openhab.automation.jsscripting.internal.scriptengine.InvocationInterceptingScriptEngineWithInvocable.invokeFunction(InvocationInterceptingScriptEngineWithInvocable.java:119) ~[?:?]
at org.openhab.core.automation.module.script.internal.ScriptEngineManagerImpl.loadScript(ScriptEngineManagerImpl.java:181) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.createAndLoad(ScriptFileWatcher.java:231) ~[?:?]
at org.openhab.automation.jsscripting.internal.fs.watch.JSScriptFileWatcher.createAndLoad(JSScriptFileWatcher.java:57) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.importFile(ScriptFileWatcher.java:211) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.lambda$2(ScriptFileWatcher.java:203) ~[?:?]
at java.util.Optional.ifPresent(Optional.java:183) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.importFileWhenReady(ScriptFileWatcher.java:201) ~[?:?]
at org.openhab.core.automation.module.script.rulesupport.loader.ScriptFileWatcher.processWatchEvent(ScriptFileWatcher.java:178) ~[?:?]
at org.openhab.core.service.WatchQueueReader.lambda$3(WatchQueueReader.java:323) ~[?:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
at java.lang.Thread.run(Thread.java:829) [?:?]
2023-01-07 22:29:57.557 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script ‘file:/openhab/conf/automation/js/sonos_coordinator_rule.js’: org.graalvm.polyglot.PolyglotException: TypeError: s.replace is not a function

As described, I have installed the JavaScript binding. My Openhab version is the 3.2 (docker installation). What am I doing wrong?