ExecuteCommandLine to move files

Since it has been proven that the new Amazon Echo binding items slow down the system to a crawl, I’m trying to programmatically enable/disable them by moving the amazon.items file out of the items directory when not needed and move them back if needed (e.g. If SceneSelector=100/Party enable the items so I can stream through my living room Echo)
I have created two scripts (e.g. “mv /etc/openhab2/items/unused/amzn.items /etc/openhab2/items/” ) but I’m struggling with permissions. If I try adding the “sudo -u openhabian” in the script I get a banner from sudo and if I don’t the script fails with Permission Denied.

Any help will be much appreciated

This is the THINGS:

Thing exec:command:yourcommand [ command="/home/openhabian/OHScripts/AMZN.sh %2$s", interval=0, autorun=false ]

This is the SH script:

if [ “$1” = “Enable” ]
sudo mv /etc/openhab2/items/unused/amazon.items /etc/openhab2/items/
sudo mv /etc/openhab2/items/amazon.items /etc/openhab2/items/unused

This is the ITEMS:

Switch YourTrigger
Switch yourcommand {channel=“exec:command:yourcommand:run”}
String yourcommand_Args {channel=“exec:command:yourcommand:input”}

This is the RULES:

rule “Your Execution”
Item YourTrigger changed
if(YourTrigger.state == ON){
logInfo(“Your command exec”, “Enable”)
logInfo(“Your command exec”, “Disable”)

Have you simply tried without the sudo part of the command?


The exec binding might be able to execute these commands for you.

I certainly don’t have issues with permissions when I move files between folders that the openHAB user has rights to.

Does that work? i.e. removing an xxx.items file after openHAB has already read it, makes the Items disappear from registry? (How would it know which Items to remove, I wonder)

Yes the items are immediately removed from registry and you will see a huge improvement immediately

Since you are stating that this has been ‘proven’ I guess it wouldn’t be difficult to point me toward more information about this issue.

Andrew, hereafter the articles I should have mentioned in my opening post.

Anyway, if you have the binding enabled, try having one thing/item/channel configured and the access http://yourip:8080/rest/items with and without the thing and notice the difference

Can you share an example of the scripts? I tried following the example in the documentation to no avail :frowning:

I guess it is the same mechanism that detects a change in a .items file, indeed if you look at the logs (I always have frontail’s page open during changes) you can see the items being added/removed

Honestly, I don’t use scripts.

If I were trying what you’re looking for, I’d just put this pair of commands in Exec binding Things and fire each one as required, by linking the Run channel

mv /etc/openhab2/items/YOUR_FILE.items /etc/openhab2/items/YOUR_FILE.remove

mv /etc/openhab2/items/YOUR_FILE.remove /etc/openhab2/items/YOUR_FILE.items

Or, I’d use a execureCommandLine in a rule

if(YourTrigger.state == ON){
executeCommandLine("mv /etc/openhab2/items/YOUR_FILE.remove /etc/openhab2/items/YOUR_FILE.items", 500)


executeCommandLine("mv /etc/openhab2/items/YOUR_FILE.items /etc/openhab2/items/YOUR_FILE.remove", 500)


Or better

executeCommandLine("cp /etc/openhab2/items/YOUR_FILE.backup /etc/openhab2/items/YOUR_FILE.items", 500)

executeCommandLine("rm /etc/openhab2/items/YOUR_FILE.items", 500)

link 1 link 2
have read both threads and see no reference to ‘Echo binding items slow down the system to a crawl’

I do have the binding enabled. What type of difference do you see when you perform the above procedure?

Have you considered simplifying file move to file rename, xxx.items to xxx.saved and back. Less permissions to worry about.

I use Habpanels on my rpi3 or phone and the loading of the dashboards is extremely slow and many times it shows LOST CONNECTION at bottom-left of the dashboard.
Also if you try with any REST browser (I use ARC as a Chrome extension), you will notice that performing a GET on http://x.x.x.x:8080/rest/items takes from 500ms WITHOUT to 6-7 sec WITH those items enabled

Something was wrong with the installation I guess, after reinstalling OH now the executeCommandLine works…go figure

1 Like

I use HabPanel as well

@s1r is totally correct!!!
Anyone running the Amazon Echo binding needs to try this!!!
Renaming the file that contains my Amazon Echo items from .items to .BAK

GET request to OpenHAB REST api on host machine
no Amazon Echo items = 11 ms
with Amazon Echo items = 1300 - 1700 ms

I know the Amazon Echo binding uses the web api, is this all down to internet latency?

@michi are you aware of this?

1 Like

So far I have isolated the following slow items:

  • title
  • musicProviderId
  • amazonMusicPlayListId

I have now placed them into an amazon_slow.items file that I keep in the /etc/openhab2/items/backup directory and move them into /items only when I need to use that given echo device. Same thing has to be done for the .things file

I have a SceneSelector item that when =100 moves the file, turns on some lights and starts a Party playlist.

1 Like

Hi, I also cannot mv a file or cp and rm due to permission errors.

sudo -u openhab mv file1.sh file2.sh

I already added openhab to sudoers as mentioned here.
So for adding the user openhab with no password:

 sudo visudo -f /etc/sudoers.d/010_pi-nopasswd

I added


I also added directly into sudo visudo

openhab ALL=(ALL:ALL) ALL

What am I missing? I am able to execute through executeCommandLine python scripts but when I use a library to move such as shutil shutil.mv I return to same issue of permission errors.