The method or field item is undefined

Hello,

I’ve been trying all, have followed the rules manual, tried both methods, but still I’m not able to get sendCommand to work. even if I put it before or after the item :frowning:

Below is an example of my latest testing rule:

rule MasterOFF
when
	Item Master_Off changed
then
	if (Master_Off.state == OFF)
		sendCommand(DiningTable, OFF)  // Here is where I get the undefined error
end

I have also tried:

rule MasterOFF
when
	Item Master_Off changed
then
	if (Master_Off.state == OFF)
		DiningTable.sendCommand(OFF) // and here again I get the undefined error
end
 

Here is the log output:

2017-10-16 00:16:32.306 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'all_off.rules'
2017-10-16 00:16:32.337 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'all_off.rules' is either empty or cannot be parsed correctly!

However none of them works.
Any help would be much appreciated.

Many thanks in advance!

Ok, it seems like the rule is triggering after all. Even though I’ve got the errors.

However, I’m trying to trigger both master on and off with a switch, but in both cases it only triggers the master OFF.

Here is my rule:

rule MasterOFF
when
	Item Master_Off changed 
then
 	if (Master_Off == OFF)
 	    DiningTable.sendCommand(OFF)
        SofaDownlights.sendCommand(OFF)
        PendantLight.sendCommand(OFF)
        TvLights.sendCommand(OFF)
        GateLights.sendCommand(OFF)
        StorageLights.sendCommand(OFF)	
        WallLights.sendCommand(OFF)		
        WorkingLight.sendCommand(OFF)	
        WashingArea.sendCommand(OFF)	
        ParkingLights.sendCommand(OFF)	
        KitchenLights.sendCommand(OFF)
    if else
        DiningTable.sendCommand(ON)
        SofaDownlights.sendCommand(ON)
        PendantLight.sendCommand(ON)
        TvLights.sendCommand(ON)
        GateLights.sendCommand(ON)
        StorageLights.sendCommand(ON)
        WallLights.sendCommand(ON)	
        WorkingLight.sendCommand(ON)
        WashingArea.sendCommand(ON)
        ParkingLights.sendCommand(ON)
        KitchenLights.sendCommand(ON) 
end

A few remarks, hope this helps:

I think you need to put all rule names in quotation marks
rule "MasterOff"
http://docs.openhab.org/configuration/rules-dsl.html#the-syntax

The log-entries you listed are normal if you use Samba to update your files. The reasons have been discussed in a few threads here on the forum, but essentially, OH tries to load the files while they are still being saved. You can just ignore them

As with regard to the difference between actions sendCommand("string","string") or methods Item.sendCommand(Command), please see here: http://docs.openhab.org/configuration/rules-dsl.html#manipulating-item-states
Methods are most of the time better/more reliable.

Finally with regard to your last rule " if else" does not exist and you likely need a few more brackets. Try this:

rule "MasterOFF"
when
	Item Master_Off changed 
then
 	if (Master_Off == OFF) {
 	    DiningTable.sendCommand(OFF)
        SofaDownlights.sendCommand(OFF)
        PendantLight.sendCommand(OFF)
        TvLights.sendCommand(OFF)
        GateLights.sendCommand(OFF)
        StorageLights.sendCommand(OFF)	
        WallLights.sendCommand(OFF)		
        WorkingLight.sendCommand(OFF)	
        WashingArea.sendCommand(OFF)	
        ParkingLights.sendCommand(OFF)	
        KitchenLights.sendCommand(OFF)
        }
    else {
        DiningTable.sendCommand(ON)
        SofaDownlights.sendCommand(ON)
        PendantLight.sendCommand(ON)
        TvLights.sendCommand(ON)
        GateLights.sendCommand(ON)
        StorageLights.sendCommand(ON)
        WallLights.sendCommand(ON)	
        WorkingLight.sendCommand(ON)
        WashingArea.sendCommand(ON)
        ParkingLights.sendCommand(ON)
        KitchenLights.sendCommand(ON) 
       }
end

I would strongly encourage you to use Eclipse Smart Home Designer or similar (http://docs.openhab.org/configuration/editors.html), it will help you notice syntax errors.

You need to review the syntax for OH rules, not sure what you’re using there. Curly brackets.

if (test) {
   dosomething
 } else if ( test 2)  {
   something different
} else {
   other thing
}