Error that I don't understand

SD card degradation? Maybe try a new one!

Can you set the ..internal.engine.ExecuteRuleJob log to trace? Find out the whole name by setting the log to more characters. And also ..internal.engine.ExecuteRuleJob

For karaf you can specify the patern it in the console or in the file /var/lib/openhab2/etc/org.apache.karaf.log.cfg.
For file based logging /var/lib/openhab2/etc/C

you can then specify the log level with Karaf or also in the /var/lib/openhab2/etc/

So I think I worked it out.

By changing ‘now’ to now.millis I changed the object from a datetime object to a long value.

.isAfter is not part of the long class (as the error suggested) so I changed now.isAfter(start) to now>start
basically

so comparing to long values which is fine.

Which made me wonder, if I hadnt set up the start and stop time values as .millis in the first place they probably wouldve been datetime objects and worked straight away…

I was going to try to fine out but will double check this is working correctly first and make sure the schedules actually change state as expected. At least then I know I have a working platform.

Cheers for you help, and hopefully the SD isnt a problem, I might take another image just to be safe!!

Ive rebooted the pi and now have a new error…

2018-02-24 10:24:00.025 [INFO ] [model.script.Heating Occupancy Start] - Occupancy_Times-1519467840016-1519450200000
2018-02-24 10:24:00.027 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'HWS Demand Check': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null
2018-02-24 10:24:00.032 [INFO ] [model.script.Heating Occupancy Start] - Occupancy_Start
2018-02-24 10:24:00.065 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'Heating Occupancy Check': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.LongExtensions.operator_greaterThan(long,long) on instance: null
2018-02-24 10:24:00.085 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'HWS Occupancy Check': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.LongExtensions.operator_greaterThan(long,long) on instance: null

The first log is showing the now.millis and start.millis.
The second log is from a different rule file, again it makes no sense because Im not actually using any string object but thats a seperate issue.
The third log is the start of the occupancy rule.

The last two errors are the new ones, which appears to say it cant compare two long values, but I dont know what the instance of ‘null’ is.

Ive not used karaf before but have managed to log into it and now have no idea how im supposed to use it lol
Are there any guides available?

https://docs.openhab.org/administration/console.html

https://docs.openhab.org/administration/logging.html#karaf-console

I checked the output in karaf and its the same as in the log file. Im seeing the warning/error messages so I dont know what else I need to look for.

Ive been messing around with it for a while and Im not getting any error messages.

Ive just tried restarting the service and have noticed this error now

2018-02-25 16:24:15.088 [WARN ] [el.core.internal.ModelRepositoryImpl] - Ignoring file 'occupancy.rules' as we do not have a parser for it.

could this be a formatting issue? I have seen in the past that I would need to open a file in vim and set its format. I normally use nano.

It still seems to run through after this though so I dont know how important this message is.

Otherwise Im out of ideas with what to do now other than through this all in the bin.

So you created the file with nano? And never opened it from Windows and saved it?

Then it should be ok.

Maybe just open it and save it so it gets reloaded. Watch the log in parallel so you see the massages.

The Null errors after a restart can come from items which have not been initiated with a value. For this you can use persistence or the system started rule.

I have set all values to write upon startup to eliminate any null values.

I only open and save with nano but did see an issue once or twice about formatting so change it with vim but that was related to a python script I was calling from the exec binding.

I worked out how to extend the number of characters in the log and here is the full path of the error

2018-02-25 19:06:10.347 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule 'HWS Demand Check': An error occurred during the script execution: Could not invoke method: org.eclipse.xtext.xbase.lib.ObjectExtensions.operator_plus(java.lang.Object,java.lang.String) on instance: null

what I dont get is where am I asking the rule to add an object and a string together?
Ive tried nulling out the logging lines but these are copies of other logging lines in the other rules (except for simple name changes)
and that first log isnt even showing after the temp><setpoint lines…

rule "HWS Demand Check"
when
        Time cron "0 * * ? * *"
then
        if(Temperature_HWS.state > HWS_Setpoint.state){
                logInfo("HWS Demand","HWS Temp is HIGH"+Temperature_HWS.state+"/"+HWS_Setpoint.state)
                if(HWS_Demand.state != OFF){
                        HWS_Demand.sendCommand(OFF)
                        logInfo("HWS Status","Demand     - "+Heating_Demand.state)
                }
        }else if(Temperature_HWS.state < (HWS_Setpoint.state+HWS_Deadband)){
                logInfo("HWS Demand","HWS Temp is LOW"+Temperature_HWS.state+"/"+HWS_Off_Temp)
                if(HWS_Demand.state != ON){
                        HWS_Demand.sendCommand(ON)
                        logInfo("HWS Status","Demand     - "+Heating_Demand.state)
                }
        }
end

Do you use VSCode as editor with openhab extension. If not I encourage you to have a look, it helps avoiding doing mistakes.

Please post your rule how it is at the moment. I think maybe there where some changes which are not reflected by your first post.

