Need help with error missing EOF at 'var'

I keep getting this error “missing EOF at ‘var’” on the first line of the following rule. What am I doing wrong?

var Number counter = 0
var Number lastcheck = 0

rule “Trigger Night Lights On”
Item multi_living_contact changed from CLOSED to OPEN
counter = counter + 1
// if(ntlt_enb.state == ON) {
if(scene_general.state == 3) {
sendCommand(light_kitchen_cabinets, ON)
sendCommand(light_living_dimmer, 25)
// }

rule “Trigger Night Light Off”
Time cron “0 * * * * ?”
if(lastcheck == counter) {
counter = 0
lastcheck = -1;
sendCommand(light_kitchen_cabinets, OFF)
sendCommand(light_living_dimmer, 0)
else {
lastcheck = counter

Do you have any rules defined before the 'var’s ? You have to (afaik) define all the “global” var’s in the beginning of the rules file.


That was it. The variables were not in the proper place. Thank you for the response. It worked fine with only set of variables. But failed when adding these. I bit of carry over of improper implementation from my initial setup.

Hi there

I am getting the same error (“missing EOF at switch”) in my rules definition. However, I have put the declarations into the first line of the rules file:


Any idea what is wrong here?

Thanks in advance!


You can’t define items (switch/dimmer/contacts etc.) in the rules file, only in the items files.
Take a look in the docs.

Ok, thanks. But deleting the definitions leads to another error:“The method or field SW_Global_Alarm is undefined”


How can I define variables of the Type “switch” in rules that are globally accessible within the entire rules file?

I tried to use the command “var SW_Global_Alarm” instead but then I get another error (“The method or field state is undefined for the type null”) when trying to access the state property of the switch.

Thank you!

Items that you define in either .items files or using PaperUI are globally available in all rules files. If you defined the switch item SW_Global_alarm using PaperUI then the error you see in the Designer is “normal” and can be safely ignored.
The Designer is not aware of any items which are defined using PaperUI. It only knows about items which are defined in items files.

The quick answer: You cannot define such an item in a rule; you will need to define it as an item in the PaperUI or in an .items file

Maybe you want to have a look here: and also at the great tutorials that are on the docs website

OK, now I got it! Thank you all!


1 Like