This page last changed on Jan 19, 2014 by skogen75.

Hi guys,

Wondering if I could get some help in getting a virtual switch to 'switch' using a rule.

I have a Squeezebox music player that I turn on/off using a virtual switch that triggers a rule to send the actual powerOn and powerOff commands. I also have a virtual switch that triggers a toggle between on/off states (play/pause, no mapping, I just use 'on' as play and 'off' as pause). This also triggers a rule that either sends the actual play or pause commands.

Now, I need the rule that monitors the virtual power sensor for an 'off' state to trigger two things:

1. Send the power off command
2. Flip the state of the play/pause switch to 'off'

otherwise my Squeezebox could be off but the play switch can indicate it is playing.

Here is what I have:

Command name:  vcSqueezebox_PowerOn
Protocol:  In-memory virtual command
Command: on
Address: vSqueezeboxPOWER
Command name:  vcSqueezebox_PowerOff
Protocol:  In-memory virtual command
Command: off
Address: vSqueezeboxPOWER
Command name:  vcSqueezebox_PowerStatus
Protocol:  In-memory virtual command
Command: status
Address: vSqueezeboxPOWER
Command name:  vcSqueezebox_PlayOn
Protocol:  In-memory virtual command
Command: on
Address: vSqueezeboxPLAY
Command name:  vcSqueezebox_PlayOff
Protocol:  In-memory virtual command
Command: off
Address: vSqueezeboxPLAY
Command name:  vcSqueezebox_PlayStatus
Protocol:  In-memory virtual command
Command: status
Address: vSqueezeboxPLAY
Sensor name:  vsSqueezebox_PowerStatus
Command: vcSqueezebox_PowerStatus
Type: switch
Sensor name:  vsSqueezebox_PlayStatus
Command: vcSqueezebox_PlayStatus
Type: switch
Switch name:  vsSqueezebox_PowerStatus
Sensor: vsSqueezebox_PowerStatus
Command(on): vcSqueezebox_PowerOn
Command(off): vcSqueezebox_PowerOff
Switch name:  vSqueezebox_PlayStatus
Sensor: vsSqueezebox_PlayStatus
Command(on): vcSqueezebox_PlayOn
Command(off): vcSqueezebox_PlayOff
package org.openremote.controller.model.event

global org.openremote.controller.statuscache.CommandFacade execute;
global org.openremote.controller.statuscache.SwitchFacade switches;
import org.openremote.controller.protocol.*;

rule "Squeezebox ON"
when
   Event(source=="vsSqueezebox_PowerStatus", value=="on")
then
   execute.command("cSqueezebox_power_on");  <-- these are the actual power_on command and it works
end

rule "Squeezebox OFF"
when
   Event(source=="vsSqueezebox_PowerStatus", value=="off")
then
   execute.command("vSqueezebox_PlayStatus","off");  <-- this doesn't turn the vSqueezebox_PlayStatus switch to off
   execute.command("cSqueezebox_power_off");  <-- this is the actual power_off command and it works
end

The rules fire when they are supposed to, that is, I can turn the power on/off, but the vSqueezebox_PlayStatus switch does not change its state to 'off', as indicated by the image not changing in the UI nor a label that monitors vsSqueezebox_PlayStatus sensor.

I have searched the forums and I think that my rules are correct, any idea on what to try to get this to work? The boot log shows no errors, however the xml-parser log shows DEBUG statements for all the switch sensors...

DEBUG 2014-01-19 10:53:27,790 (XML): A switch sensor (Name = 'vsSqueezebox_PowerStatus', ID = 3696905) has an incomplete <state> element mapping, the value attribute is missing in <state name = on/>.
DEBUG 2014-01-19 10:53:27,790 (XML): A switch sensor (Name = 'vsSqueezebox_PowerStatus', ID = 3696905) has an incomplete <state> element mapping, the value attribute is missing in <state name = off/>.

I am using the following:
OpenRemote-Controller-2.1.0_SNAPSHOT-2013-06-17
Preview designer
iOS

Thanks much,

Erik

I just checked the WebConsole and that doesn't work either.

Do I have the correct/needed packages/imports/global statements? Does the execute.command need to be changed to something else?

I have also tried to make two new sets of virtual switches with their associated sensors and commands and I can't get one switch to change the other via rules either. Hmmm I feel like I am missing something simple.

Thanks,
Erik

Posted by skogen75 at Jan 19, 2014 18:55

Change

   execute.command("vSqueezebox_PlayStatus","off");  <-- this doesn't turn the vSqueezebox_PlayStatus switch to off

to

   execute.command("vcSqueezebox_PlayStatus","off"); 

Hmmm I feel like I am missing something simple.

Indeed, a letter 'c'

Alternatively you can change it to:

  switches.name("vSqueezebox_PlayStatus").off();

as you already added global switches.

Posted by aktur at Jan 19, 2014 21:37

Awesome!!!

It works!

Thanks Michal, I have read many of your posts and you really know your stuff. You made my day!

Erik

Posted by skogen75 at Jan 19, 2014 21:52
Document generated by Confluence on Jun 05, 2016 09:36