I did have an error because I tried to change the line I thought was causing a problem, but reverted back to how it was before, the rule is posted above, the HWS_Setpoint is just a reminder at the top so I got the spelling and format correct. Its a number item from another file.

I havent used VScode, but is there any reason I cant on a headless pi? It looks like it has a GUI but I only connect SSH over the network.

I use net sftp to mount the drive from my rpi to my windows pc. And run VSCode in windows. There are sftp clients for every os or use samba which needs more configuration.

So basically, I see no reason you can’t use VSCode to edit the files on your headless pi.

Ive sorted VScode over sftp and could see lots of errors regarding comparisons or strings due to not being able to convert a .state to a .number which makes no sense to me as other .state items are being recognised as the numbers they are and they are in the same lines???

anyway, heres a snippet of the rules and I have declared the apparent string as a number as it seems to be working. Its now showing the log info of the proceeding lines so its processing past the line in question.

rule "HWS Demand Check"
when
        Time cron "0 * * ? * *"
then
        if(Temperature_HWS.state > HWS_Setpoint.state as Number){
                logInfo("HWS Demand","HWS Temp is HIGH"+Temperature_HWS.state+"/"+HWS_Setpoint.state)
                if(HWS_Demand.state != OFF){
                        HWS_Demand.sendCommand(OFF)
                        logInfo("HWS Status","Demand - "+Heating_Demand.state)
                }
        }else if(Temperature_HWS.state < (HWS_Setpoint.state as Number + HWS_Deadband)){
                logInfo("HWS Demand","HWS Temp is LOW"+Temperature_HWS.state+"/"+HWS_Setpoint.state+"/"+HWS_Deadband)
                if(HWS_Demand.state != ON){
                        HWS_Demand.sendCommand(ON)
                        logInfo("HWS Status","Demand - "+Heating_Demand.state)
                }
        }
end

so the benefit that VScode gave me was highlighting the line where the error was, but I have no idea why it is an error in the first place.

Any ideas?

another thing with vscode, it wouldnt let me save the file I had changed, so I had to copy it and paste it into the ssh terminal then save that way. Is there a way to get the privileges when trying to save? I couldnt see in the settings and couldnt see anything about it with a google.

Linux has a very strict file access permission policy.

Add your user in this case pi to the group openhab. For the group policy to have effect you must reboot.

sudo usermod -a -G openhab pi

Change all file permissions in the openhab folder to be read, write, execute for owner and group, and to be read and executable by all. This has to be repeated eg, when you install a new binding, the cfg for the binding will not have the permission set. I set the sgid bit to make the files and folders inherit the file permissions from the parent bu it seems not to work. I have not look into ACL managment which would be the next step.

sudo chmod -R 2775 /etc/openhab2

Now after reboot you should be able to edit and save the files.

The benefit of VSCode is, it helps a lot.

The Items are all object types. This means they are more then e.g. just a plain number. They have functions you can call and the information is store into them.

Contact  ContactItem
Switch   SwitchItem
String   StringItem
Number   NumberItem
DateTime DateItme

If you want to get the number from NumberItem you need to

var aNumber = NumberItem.state
var aString = StringItem.state

here you can see getting a state from a string can not compare with a state from a Number.
I don’t know how your Items where defined, so this is just an assumption.

Also the error when you hover over the red marked Variables will help you resolve this errors.

Type mismatch: cannot convert from State to Number

To put it simple, the runtime environment is sometimes able to guess what you intended to do but not always.

But explicitly converting the value from item state to a number object will solve that.

if( ( NumberItem_1.state as Number  ) > ( NumberItem_2.state as Number ) ){
    logInfo("Show me your number", NumberItem_1.state.toString )
}

To get into this you have also post your items file.

I have carried out these instructions but in VScode I still cant save the edits Im making in the openhab directory.

I can log in via SSH and make the changes then view in VScode to see if it gives me any errors. It works but it kinds of defeats the purpose.

Do you have any idea what it might be? In VScode I also keep getting the error that it cant connect to the rest API which I tried resolving using some instructions on this forum but it also didnt work unfortunately.

when trying to save an edit, VScode shows me an error ‘failed to save, retry as admin’ which then brings up a windows pop up window. So I dont tell if this is trying to escalate permissions in windows or on the pi??

also, after changing the permissions the files and folders were highlighted in yellow when I look in the terminal so I assume the permissions are different than before.

Thanks

Please post the output of the folders in etc/openhab and also one sub folder.

ls -l

You have to use the user pi and provide the password when connecting with sftp.

And here some info to setup VSCode

here is the output of ls -l

no idea what it means :grin:

total 44
drwxrwsr-x 2 openhab openhab 4096 Jan 10 21:25 html
drwxrwsr-x 3 openhab openhab 4096 Oct 25 10:52 icons
drwxrwsr-x 2 openhab openhab 4096 Mar 10 11:28 items
drwxrwsr-x 2 openhab openhab 4096 Jan 10 21:25 persistence
drwxrwsr-x 2 openhab openhab 4096 Mar 10 11:33 rules
drwxrwsr-x 2 openhab openhab 4096 Jan 10 21:25 scripts
drwxrwsr-x 2 openhab openhab 4096 Jan 10 21:52 services
drwxrwsr-x 2 openhab openhab 4096 Mar  9 21:34 sitemaps
drwxrwsr-x 2 openhab openhab 4096 Jan 10 21:25 sounds
drwxrwsr-x 2 openhab openhab 4096 Feb 19 11:03 things
drwxrwsr-x 2 openhab openhab 4096 Jan 19 20:15 transform

