OH3 Rules / Scripts and CommandLine

  • Platform information:
    • Hardware: Intel i9 9900 with 32GB of memory
    • OS: Arch Linux
    • Java Runtime Environment: Zulu Embedded 8 Java 11 OpenJDK
    • openHAB version: OH3 3.10 Snapshot
  • Issue of the topic: Executing command-line from a Rule/Script.

I am creating a rule that is supposed to execute a command when a switch changes status.

I’ve created a switch item to control my Roku. The switch seems to work just fine as it is toggling across all devices and updating.

I created a rule that is supposed to execute a command when the state changes however, nothing happens when I flip the switch.

I have tried creating the rule in /etc/openhab3/rules/home.rules and creating the script on the web UI. Both cases don’t work.

Here is what I have tried in /etc/openhab3/rules/home.rules:

rule "Roku On"
    when
            Item rokuPower received command ON
    then
            executeCommandLine(Duration.inSeconds(5), "curl -d '' http://192.168.1.33:8060/keypress/Home")
    end

In the rule creator UI web tool, I create the rule like the following:

triggers:
  - id: "1"
    configuration:
      itemName: rokuPower
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - id: "2"
    configuration:
      type: application/javascript
      script: executeCommandLine(Duration.inSeconds(5), "curl -d ''http://192.168.1.33:8060/keypress/Home")
    type: script.ScriptAction

Here is a screenshot of the UI:

Are there any known issues with sending commands to command line or am I completely doing this wrong? Thanks, and any help is appreciated.

First of all OH3 requires Java 11

I would have guessed it needed to be under /etc/openhab/rules

no more conf folder?

Thanks for the responses, I am not sure how I got the wrong Java version, but zulu-embedded-8 was wrong because OH3 wouldn’t even start with that (I had that installed for OH2)… I am running Java 11 OpenJDK.

[root@banshee openhab3]# archlinux-java status
Available Java environments:
  java-11-openjdk (default)
  java-14-openjdk
  zulu-8
  zulu-embedded-8

As for the configuration folder/location; /etc/openhab/rules doesn’t exist nor does it work, however, when I add to /etc/openhab3/rules/home.rules, the rules populate in the web UI.

To further clarify, other switches and rules are working, just not rules with command line execution.

Problem solved. The commands weren’t whitelisted.

Sorry typo. I thought they got rid of the version number in the folders.