Exec binding script does not work when turning off [Solved]

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: Raspbian GNU/Linux 9
    • Java Runtime Environment: openjdk version “1.8.0_152”
    • openHAB version: 2.4.0 Release Build
  • Issue of the topic:
    I created a script to wake my PC using Wake on LAN and suspend it (hibernate).
    When I execute the script from the command line everything works fine, passing “on” as a parameter turns the PC on, passing “off” as a parameter turns the PC off, and passing “status” as a parameter correctly displays the status of the PC (off for a while, while booting up, on when done)

However when I create a Thing with the exec binding only the “on” and “status” part work. I directed some log messages to a file in the “off” section and they are appended to the file correctly, but the hibernate command does not seem to come through.

here is the script:


case "${1}" in
                exec sudo etherwake $MAC_ADDRESS &> /dev/null

                date >> /var/log/pascal.log
                echo "PC off " >> /var/log/pascal.log
                whoami >> /var/log/pascal.log
                echo "timeout 3 sshpass -p $PASSWORD ssh $USERNAME@$IP_ADDRESS shutdown /h " >> /var/log/pascal.log
                echo "$PATH" >> /var/log/pascal.log
                echo "" >> /var/log/pascal.log

                exec timeout 3 sshpass -p $PASSWORD ssh $USERNAME@$IP_ADDRESS shutdown /h &>/dev/null

                timeout 1 ping -c 1 -n $IP_ADDRESS &>/dev/null
                if [ $? -eq 0 ]; then
                        echo "ON"
                        exit 0
                        echo "OFF"
                        exit 1

                echo "Usage: pascals_pc <on|off|status>"
                exit 1

exit 0

I placed it in /usr/local/bin/ and added ALL ALL=NOPASSWD: /usr/sbin/etherwake to my sudoers file using visudo

  • Please post configurations (if applicable):

    • Things configuration related to the issue

      Thing exec:command:pascals_pc "Pascals PC Control" [ command="/usr/local/bin/pascals_pc %2$s", interval=0, timeout=10, autorun=true ]
      Thing exec:command:pascals_pc_status "Pascals PC Status" [ command="/usr/local/bin/pascals_pc status", interval=20, timeout=5 ]
    • Items configuration related to the issue

      String network_device_pascals_pc_control "Pascals PC Control" { channel="exec:command:pascals_pc:input", channel="exec:command:pascals_pc_status:output", autoupdate="false" }
      String network_device_pascals_pc_status "Pascals PC Status" { channel="exec:command:pascals_pc_status:output" }
      Switch network_device_pascals_pc_switch "Pascals PC" ["Switchable"]
    • Sitemap configuration related to the issue

      sitemap test label="My home automation" {
          Frame label="Test Frame" {
              Switch item=network_device_pascals_pc_switch
    • Rules code related to the issue

      rule "Pascals PC Switch"
              Item network_device_pascals_pc_switch changed
              logInfo("Network", "Switching Pascals PC " + network_device_pascals_pc_switch.state.toString + ": " + network_device_pascals_pc_control.state.toString)
      rule "Pascals PC State"
              Item network_device_pascals_pc_status changed
              logInfo("Network", "Switching Pascals PC " + network_device_pascals_pc_status.state.toString + ": " + network_device_pascals_pc_control.state.toString)
  • If logs where generated please post these here using code fences:
    None besides the output from the rule

Well in an effort to not look stupid I tried to fix the problem myself one last time. As it turns out I am stupid and someone created a post for stupid people like me: How to solve Exec binding problems .

My openhab user did not have my PC in its known host file. So I copied the file from the openhabian user.