Duplicate local variable previousState

Hi everyone,

I’m using visual studio code to edit all openhab related files. It work perfectly but I ran into a small issue. The syntax validation of visual studio code gives the warning “Duplicate local variable previousState” on the first line of that rule:

rule "Dim lights for TV"
	when
		Thing 'samsungtv:tv:0ee6b281_00fa_1000_9021_5cf6dcd66f98' changed from OFFLINE to ONLINE or // TV switch on
		Item  Lamps_Salon_Toggle changed from OFF to ON or  // Lights of salon software switch on 
		Thing "hue:0210:001788278066:14" changed from OFFLINE to ONLINE or	// Lihgts of salon hardware switch on 
		Thing "hue:0210:001788278066:8" changed from OFFLINE to ONLINE or
		Thing "hue:0210:001788278066:12" changed from OFFLINE to ONLINE
	then
		var sts1 = ThingAction.getThingStatusInfo("hue:0210:001788278066:14").getStatus();
		var sts2 = ThingAction.getThingStatusInfo("hue:0210:001788278066:8").getStatus();
		var sts3 = ThingAction.getThingStatusInfo("hue:0210:001788278066:12").getStatus();
		var tv = ThingAction.getThingStatusInfo("samsungtv:tv:0ee6b281_00fa_1000_9021_5cf6dcd66f98").getStatus();

		if (sts1.toString() == 'ONLINE' &&
			sts2.toString() == 'ONLINE' &&
			sts3.toString() == 'ONLINE'  &&
			Lamps_Salon_Toggle.state == ON &&
			tv.toString == "ONLINE"
		) {
		    	sendCommand(Lamps_Salon_Dimmer, 10)
		    	
		    }
end

The rule is working perfectly.
I saw that previousState is a variable defined automatically in rules with at least one status change event trigger. This is my case I have 5 of them.
Doing some tests I noticed that I have this warning when I mix Things and Items in the when clause. If I have only items or only things I don’t have the warning.

How can I get rid of that warning when using things and items in rules?

Thanks

I think this is something to file an issue over on the Eclipse Smarthome github:

Thanks for your answer Rich
I’m not using eclipse/smarthome but Visual Studio Code with the openHAB extension.
So you think it is an error in the validation. That looks logic as the rule works :slight_smile:
In opneHAB extension documentation I see:

This extension comes with Language Server Protocol support. Language servers allow you to add your own validation logic to files open in VS Code. openHAB from version openHAB 2.2.0 Build #1065 (SNAPSHOT) has the Language Server exposed on 5007 port. openHAB 2.2 since build #1084 has LSP feature enabled in the runtime, so there are no additional steps for you to make it work.

Looks like OpenHAB has a language server and the “error” should be there.
I see there is a github page for that.
I’ll try to put an error report there.

Thanks anyway

Eclipse Smarthome is the basis upon which OH is built and where this code resides. You are thinking of ESH Designer which is completely separate.

Nope, it is a problem with the Rules Engine.

Wrong place. My original link is the correct place. That is where the Rules Engine is implemented.