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

**URL:** <https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092>\
**Category:** Devices\
**Created:** [October 21, 2018, 5:54pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092 "2018-10-21T17:54:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruskie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruskie/32/13911_2.png) [@Ruskie](https://community.homey.app/u/Ruskie)\
**Post date:** [October 21, 2018, 5:54pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/1 "2018-10-21T17:54:10Z")

</div>

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?  
Thanks

---

<div class="post-metadata">

**Author:** ![johan\_bendz](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/johan_bendz/32/10344_2.png) [@johan\_bendz](https://community.homey.app/u/johan_bendz)\
**Post date:** [October 21, 2018, 7:10pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/2 "2018-10-21T19:10:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Ruskie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruskie/32/13911_2.png) [@Ruskie](https://community.homey.app/u/Ruskie)\
**Post date:** [October 22, 2018, 12:44am UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/3 "2018-10-22T00:44:25Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![anon2681894](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon2681894](https://community.homey.app/u/anon2681894)\
**Post date:** [October 22, 2018, 7:32am UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/4 "2018-10-22T07:32:00Z")

</div>

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

 ![50](https://us1.discourse-cdn.com/flex025/uploads/athom/original/2X/8/86224334428efa9e5c8aff2a855de8536f526f50.png)

---

<div class="post-metadata">

**Author:** ![TedTolboom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tedtolboom/32/12081_2.png) [@TedTolboom](https://community.homey.app/u/TedTolboom)\
**Post date:** [October 22, 2018, 10:46am UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/5 "2018-10-22T10:46:20Z")

</div>

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).

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [October 22, 2018, 2:27pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/6 "2018-10-22T14:27:07Z")

</div>

U sure about that?

---

<div class="post-metadata">

**Author:** ![anon2681894](https://avatars.discourse-cdn.com/v4/letter/a/c67d28/32.png) [@anon2681894](https://community.homey.app/u/anon2681894)\
**Post date:** [October 22, 2018, 2:38pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/7 "2018-10-22T14:38:28Z")

</div>

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… 🙂

---

<div class="post-metadata">

**Author:** ![TedTolboom](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/tedtolboom/32/12081_2.png) [@TedTolboom](https://community.homey.app/u/TedTolboom)\
**Post date:** [October 22, 2018, 6:51pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/8 "2018-10-22T18:51:55Z")

</div>

> [@anon2681894](#):
>
> 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… 🙂

We’re both right… 🤨

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

---

<div class="post-metadata">

**Author:** ![Ruskie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruskie/32/13911_2.png) [@Ruskie](https://community.homey.app/u/Ruskie)\
**Post date:** [October 23, 2018, 5:36pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/9 "2018-10-23T17:36:57Z")

</div>

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 🙄  
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? 😂

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [October 23, 2018, 5:46pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/10 "2018-10-23T17:46:37Z")

</div>

> [@Ruskie](#):
>
> I am not making any sense, am I?

Uhm, no ur not:

> [@Ruskie](#):
>
> ie it was NOT playing already), THEN STOP Sonos

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.

---

<div class="post-metadata">

**Author:** ![Ruskie](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/ruskie/32/13911_2.png) [@Ruskie](https://community.homey.app/u/Ruskie)\
**Post date:** [October 23, 2018, 6:05pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/11 "2018-10-23T18:05:23Z")

</div>

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  
ELSE  
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 🙂

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

Sorry, rather new here.

---

<div class="post-metadata">

**Author:** ![Rocodamelshekima](https://sea1.discourse-cdn.com/flex025/user_avatar/community.homey.app/rocodamelshekima/32/8209_2.png) [@Rocodamelshekima](https://community.homey.app/u/Rocodamelshekima)\
**Post date:** [October 23, 2018, 6:08pm UTC](https://community.homey.app/t/how-to-get-store-sonos-current-status-in-a-variable/3092/12 "2018-10-23T18:08:02Z")

</div>

> [@Ruskie](#):
>
> Please enlighten me on this tags business.

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.
