Sonos - How do you check/report the play state of Sonos (to set a variable)?


#1

This is more of a general question rather than full Piston: Design help, so I thought I would post it here. If it is better being in Piston: Design help, please let me know and I will move it over there.

  • I want to create a Lightning alert piston for when someone is swimming.
  • Most of the time we are swimming, we have music playing on an outdoor Sonos.
  • I have a WeatherFlow Smart Weather Station which has lightning detection and reports lightning strikes by distance. It currently has IFTTT integration, but later this year it should have direct ST integration as well.

Something along the lines of;
If music is playing on the Pool Sonos, and lightning is detected, pause the music, speak message then resume playback.

I only want the rule to be active when the Sonos play state (??) is playing. How do I check/report the play state of Sonos in a piston?

TIA


#2

You could use a restriction

Only When
{sonosdevicename) status is ‘playing’


#3

I had actually written that exact rule when I first started looking into this last, but something is obviously wrong with it. Here a simplified rule and the error I get.

At the top of the piston screen…

and the logs


#4

You need to use use ‘status’ instead of ‘$status’. They serve very different purposes. Sorry, I thought about mentioning that and forgot.


#5

So I assume there is something about line 18 that is wrong, I just don’t know where to start. Here is the condition box;

If I change the status type to the other one list;

I still get the same error


#6

I stand corrected, it IS working now. I tried that previously and got the errors??


#7

Now it’s not. I don’t know what is happening here?? I have to head out for a bit. Any thoughts?


#8

When I import your piston, it asks me to replace three devices: RGB Bulb 3, Music Player 5, and Contact Sensor 2. But I see no reference to a contact sensor in the body of the piston itself. Something is clearly off, so my suggestion is to start over clean:


#9

I created this from new, and it seems to work correctly. Feel free to try it on your end as well to confirm (if you have time).

So with that working, it gives me proof of concept to try to create the more complex piston I need. Maybe the original rule I had tried didn’t work because I had imported or duplicated it from another piston??

Either way, thanks for you help with this.


#10

There is definitely something broken in your original piston, but I’ve never seen anything like that before and can’t say how it happened. Perhaps one of the @webCoRE_Minions will take a peek, if only because an error like that shouldn’t happen and the fact that it did complicated what was otherwise very simple question to answer.

Anyway, glad you’re up and running.


#11

There was originally an else if condition that was deleted, but you can see when restoring the piston that the placeholder for it is still there. Issues with removing else if conditions have been reported before but this is the first I’ve seen where the condition seems to have an effect on the piston. I’m not sure why it would affect how the piston operates, but this is a good scenario for how not being able to get rid of an else if could at the very least be confusing for importing the piston.


#12

Thanks for the explanation. I am new to all of this and while playing around with different settings/rules etc, I moved bits of code around in different arguments. I will make sure going forward that I do that less often, and just put it all in fresh :slight_smile:.


#13

@saxnix

Please share your piston when finished as I have a need for something like this as well.


#14

Will do @Prayerfuldrop. At this stage, I am going to attempt to build it using the IFTTT webhook, but I don’t know how to do it. I posted a question about how to do it here, so hopefully that will get answered and I can continue. Once I get something in place, I will put it up in the Piston Design Help section, and will post a link back here.


#15

@Prayerfuldrop Here is the link to the Piston I am working on for Lightning detection notification.