[SOLVED] Starting sonos (play1/play3) with a fixed Radio-Station, when pressing Play-Button at the Speaker

Hardware: RasPI 3b, OH: 2.5.0 M1, Sonos-Firmware 10.0

I want to start my Sonos-Speaker with a fixed Radio-Station and fixed volume, when pressing the Play-Button at the Speaker, and made a Rule therefore:

//var Timer tAZRadio = null

rule "ArbeitszimmerRadio"
when
    Item AZ_Sonos_Control changed from PAUSE to PLAY
//      Item AZ_Sonos_Stop changed from ON to OFF
then
//    tAZRadio?.cancel
    logInfo("azRadio","AZ_Sonos_Control eingeschaltet!")
//    tWZRadio = createTimer(now.plusSeconds(5),[|
        AZ_Sonos_Volume.sendCommand(15)
        AZ_Sonos_Tuneinstationid.sendCommand("15034")
//    ])
end

.items

Player AZ_Sonos_Control   "Player"  <sonos_control>  (AZ_Sonos) {channel="sonos:PLAY1:RINCON_949F3E157B8401400:control"}

When pressing the Play-Button at Speaker, i can see the following statements in the logger:

// Play Button at Sonos-Speaker
//
2019-02-13 15:12:16.060 [vent.ItemStateChangedEvent] - AZ_Sonos_Currenttrack changed from SWR3 99.6 - Mehr Hits. Mehr Kicks. Einfach SWR3 - Baden-Baden, Germany to SWR3 99.6 - Rainbirds - Blueprint - Mehr Hits. Mehr Kicks. Einfach SWR3 - Baden-Baden, Germany
2019-02-13 15:12:16.066 [vent.ItemStateChangedEvent] - AZ_Sonos_State changed from STOPPED to TRANSITIONING
2019-02-13 15:12:16.082 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from PAUSE to UNDEF
2019-02-13 15:12:16.086 [vent.ItemStateChangedEvent] - AZ_Sonos_Stop changed from ON to OFF
2019-02-13 15:12:16.624 [vent.ItemStateChangedEvent] - AZ_Sonos_State changed from TRANSITIONING to PLAYING
2019-02-13 15:12:16.630 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from UNDEF to PLAY
2019-02-13 15:12:52.077 [vent.ItemStateChangedEvent] - AZ_Sonos_Currenttrack changed from SWR3 99.6 - Rainbirds - Blueprint - Mehr Hits. Mehr Kicks. Einfach SWR3 - Baden-Baden, Germany to SWR3 99.6 - Olly Murs - Excuses - Mehr Hits. Mehr Kicks. Einfach SWR3 - Baden-Baden, German

…and the Speaker starts to play, but with the last entry. No Rule is fired and that’s not what i expected.

But when pressing the Player-Button in the Sitemap, the Rule is fired and the Speaker starts with the required values (Radio, Volume) and the Logger shows the following, which is a lot more than before:

2019-02-13 15:01:57.955 [ome.event.ItemCommandEvent] - Item 'AZ_Sonos_Control' received command PLAY
2019-02-13 15:01:57.997 [nt.ItemStatePredictedEvent] - AZ_Sonos_Control predicted to become PLAY
2019-02-13 15:01:58.006 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from PAUSE to PLAY
2019-02-13 15:01:58.387 [vent.ItemStateChangedEvent] - AZ_Sonos_Currenttrack changed from Antenne ThĂĽringen 102.2 - George Ezra - Hold My Girl - Wir lieben ThĂĽringen! Wir lieben Musik! - Inselsberg, ThĂĽringen, Germany to Antenne ThĂĽringen 102.2 - David Guetta & Sia - Flames - Wir lieben ThĂĽringen! Wir lieben Musik! - Inselsberg, ThĂĽringen, Germany
2019-02-13 15:01:58.410 [vent.ItemStateChangedEvent] - AZ_Sonos_State changed from STOPPED to TRANSITIONING
2019-02-13 15:01:58.413 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from PLAY to UNDEF
2019-02-13 15:01:58.416 [vent.ItemStateChangedEvent] - AZ_Sonos_Stop changed from ON to OFF
2019-02-13 15:01:58.764 [INFO ] [ipse.smarthome.model.script.AZ_Sonos] - AZ_Sonos_Control eingeschaltet!
2019-02-13 15:01:58.771 [ome.event.ItemCommandEvent] - Item 'AZ_Sonos_Volume' received command 18
2019-02-13 15:01:58.779 [ome.event.ItemCommandEvent] - Item 'AZ_Sonos_Tuneinstationid' received command 24896
2019-02-13 15:01:58.793 [nt.ItemStatePredictedEvent] - AZ_Sonos_Volume predicted to become 18
2019-02-13 15:01:58.797 [nt.ItemStatePredictedEvent] - AZ_Sonos_Tuneinstationid predicted to become 24896
2019-02-13 15:01:58.806 [vent.ItemStateChangedEvent] - AZ_Sonos_Tuneinstationid changed from 25774 to 24896
2019-02-13 15:01:59.359 [vent.ItemStateChangedEvent] - AZ_Sonos_CurrentAVtransportURI changed from x-sonosapi-stream:s25774?sid=254&flags=8224&sn=0 to x-sonosapi-stream:s24896?sid=254&flags=32
2019-02-13 15:01:59.364 [vent.ItemStateChangedEvent] - AZ_Sonos_CurrenttrackURI changed from aac://http://antenne-th.divicon-stream.net/antth_atlive_sfS8-aacplus-64?sABC=5p641ro7%230%2335853p6o65q583qq09rps4onqs878osr%23gharva&amsparams=playerid:tunein;skey:1550065335 to x-sonosapi-stream:s24896?sid=254&flags=32
2019-02-13 15:01:59.648 [vent.ItemStateChangedEvent] - AZ_Sonos_CurrentTitle changed from Antenne ThĂĽringen 102.2 to SWR3 99.6
2019-02-13 15:01:59.663 [vent.ItemStateChangedEvent] - AZ_Sonos_Currenttrack changed from Antenne ThĂĽringen 102.2 - David Guetta & Sia - Flames - Wir lieben ThĂĽringen! Wir lieben Musik! - Inselsberg, ThĂĽringen, Germany to SWR3 99.6 - Mehr Hits. Mehr Kicks. Einfach SWR3 - Baden-Baden, Germany
2019-02-13 15:01:59.670 [vent.ItemStateChangedEvent] - AZ_Sonos_State changed from TRANSITIONING to STOPPED
2019-02-13 15:01:59.673 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from UNDEF to PAUSE
2019-02-13 15:01:59.677 [vent.ItemStateChangedEvent] - AZ_Sonos_Stop changed from OFF to ON
2019-02-13 15:02:00.047 [vent.ItemStateChangedEvent] - AZ_Sonos_CoverAlbum changed from raw type (image/png): 6804 bytes to raw type (image/png): 3222 bytes
2019-02-13 15:02:01.074 [vent.ItemStateChangedEvent] - AZ_Sonos_CurrenttrackURI changed from x-sonosapi-stream:s24896?sid=254&flags=32 to aac://http://dg-swr-http-dus-dtag-cdn.cast.addradio.de/swr/swr3/live/aac/96/stream.aac?ar-distributor=f0a1
2019-02-13 15:02:01.328 [vent.ItemStateChangedEvent] - AZ_Sonos_State changed from STOPPED to TRANSITIONING
2019-02-13 15:02:01.347 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from PAUSE to UNDEF
2019-02-13 15:02:01.359 [vent.ItemStateChangedEvent] - AZ_Sonos_Stop changed from ON to OFF
2019-02-13 15:02:01.852 [vent.ItemStateChangedEvent] - AZ_Sonos_State changed from TRANSITIONING to PLAYING
2019-02-13 15:02:01.859 [vent.ItemStateChangedEvent] - AZ_Sonos_Control changed from UNDEF to PLAY

