Homey Community Forum

How to get/store Sonos current status in a variable?

Hi all -

One of my Sonos connect’s is playing to TWO zones through a 2-zone amplifier. I have a Homey Flow to play Sonos when the lights are turned on in Zone 2, and pause when the lights go off in Zone 2.

However, since the Sonos is shared with Zone 1, the stop command above also stops playback if it was started manually in Zone 1.

So, the automation I am trying to create is like this:

Store current Sonos_status in a boolean variable (or flip a virtual switch).
If lights on, start Sonos playback in Zone 2 (if it’s on already, it is not affected, so no extra conditions here)
When lights go off, THEN IF Sonos_status=false (ie it was NOT playing already), THEN STOP Sonos.
Otherwise, do nothing so it keeps playing if it was playing already.

But I couldn’t find a way to set the variable using Sonos as a CONDITION, only as ACTION ie not being able to store its status.

Any workarounds you might suggest?

No, there is no way today to trigger on a Sonos app/variable change event.

You will have to set a “every x seconds” trigger that checks the variable for change if you want to trigger on Sonos changes.

Here’s a rather convoluted solution I am thinking of:

I also have my Sonos exposed to Apple’s Home via homebridge.

So the idea is to set up a Virtual Devices switch in Homey as my boolean Sonos status “storage”, expose it to Homekit via Sprut Homekit Homey App and have its status changed by a simple Homekit automation, sth like When Sonos (it’s an on/off switch in Apple’s Home App) is On, Turn Dummy Switch On. When Off, turn Off.

I assume this will get “reported” back to the Homey world.

I would then use it as an AND condition for turning off Sonos playback when lights are switched off (manually, or on timer) - so that if the Sonos was on when the whole thing started it won.t be turned off when it ended.

But my question in reference to your response is how do I “extract” the Sonos status in Homey at all?

Why not use the ‘Tags’ to set the status ?? Using Logic (or better logic) Some thing like this :

The tags suggested by @anon2681894 will work, if the Sonos is exclusively controlled by Homey…

Please not that if you change the volume through the Sonos app, the Homey tags will become out of sync (show an incorrect state).

U sure about that?

For me the ‘playing’ tag also toggles when using the sonos app, or control the sonos by pressing the fiscal button. So i guess it does not have a sync issue there… :slight_smile:

We’re both right… :face_with_raised_eyebrow:

It did not work for me on Sonos 4.0.13 (beta)… until I re-added my Sonos speakers based on this version…

1 Like

Not sure how to use tags to ascertain Sonos status, will read some more. My idea, on a second thought, won’t work since the “storage” switch will be updated and forget its past status the moment Sonos starts playback. So that was dumb :roll_eyes:
The solution i am thinking of is turning off Sonos when countdown reaches zero, but this timer will ONLY start if the Sonos is off in the first place as reported back to Homey from Apple Home through a virtual switch… I am not making any sense, am I? :joy:

Uhm, no ur not:

If it was not playing, why stop them?
And why save the status in a boolean while u have the status in the tags?
IF lights go on AND sonos tag is “playing” THEN do whatever u like.
Or u confused me too much alr.

Trying this as we speak:
Flow 1
IF Motion Sensor=ON AND Sonos_virtual_switch_set_by_Homekit=OFF THEN

  1. START Sonos_countdown
  2. TURN Sonos ON
    TURN Sonos ON

Flow 2
If Sonos_countdown reaches 0, then TURN Sonos OFF

Another question is, how does Homey execute commands in the THEN section, from Top to Down in sequence or all at the same time?

If “chronologically”, one after another, I might reduce the above without having tow do Two Sonos On in both THEN and ELSE parts. Maybe :slight_smile:

Please enlighten me on this tags business. Is it a condition using Better Logic?

Sorry, rather new here.

On the top of ur flow page there is a “Tags” section. Click it and find ur Sonos speaker. There u will find the tag.
Also in the pic @anon2681894 was showing u a few posts up.