Running simple bash scripts with OpenHAB

  • Platform information:
    • Hardware: Raspberry Pi 1 B+ (512MB) {I know I should use a newer Pi, I just don’t have one at this location at the moment, SD card is brand new btw}
    • OS: Raspbian 9.9 (OpenHabian)
    • Java Runtime Environment: openjdk version “1.8.0_212”, OpenJDK Runtime Environment (Zulu8.38.0.163-CA-linux_aarch32hf) (build 1.8.0_212-b163), OpenJDK Client VM (Zulu8.38.0.163-CA-linux_aarch32hf) (build 25.212-b163, mixed mode, Evaluation)
    • openHAB version: openHAB 2.4.0 Release Build with the demo addons.cfg
  • Issue of the topic:
    I cannot seem to execute simple bash scripts using OpenHAB on my OpenHABian system. I wish to use OpenHAB to replace my Domoticz system at my parents’ place as it is more user-friendly when it comes to reconfiguring devices (lots of Domoticz stuff is hardcoded in my experience and I live far away; I want them to be able to reconfigure things by themselves if necessary). Most tutorials show that it’s easy to connect Philips Hue lights and other “smart” devices to an OpenHAB system, however I do not own any of these fancy devices and for the moment simply wish to use OpenHAB to execute my scripts to turn on and off 433MHz switches.
    I’ve posted about this before, but I gave up on my project quickly back then; I now want to give it another go.
    This is what I have tried so far:
    The exec binding is installed.
    I am using two simple scripts which use the WiringPi library to switch a light on and off respectively. These scripts, executed from the terminal over ssh, work. I chmod 777'd these scripts and made my system very vulnerable by sudo visudoing and giving everyone (root, openhabian, openhab, sudo, etc.) access to everything without requiring a password, as outlined in this post. It still doesn’t work. Looking at the logs gives me no real explanation of what could be wrong.
    I understand I must add something to the rules (executeCommandLine) but it is unclear to me what format this should be in as there is conflicting information on the forum regarding this (seen here).

I really would like this to work so that I get deeper into OpenHAB and turn these dumb switches into part of a smart home which is modular and mimics human behavior.

  • Please post configurations (if applicable):
    • Things:
      Thing exec:command:switchOff [command="/opt/rc-switch/"]
      Thing exec:command:switchOn [command="/opt/rc-switch/"]
    • Items configuration related to the issue
      Switch LampOff "Lamp Off" <switch> (GF_Living, Lights) {channel="exec:command:switchOff:input"}
      Switch LampOn "Lamp On" <switch> (GF_Living, Lights) {channel="exec:command:switchOn:input"}
    • Sitemap configuration related to the issue - did not alter the demo sitemap, my switches show up in the demo Basic UI.
    • Rules code related to the issue - again, did not alter this, the reason being that I find the instructions online and on the forum conflicting and I do not know what should be entered here.
    • Services configuration related to the issue - did not edit.
  • If logs where generated please post these here using code fences:
    What I found which may pertain to my problem:

(I’m not using REGEX atm afaik, will be useful in the future but now everything is (ashamedly) hardcoded)
2019-07-22 23:32:53.623 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable

2019-07-22 23:32:53.634 [WARN ] [hab.binding.exec.handler.ExecHandler] - Couldn't transform response because transformationService of type 'REGEX' is unavailable

2019-07-22 23:32:58.363 [hingStatusInfoChangedEvent] - 'exec:command:switchOff' changed from ONLINE to UNINITIALIZED

2019-07-22 23:32:58.406 [hingStatusInfoChangedEvent] - 'exec:command:switchOff' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)

2019-07-22 23:32:58.449 [hingStatusInfoChangedEvent] - 'exec:command:switchOn' changed from ONLINE to UNINITIALIZED

2019-07-22 23:32:58.489 [hingStatusInfoChangedEvent] - 'exec:command:switchOn' changed from UNINITIALIZED to UNINITIALIZED (HANDLER_MISSING_ERROR)

2019-07-22 23:32:58.985 [temChannelLinkRemovedEvent] - Link 'LampOff => exec:command:switchOff:input' has been removed.

2019-07-23 01:11:14.229 [ome.event.ItemCommandEvent] - Item 'LampOn' received command ON

2019-07-23 01:11:14.315 [nt.ItemStatePredictedEvent] - LampOn predicted to become OFF

And finally, while I am not using HomeKit at the moment and I believe it to be irrelevant to the current problem, I keep getting this error:

==> /var/log/openhab2/openhab.log <== 2019-07-22 23:32:51.483 [ERROR] [core.karaf.internal.FeatureInstaller] - Failed installing 'openhab-persistence-rrd4j, openhab-transformation-map, openhab-misc-homekit, openhab-misc-restdocs, openhab-misc-hueemulation': Error: Error downloading

You need to tell the exec binding under what circumstances you would like it to run the script, as in the documentation.

Presumably you do not want a periodic run, so you’d set interval to 0

It looks like you want it to run when you send a command to the input channel, so you’d set autorun to true

Thing exec:command:switchOff [command="/opt/rc-switch/", interval=0, autorun=true]

It’s smart to use the timeout provided, to prevent a faulty script hanging up the exec binding forever.

Thing exec:command:switchOff [command="/opt/rc-switch/", interval=0, autorun=true, timeout=5]

Using two separate things and two separate switches for on/off is a bit clumsy. Once you’ve got it working in this way, you might want to look into enhancing your script so that it can accept a parameter.