I would be grateful for every hint or solution. Thx in advance.

Cheers - Peter

The problem with the Rule trigger is, if you look in the events.log, that the Item changes first to UNDEF and then to PLAY so the Item never changes from PAUSE directly to PLAY. If you want to trigger the rule any time it changes to play get rid of the from part of the Rule trigger. If you want to only run when it goes to PAUSE to PLAY, then it gets…complicated.

This is because when you change the Item state using the sitemap it goes straight from PAUSED to PLAY without that intermediate UNDEF in between.

Hi Rich, thx for reply. I have to smile a bit, when reading your words

and be happy that i’m not too stupid to understand, that there’s an easy solution and I will not see it.
Leaving the “from”-Part was my first solution, but ended in a dead-lock, so I added the “from”.

But I found a much easier way to handle it. I simply say it to “Alexa” and “she” will do, what I say, without any grumble, and btw it saves five meters to go to my Sonos :stuck_out_tongue_winking_eye:

Cheers,
Peter

EDIT: But that doesn’t mean that i’m not looking for Rule-based Solution anymore. If there is anyone out there to help or give me tips, don’t hesitate to answer me, every hint is welcomed.

Well, the complicated part is that you would need to set up some book keeping and timers/timestamps.

  • You need one Rule to trigger when the Item changes to PAUSE. Record a timestamp so you know when this occurred.

  • You need another Rule to trigger when the Item changes to PLAY. In this Rule check the timestamp for when the Item changed to PAUSE. If that was recent enough (you’ll have to experiment to figure out what recent enough is) then you execute the body of your current Rule.

1 Like

Thx, Rich. I understand the way to go for the goal. (As book keeping was my daily business for more than 45 years :joy:)

Reading your proposal it seems not that hard to realise my wish. I will have a look in your DP :wink: how to calculate timing differences (elapsed time). Thx, again for your help and showing me the right way.
Cheers,
Peter

Hi Fibu,

I tried doing what Rich said back in July 2018 till November and it really never ended up working perfectly. I ended up stopping controlling all the Sono’s (Play, Pause, Stop, etc.) from OH HabPanel and I just show the status of each Sonos now. I’m running OH 2.3.001 and the binding is the 02.19.19 stable build which is v2.5. I’m also running Sonos’s controller v10.x.

I do however control stopping (and dejoining from a group) some Sonos in Rules based on a Samsung TV and Onkyo receiver getting turned ON to watch TV.

Just my 2 cents worth.

Best, Jay

It might be worth one of you two filing an issue on the binding. I don’t see any reason why the Item should go to UNDEF first and then to PLAY (for example). UNDEF should be reserved when the state is truly unknown. There is less than 100msec between transitioning from PAUSE to UNDEF to PLAY.

It is clearly causing problems and limiting the use cases.

@rlkoshak, @jwiseman

No worries, mates.
It’s no problem, it’s just nosiness, tinkering with my equipment. So now I know that the Play-Knob of my speaker doesn’t work as the Player Item of my Sonos-Binding.
So, as Rich said it seems to be special art of the binding, how to handle the several channels.

What is more important for me, is to get shown how a solution could look like. And learing from the best, is always the best what can happen.

Maybe Jay will file an issue, as I don’t know how to do and where.

Cheers,
Peter

For the record the steps are:

  1. sign up for a GitHub account
  2. navigate to https://github.com/openhab/openhab2-addons
  3. click on “issues”
  4. search to see if an issue is already opened that covers the problem
  5. if not click “new issue” and fill out the template.
1 Like