Configuration model 'test.rules' is either empty or cannot be parsed correctly!

rules
oh2
cron
Tags: #<Tag:0x00007fe057b26148> #<Tag:0x00007fe057b25f68> #<Tag:0x00007fe057b25dd8>

(Rich Koshak) #6

OK, this is pointing to one of the following:

  • There is a special character or something like that floating around in that file. Try creating a brand new file and type in (don’t copy) the code over. Use a native editor on the machine where OH is running (nano, vi, Notepad, Notepad++).

  • Corrupt or failing file system. If you are on a Raspberry Pi errors like this can point to a failing SD card.

  • Raspberry Pi with insufficient power supply.

Just to be clear. There is nothing syntactically wrong with the rule as posted.


(p0lar) #7

remember it works the first time i change the file after a OH2 restart. and subsequent changes are flagged empty. sounds like a variable not getting cleared.


(Rich Koshak) #8

I’ve seen plenty of people report errors that rules files are not loaded at all. I’ve never seen one where it loads the first time and fails after subsequent reboots EXCEPT for one time and the cause was a failing SD card.


(p0lar) #9

found a single extra space after the “when” removed it and now its clean

Hmmm


(p0lar) #10

ok new info. when I use notepad++ to edit the file on my ubuntu server installed on a VM HD it gives me the error with just adding blank line at the end of the file. if i make the SAME change in vi directly it works clean… looks like Notepad++ is adding something


(Rich Koshak) #11

What encoding are you using in Notepad++?

Have you considered using Designer? At a minimum I strongly recommend Designer to check the syntax of your files when you run into problems.

An extra space in any of those locations should not be causing any problems.


[SOLVED] Cannot get rules to work, OH2.2, Windows
(wolf_from_the_north) #12

very intresting as i a seeing the same thing.
curious if anyone solved this yet.

kindest regards


(p0lar) #13

i have tried designer but i dont think its been upgraded for OH2 right? it doesn’t feel like it.

it doesn’t even recognize sendMail as a rule command.

am I using it wrong? the .8 version


(lipp_markus) #14

Don’t think you are doing anything wrong. The .8 version does not recognize all syntax (such as your sendMail example), but it is still better than nothing for me. 0.9 version seems to remain broken and no fix is insight as far as I know. Just ignore the few syntax warnings (in my case not that many).

