[SOLVED] Rule for switch is not working

  • Platform information:
    • Hardware: VM
    • OS: windows 7
    • Java Runtime Environment: jre 1.8.0_191
    • openHAB version: 2.4.0
  • Issue of the topic:

Hi i have the problem the following rule is not working the shutter is not moving up:
any Idea?

rule “Switch_GF_Office_Street1_Up_Alexa”
when
Item Switch_GF_Office_Street1_Up_Alexa received command
then

switch(receivedCommand) {
	case OFF:  sendCommand(Shutter_GF_Office_Street1, STOP)
	
	case ON: sendCommand(Shutter_GF_Office_Street1, UP)
  • Items:
    Rollershutter Shutter_GF_Office_Street1 “Büro Straße 1” (GF_Office, Shutters)
    Switch Switch_GF_Office_Street1_Up_Alexa “Büro Rollladen Straße hoch”[“Switchable”]

  • Logs
    2018-12-26 22:32:52.489 [ome.event.ItemCommandEvent] - Item ‘Switch_GF_Office_Street1_Up_Alexa’ received command OFF
    2018-12-26 22:32:52.489 [vent.ItemStateChangedEvent] - Switch_GF_Office_Street1_Up_Alexa changed from ON to OFF
    2018-12-26 22:32:54.549 [ome.event.ItemCommandEvent] - Item ‘Switch_GF_Office_Street1_Up_Alexa’ received command ON
    2018-12-26 22:32:54.564 [vent.ItemStateChangedEvent] - Switch_GF_Office_Street1_Up_Alexa changed from OFF to ON

Your rule has no end statement
You should use the .sendCommand() method instead of the action
Your statement switch (receivedCommand) is interpreted as switch true and therefore
never execute internal cases.

rule “Switch_GF_Office_Street1_Up_Alexa”
when
    Item Switch_GF_Office_Street1_Up_Alexa received command
then
    switch receivedCommand {
        case OFF:  Shutter_GF_Office_Street1.sendCommand(STOP)
        case ON: Shutter_GF_Office_Street1.sendCommand(UP)
    }
end

thx for fast answer but still the same problem
log see below
how to check if the rule is really executed ?

2018-12-26 23:01:19.535 [ome.event.ItemCommandEvent] - Item ‘Switch_GF_Office_Street1_Up_Alexa’ received command ON
2018-12-26 23:01:19.551 [vent.ItemStateChangedEvent] - Switch_GF_Office_Street1_Up_Alexa changed from OFF to ON

rule “Switch_GF_Office_Street1_Up_Alexa”
when
    Item Switch_GF_Office_Street1_Up_Alexa received command
then
    logInfo("RULE","START")
    switch receivedCommand {
        case OFF:  Shutter_GF_Office_Street1.sendCommand(STOP)
        case ON: Shutter_GF_Office_Street1.sendCommand(UP)
    }
    logInfo("RULE", "END")
end

Monitor the logs when saving the rule and at execution

now the whole rule file is broken

2018-12-26 23:16:11.387 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘demo.rules’ has errors, therefore ignoring it: [14,6]: no viable alternative at input ‘â’

Hi Paul,

Add logging statements. You can modify your existing rule or add a new rule. I think something like this will work

rule "Test Logging"
when
    Item Switch_GF_Office_Street1_Up_Alexa changed
then
    logInfo("Test Logging", "Switch_GF_Office_Street1_Up_Alexa is:  " + Switch_GF_Office_Street1_Up_Alexa.state)
end

Regards,
Burzin

ok thx now it works

Glad you have it working.:+1:

Please click the square box on the post that provided the solution and edit the title to start with [Solved].

Thanks

Edit: I edited the title so please mark the appropriate post that provided the solution.

The solution is:

rule “Switch_GF_Office_Up_Alexa”
when
Item Switch_GF_Office_Up_Alexa received command
then

switch(receivedCommand) {
	case OFF:  {sendCommand(Shutter_GF_Office_Street1, STOP)
			   sendCommand(Shutter_GF_Office_Street2, STOP)
			   sendCommand(Shutter_GF_Office_Side, STOP)
			   }
	case ON: {sendCommand(Shutter_GF_Office_Street1, UP)
			sendCommand(Shutter_GF_Office_Street2, UP)
			sendCommand(Shutter_GF_Office_Side, UP)
			}
	}

end

You should use the .sendCommand() method instead of the action
eg:

Shutter_GF_Office_Street2.sendCommand(STOP)

It is faster to execute and easier to compile.
See: https://www.openhab.org/docs/configuration/rules-dsl.html#myitem-sendcommand-new-state-versus-sendcommand-myitem-new-state

so this is the better solution and its working

rule “Switch_GF_Office_Up_Alexa”
when
Item Switch_GF_Office_Up_Alexa received command
then

switch(receivedCommand) {
	case OFF:  {Shutter_GF_Office_Street1.sendCommand(STOP)
			    Shutter_GF_Office_Street2.sendCommand(STOP)
			    Shutter_GF_Office_Side.sendCommand(STOP)
			   }
	case ON: {	Shutter_GF_Office_Street1.sendCommand(UP)
			    Shutter_GF_Office_Street2.sendCommand(UP)
			    Shutter_GF_Office_Side.sendCommand(UP)
			}
	}

end