Error that I don't understand

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