Thats only the folders, not the content of one folder. Means the files you want to edit. Please look in the items folder and list it.

The drwxrwsr-x are the user rights and they are as they schould.

You have to adjust the file setting for every new created file of openhab.
When you install a binding the new cfg will not have the file permisision to be access by pi.

So if this error occurs look at the file permission of this file. and change it accordingly.

Please look if the user pi is also in the group openhab, and restart!

groups
pi adm dialout cdrom sudo audio video plugdev games users input netdev openhab gpio i2c spi

In your rules, you should use Numbers variables.

rule "HWS Demand Check"
when
        Time cron "0 * * ? * *"
then
        var Temp = Temperature_HWS_state as Number
        var Setpoint = HWS_Setpoint.state as Number
        var Deadband = HWS_Deadband.state as Number // (I could see how you get your deadband value from so I assumed an Number Item)
        if(Temp > Setpoint){
                logInfo("HWS Demand","HWS Temp is HIGH"+Temp.toString() +"/"+ Setpoint.toString())
                if(HWS_Demand.state != OFF){
                        HWS_Demand.sendCommand(OFF)
                        logInfo("HWS Status","Demand - "+Heating_Demand.state.toString())
                }
        }else if(Temp < (Setpoint + Deadband)){
                logInfo("HWS Demand","HWS Temp is LOW"+Temp.toString()+"/"+Setpoint.toString()+"/"+Deadband.toString())
                if(HWS_Demand.state != ON){
                        HWS_Demand.sendCommand(ON)
                        logInfo("HWS Status","Demand - "+Heating_Demand.state)
                }
        }
end

OK that makes more sense.

Here the items folder

pi@raspberrypi:/etc/openhab2 $ ls -l items
total 24
-rwxrwsr-x 1 root    root     108 Mar  4 20:16 boiler.items
-rwxrwsr-x 1 root    root    1324 Mar  4 20:26 mqtt.items
-rwxrwsr-x 1 root    root    1312 Mar  4 20:23 occupancy.items
-rwxrwsr-x 1 root    root     767 Mar 10 10:28 presence.items
-rwxrwxr-x 1 openhab openhab  227 Mar  9 19:54 readme.txt
-rwxrwsr-x 1 root    root     904 Mar 10 10:34 setpoints.items

and for comparison, the rules files where I have added new files without updating the persmissions

pi@raspberrypi:/etc/openhab2 $ ls -l rules
total 36
-rwxrwsr-x 1 root    root    2473 Mar  4 20:10 boiler.rules
-rwxrwsr-x 1 root    root    3421 Feb 26 14:41 heatingdemands.rules
-rw-r--r-- 1 root    openhab 2055 Mar  9 21:33 heating.rules
-rwxrwsr-x 1 root    root    5370 Feb 26 14:22 occupancy.rules
-rwxrwsr-x 1 root    root     356 Jan 26 21:40 ovr.rules
-rwxrwsr-x 1 root    root     876 Feb  6 13:49 presence.rules
-rwxrwsr-x 1 openhab openhab  222 Jun 28  2017 readme.txt
-rw-r--r-- 1 root    openhab  754 Mar 10 11:07 setpoints.rules

and here is the pi groups

pi@raspberrypi:/etc/openhab2 $ groups pi
pi : pi adm dialout cdrom sudo audio video plugdev games users input netdev spi i2c gpio openhab

Worth noting too, I log in with the pi user account in SFTP net drive. I see owner of the file is root, does that mean that pi isnt being giving root access through SFTP? I cant see an option to escalate that persimission in SFTP. So next option, would be to always give the pi user root access?

na just change the group of the files.

To change the permissions on all the files and folders recursively from the folder you are in.

chown -R username:groupname * 

You can also specifiy the filepath.

sudo chown openhab:openhab /etc/openhab2/*

Thes will make all file belong to openab and the group openhab, as it should be, imho.

its working fine now thanks.

Just so I understand what happened…

changing the files/folders to be owned by openhab, and the pi user is in the openhab group, by logging in with pi in SFTP it is given the permissions to read/write/execute etc. Whereas before, the files/folders were owned by root, so pi did not inherit those permissions.

I am able to now make changes etc, but if I create a new file, I still need to SSH into the pi and update the permissions to be able to modify it in VScode.

One thing that I dont understand (but I dont think is important), when I change the permissions as described above

sudo chmod -R 2775 /etc/openhab2

The files are all highlighted in yellow.

When I changed the owner, the text was green, which I believe it what happens if you make a file executable??
after adding a new file and doing the sudo chmod business again, they are highlighted yellow again.
Regardless, this works for VScode. so maybe its necessary.

Thanks