Problem with rcswitch

Hi guys,

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:

Switch Light_FF_Test “Test Funksteckdose” (FF_Test, Lights) {exec=“OFF:/opt/rcswitch-pi/send 00001 5 0, ON:/opt/rcswitch-pi/send 00001 5 1”}

But this does not work. I see the command is received by openhab but the rc switch won´t act.

Any idea? Thank you!!

Hi,

i did solve this using the scripting engine within Openhab. I meanwhile moved to weMo switches - but what i think i did was.

I created shell scripts on my pi containing the commands - like

switchON.sh:

/opt/rcswitch-pi/send 00001 5 1

If you change the userrights to 777 or 766 you should not have an issue with the execution from the PI user.

Then i created a script in openhab designer (switchON.script):

executeCommandLine("sh /opt/openhab/configurations/scripts/switchOn.sh")

and then had created an item:

Switch "FunkSwitch"

and created a rule

rule FunkSwitchOff
when
	Item FunkSwitch received command OFF
then
        callScript("switchON")
end

might be a bit more elegant way to be done - but at least it worked for me.

cheers
Karsten

I created a script as you mentioned and changed userrights to

-rwxrwxrwx 1 pi root 47 Sep 4 10:35 switch.sh

When trying to execute as pi user I get this:

pi@openhab /opt/openhab/configurations/scripts $ ./switch.sh 5 1
wiringPiSetup: Must be root. (Did you forget sudo?)

So still does not work without sudo :frowning:

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.

Cheers
Karsten

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.

Cheers
Karsten

Hi Karsten,

I created a file dirList.sh:

#!/bin/bash
ls -al > /opt/openhab/content.txt

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:

pi@openhab /opt/openhab $ sudo ls -al > /opt/openhab/content.txt
-bash: /opt/openhab/content.txt: Permission denied

Only root user can run the script.
But now I can confirm that it runs from shell, but not from openhab. I added the following line to home.items:

Switch listDir    "Test list Dir"    (FF_Test)    {exec:"ON:sudo /opt/openhab/dirList.sh, OFF:sudo /opt/openhab/dirList.sh"}

doesn´t work with or without sudo

This item definition works for me:

Switch Send433_01100_A {exec=">[ON:/bin/sh@@-c@@ssh mirror -l pi sudo /opt/rcswitch-pi/send 01100 1 1] >[OFF:/bin/sh@@-c@@ssh mirror -l pi sudo /opt/rcswitch-pi/send 01100 1 0]"}

The ssh commands without passwords work because of ssh key authentication.

Gentlemen, the “Exec Binding” wasn´t installed…

it´s working now…

Thanks for your help! :slight_smile:

:smiley: ok - next timne i’ll ask that question first :smiley: