This page last changed on Oct 14, 2014 by jules_bike.

I am using the Sonos node.js within OR and I want to have a Play/Pause switch that reads the status of the player. I've got a sensor which works fine but it returns several values:

STOPPED
PAUSED_PLAYBACK
PLAYING
TRANSITIONING

I would like to aggregate the values
STOPPED
PAUSED_PLAYBACK
to be treated as off

PLAYING
TRANSITIONING
to be treated as on

The switch would then use these values to show player state and also allow play and pause commands.

Is there a way to do this? I assume I need to use rules but I can't work out how!

You can use custom sensor and assign for your names corresponding on/off states. Then you can use this custom sensor for your switch. No rules necessary.

Posted by aktur at Oct 15, 2014 00:36

Hi Michal I get it working with a custom sensor with names: off and on assigned to values: paused_playback and playing.

However when I try and add two more names on and off for transitioning and stopped the designed only saves the first two because I guess names have to be unique.

Is there a way to fix this? When I pause a Sonos playlist it returns a status paused_playback but when I pause the radio it returns stopped. This means the switch only can work with one of them.

Posted by jules_bike at Oct 15, 2014 13:44

I think that names must be from paused/playing/stopped set and values on/off, but I haven't tested it. Of course you can do this also through rules like this:

rule "r1"
when
  Event(source=="aaa", value=="STOPPED")
then
  execute.command("in-memoryVirtualCommand", "off")
end

rule "r2"
when
  Event(source=="aaa", value=="PAUSED_PLAYBACK")
then
  execute.command("in-memoryVirtualCommand", "off")
end

etc.
Posted by aktur at Oct 15, 2014 14:53

I tried making the names the variables and the values on and off but that did not work.

In the end I've found a feature/bug! You can put on and off in lower and upper case and it seems to allow duplicates and it triggers the switch.

I think the rules one is the better option plus it can work with your fix for storing values outside of OR.

thanks for the help

Posted by jules_bike at Oct 15, 2014 16:57
Document generated by Confluence on Jun 05, 2016 09:34