By the way I do get this error “…empty or cannot be parsed correctly!” on a lot of my conf files. I exclusively use designer, but still. However, the upside, this error does not seem to impact any functionality of OH2.
I just hope that these ‘little’ errors and inconveniences (and there are a lot of "just ignore’ and undocumented tips and tricks) do not add up to that many that the whole project will become balked down by it.


(Erkan Balci) #15

Well whenever i make changes and save in OSX Textwrangler or Windows Notepad++ or designer, i have these errors not only on rules file but also on items and some other config files. What i do is i open the file in “vi” and :wq, save and exit. Then it accepts the file without an error. Still cannot understand what is the real problem.


(Erkan Balci) #16

OK, at last i found the problem for my situation. In the rules file, there should be no whitespaces, either space or tab at the end of each and every line, and at the end of the file. So, check every line for the extra spaces at the end, remove them, and also at the end of the file remove any empty lines. Now it works with TextWrangler, Notepad++ and Designer without any problems.


(Jens W.) #17

Just in case anyone is reading this looking for a solution and the above didn’t help: I have additional information.

I’ve been scratching my head over this for a long time now. I’m running openHabian and am using a Mac and VS Code. Even after scouring my .rules files for blank lines or extra spaces this error just wouldn’t go away. Then it dawned on me that it might be some problem with file encoding. I then did the following for every file, using VS Code:

  • Copied the code
  • Created a new file (right click on rules folder --> New File)
  • Pasted the code and saved the file
  • Deleted the old file

And the error message was gone!

Copying the files did not solve the problem btw… I had to create new ones.

EDIT:

I’m sorry to say that this does not solve the problem after all. :frowning:

But there is definitely something strange going on here. The “copy & paste to a new file” trick seemingly works at first. The file is then saved without openHab logging the error. Subsequent presses of Ctrl + S lead to the single log entry

2017-11-26 23:08:47.623 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'xyz.rules'

So… still no error. Removing any character in VS Code, adding it again (so, in effect, no change) and pressing Ctrl + S leads to:

2017-11-26 23:06:36.346 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'xyz.rules'
2017-11-26 23:06:36.357 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'xyz.rules' is either empty or cannot be parsed correctly!
2017-11-26 23:06:36.796 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'xyz.rules'

Strange.


(Paul Muldoon) #18

I get the same thing and often ignore it although would love to get rid of these warnings. I just tried creating a new rules file with VSCode and get the same empty parsing error with rule.

rule "Testing Rules"
when
    System started
then
    sendCommand(FF_Light_FamilyRight, OFF)    
end

No extra spaces or anything that I can see that would result in the Warning.


(lipp_markus) #19

I guessing you are accessing your files remotely through Samba. If so, please rest assured that this is an issue caused by Java that is benign and does not cause any trouble. If you search the forum you can find more technical explanations, but in a nutshell, the rules file is read immediately when it is touched by the file system, and at that point, the write process (when you save a file) is not yet finished, which then causes the warning. However, when the write process has ended your file is read again, this time successfully (except for user errors of course :slight_smile: ) and you can see the corresponding log messages immediately following the warning. Apparently a feature connected to Java and hence it will likely stay like this forever. SImply put: just ignore it. Hope that helps.


Persistence file error openhab 2.1
(Daniel) #20

Hi

I copied a very easy rule from OH1 to OH2, the items haven´t changed since then:
rule
"Weihnachtsbeleuchtung"
when
Item Schuko_OG_Gang received command ON
then
sendCommand(Fenster_riesig_l, 0)//0
end

In OH1 the rule was executed without any problems, but no, nothing happens, Schuko_OG_Gang turns on but that is all. In the logs i get the following:
2017-12-28 17:21:39.010 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model ‘Weihnachtsbeleuchtung.rules’

2017-12-28 17:21:39.039 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Weihnachtsbeleuchtung.rules’ is either empty or cannot be parsed correctly!

2017-12-28 17:21:39.251 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘Weihnachtsbeleuchtung.rules’

I don´t see the mistake. Can you please give me a hint?
THX
Daniel


(Rich Koshak) #21

The warning you see in the logs is normal. You are probably editing your file over SAMBA or using one of the many text editors that generate two file system events when you save your file. When you see “Loading model …” without an error or warning immediately after your file loaded successfully.

Check events.log to verify that Schuko_OG_Gang is actually receiving the command.

Add a logInfo as the first line of your rule to verify whether the Rule is triggering or the problem is with your sendCommand.

And in the future please use code fences so your rules and logs are easier to read:

```
code goes here
```

(Joakim östberg) #22

I have the same issue, and I can’t find any errors to my code:
// Imports
org.eclipse.smarthome.core.items
org.eclipse.smarthome.core.persistence
org.eclipse.smarthome.core.library.types
org.eclipse.smarthome.core.library.items
org.eclipse.smarthome.model.script.actions

rule “Wallplug_FF_LR_TV ON”
when
Item GF_Kitchen_Light changed from OFF to ON
then
GF_LivingDining_Power.sendCommand(ON)
end

I’m running openHab as a docker. could that be a problem here? If the dockers are using the pointed out folders (cond and userdata) using a samba protocol.

Here is the logs:
2018-03-22 11:55:42.777 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘test2.rules’
2018-03-22 11:55:42.779 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘test2.rules’ is either empty or cannot be parsed correctly!

And the simple rule isn’t working…


(Vincent Regaud) #23

Hi,
Can you remove the imports, you don’t need them.
Can you post the rule code in rules codes fences, please?

Thanks


(Andreas Imhof) #24
  1. remove the imports at the beginning
  2. If you are changing the files via samba share, then there should be a third line in the logs saying "Loading model ‘test2.rules’ "
  3. use a logInfo as mentioned before:
  1. check if “GF_Kitchen_Light” and “GF_LivingDining_Power” are Switch items…

Andreas

PS: most of possible solutions are written in the 20+ posts before. Please read carefully the posts and try to find the solution before asking the same questions again and again… If there is still a problem please feel free to describe what you have done so far and what the error is…


(Joakim östberg) #25

Thanks for the help. I got it working now.
The item had a duplicate with a similar name, my bad.