Sonos Play Overlay Audio Clips using local websockets

I have created an addon to JRule which will connect to local socket and play audio Clips.
The benefit over using the normal sonos binding is that it will not interrupt what is playing, and it will continue to play what was played before once the clip finishes.

Hope it can help someone. It’s not that well tested yet so expect changes.

/S

1 Like

Next up to fix is tts and audio sink. Possibly I could consider merging some code with the Sonos-binding.

Enhancing the existing binding is of course the way to go.

It was in my TODO list to try to do that but not very high. I have not yet started.

Well, I want to show case Jrule, you get Items and rules for free that you won’t get with the regular sonos-binding. Other than that I agree. I’ll see what I can do.

1 Like

This is like gold for me. Thank you for sharing.

1 Like

I have added audio sinks now as well to support oh say.

2 Likes

can i ask for something ? can you adjust so that the sinks have some kind of added name like _clip or whatever when they show up in the sinks list in the webui ?
milllion thanks

Where in the UI do you see this? (Screenshot?).
The audio sink are named “jsas:RINCON_XYZABVDEDFD”,
What would you like to rename them to? “jsas:RINCON_XYZABVDEDFD_clip” ?

I hope this explains what I mean. It’s really confusing to know wich sink is from who Sonos or the rule.

Fixed!

1 Like

I have added a new version
Some refactorings with names and also added possibility to cancelAudioClips (cancel overlay)
as well as flashing the led on the speaker when playing audio clips.

1 Like

Hi @Seaside

Thanks for taking the time and putting in the effort to build this. I came across this by accident, but it’s something I’ve been looking for. I have a number of Notifications that run and find it very annoying that the current stream is stopped to play the Notification.

I have completed the installation, but I’m getting this error. Which I suspect could be down to the version of Java I’m running. Can you help?

openjdk 17.0.10 2024-01-16 LTS
OpenJDK Runtime Environment Zulu17.48+15-CA (build 17.0.10+7-LTS)
OpenJDK 64-Bit Server VM Zulu17.48+15-CA (build 17.0.10+7-LTS, mixed mode, sharing)

[JRuleCompiler, Could not create create instance using default constructor: {}]{}
java.lang.reflect.InvocationTargetException: null
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77) ~[?:?]
        at jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[?:?]
        at java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499) ~[?:?]
        at java.lang.reflect.Constructor.newInstance(Constructor.java:480) ~[?:?]
        at org.openhab.automation.jrule.internal.compiler.JRuleCompiler.loadClass(JRuleCompiler.java:151) ~[?:?]
        at org.openhab.automation.jrule.internal.compiler.JRuleCompiler.lambda$1(JRuleCompiler.java:110) ~[?:?]
        at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:992) ~[?:?]
        at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:762) ~[?:?]
        at org.openhab.automation.jrule.internal.compiler.JRuleCompiler.loadClassesFromJar(JRuleCompiler.java:94) ~[?:?]
        at org.openhab.automation.jrule.internal.handler.JRuleHandler.createRuleInstances(JRuleHandler.java:312) ~[?:?]
        at org.openhab.automation.jrule.internal.handler.JRuleHandler.initialize(JRuleHandler.java:220) ~[?:?]
        at org.openhab.automation.jrule.internal.JRuleFactory.init(JRuleFactory.java:95) ~[?:?]
        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:1136) [?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) [?:?]
        at java.lang.Thread.run(Thread.java:840) [?:?]
Caused by: java.lang.NoClassDefFoundError: com/google/gson/Gson
        at org.openhab.automation.jrule.sonos.SonosWsClient.<init>(SonosWsClient.java:52) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosCoordinator.<init>(SonosCoordinator.java:29) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosCoordinator.get(SonosCoordinator.java:44) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.fetchThingAttributes(SonosRuleModule.java:96) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.lambda$fetchSonosThingAttributes$5(SonosRuleModule.java:85) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?]
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) ~[?:?]
        at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1707) ~[?:?]
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
        at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.fetchSonosThingAttributes(SonosRuleModule.java:85) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.<init>(SonosRuleModule.java:26) ~[?:?]
        ... 18 more
Caused by: java.lang.ClassNotFoundException: com.google.gson.Gson
        at java.net.URLClassLoader.findClass(URLClassLoader.java:445) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:592) ~[?:?]
        at java.lang.ClassLoader.loadClass(ClassLoader.java:525) ~[?:?]
        at org.openhab.automation.jrule.internal.handler.JRuleHandler$JRuleClassLoader.loadClass(JRuleHandler.java:545) ~[?:?]
        at org.openhab.automation.jrule.sonos.SonosWsClient.<init>(SonosWsClient.java:52) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosCoordinator.<init>(SonosCoordinator.java:29) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosCoordinator.get(SonosCoordinator.java:44) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.fetchThingAttributes(SonosRuleModule.java:96) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.lambda$fetchSonosThingAttributes$5(SonosRuleModule.java:85) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183) ~[?:?]
        at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179) ~[?:?]
        at java.util.HashMap$KeySpliterator.forEachRemaining(HashMap.java:1707) ~[?:?]
        at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509) ~[?:?]
        at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150) ~[?:?]
        at java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173) ~[?:?]
        at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[?:?]
        at java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.fetchSonosThingAttributes(SonosRuleModule.java:85) ~[?:?]
        at org.openhab.automation.jrule.rules.user.SonosRuleModule.<init>(SonosRuleModule.java:26) ~[?:?]
        ... 18 more

Looks like gson lib is missing. It should normally be included by openhab. What version of openhab are you running?

I’m running version 4.1.2. Is there a way to check what version of the gson lib I have installed?

If you login to the karaf console and do:

openhab> bundle:list|grep Gson
 36 x Active x  80 x 2.10.1.v20230109-0753  x Gson

You should have gson there.

I’ve also built a version which includes gson, you could try it:

I’m running 4.1.2 stable myself, without having to provide the gson jar file.

Thanks, I’ve checked and it looks all good.

openhab> bundle:list|grep Gson
 36 x Active x  80 x 2.10.1.v20230109-0753  x Gson

I’ve tried a reboot or two and still get the same error. Anything else I can try?

Thanks,

Garry

Over the weekend I built a new server and installed openHAB, so clean install and still get the same error. Could it be the version of Java I’m running?

I doubt it. Have you tried the jar where gson is inclduded as well?
Difficult to understand what happens since I don’t get this error myself, have not seen other users getting it either.

If you are experimenting with new versions of openhab, you could try to install 4.0.0 and see if it works better? (Just to see that it is not a version thing)

OK, I’ve made some progress.

  1. Created new VM and installed Rocky Linux 8
  2. Installed Java-17
  3. Installed the Development libraries for Java-17
  4. Installed openHAB
  5. Installed the Sonos Binding
  6. Install the JRules component
  7. Downloaded the jrules-sonos.jar to the jrules-jar folder
  8. Rebooted the server

The logs no longer have my original error. So we have success.

1 Like