I installed rc switch on my raspberry pi where openhab is also hosted. I can control my rc switch using the following code and logged in as root:
On:
/opt/rcswitch-pi/send 00001 5 1
Off:
/opt/rcswitch-pi/send 00001 5 0
This works perfect. When I am logged in as Pi user I have to modify it a bit:
On:
sudo /opt/rcswitch-pi/send 00001 5 1
Off:
sudo /opt/rcswitch-pi/send 00001 5 0
So now I would like to control it using Opnehab. I use this code in the home.items file:
you can include sudo to it as well yes. it really depends on who is the owner on the prog you are calling within the script. if this requires root - then yes you would need to include sudo.
As I mentioned in my first post, from command line it works with sudo, but not from openhab for any reason. Also tried your workaround with rules and scripts from openhab, still no operation. This is really sad that it is so difficult to let openhab just execute simple commands. I mean if it just can´t operate some easy commands for a first try, I don´t think I should stay with this solution and maybe switch to domoticz for example. But maybe we´ll find a way to make the rc switch work…
i use scripting and calling shell scripts out of openhab very often and it works smart.
Could you pls share more details from your log files? Is the script call shown in the debug log file? is there any entry at all? If so could you pls post the details from log relevant to that switch and the call of the script?
Alternatively could you probably instead of calling the switch action just create a simple shell script that is putting the content of directory into a file like:
dirList.sh:
ls -al > content.txt
to check if this works at all. my view is that mostly it is because of the user access rights on the script to call from OH.
When trying to execute as user pi from shell I already get an error:
sudo: dirList.sh: command not found
Here you can find my logfiles:
events.log:
2015-09-04 13:17:47 - Light_FF_Test received command ON
2015-09-04 13:17:48 - Light_FF_Test received command ON
2015-09-04 13:17:52 - listDir received command ON
2015-09-04 13:17:54 - listDir received command OFF
2015-09-04 13:20:07 - listDir received command ON
2015-09-04 13:20:08 - listDir received command ON
2015-09-04 13:21:14 - listDir received command ON
2015-09-04 13:21:15 - listDir received command OFF
openhab.log:
2015-09-04 13:09:41.594 [INFO ] [penhab.io.rest.RESTApplication] - Stopped REST API
2015-09-04 13:09:46.429 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Stopped Classic UI
2015-09-04 13:11:23.345 [INFO ] [.o.core.internal.CoreActivator] - openHAB runtime has been started (v1.7.0).
2015-09-04 13:11:44.922 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - mDNS service has been started
2015-09-04 13:11:46.199 [INFO ] [o.o.i.s.i.DiscoveryServiceImpl] - Service Discovery initialization completed.
2015-09-04 13:11:49.437 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'db4o.persist'
2015-09-04 13:11:52.870 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'rrd4j.persist'
2015-09-04 13:11:53.084 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'logging.persist'
2015-09-04 13:11:53.441 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'exec.persist'
2015-09-04 13:11:54.007 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.items'
2015-09-04 13:12:17.592 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'home.sitemap'
2015-09-04 13:12:21.790 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'switchOn.script'
2015-09-04 13:12:33.308 [INFO ] [penhab.io.rest.RESTApplication] - Started REST API at /rest
2015-09-04 13:12:40.017 [INFO ] [.o.u.w.i.servlet.WebAppServlet] - Started Classic UI at /openhab.app
2015-09-04 13:12:52.846 [INFO ] [.service.AbstractActiveService] - NTP Refresh Service has been started
2015-09-04 13:12:53.129 [INFO ] [.service.AbstractActiveService] - HTTP Refresh Service has been started
2015-09-04 13:12:55.767 [INFO ] [c.internal.ModelRepositoryImpl] - Loading model 'switch.rules'
2015-09-04 13:17:37.445 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:17:40.645 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:17:40.658 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:17:40.668 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:17:47.545 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:17:47.637 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:17:47.648 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:17:47.658 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:17:57.654 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:18:07.750 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:20:02.931 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:20:02.941 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:20:02.960 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:20:07.958 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:20:08.032 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:20:08.052 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:20:08.060 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:20:18.061 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:20:28.144 [INFO ] [c.internal.ModelRepositoryImpl] - Refreshing model 'home.items'
2015-09-04 13:21:10.083 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:21:10.100 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:21:10.120 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:21:14.216 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:21:14.237 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
2015-09-04 13:21:14.246 [ERROR] [o.u.i.items.ItemUIRegistryImpl] - Cannot retrieve item Date for widget org.openhab.model.sitemap.Text
Thanks for your help so far!!
edit:
I can run dirList now after chmod and chown:
-rwxrwxrwx 1 pi root 46 Sep 4 13:26 dirList.sh
user pi can´t run the script! Also not using sudo: