Orderly shutdown?

Hi all,
I’m using OH to control my home theatre (KODI, FireTV, AVR, several lights controlled by media player state etc). I’m searching for a reliable way to shutdown; only way I’ve found is via openhab.service:


1.) added line to openhab.service:
  ExecStart=/usr/share/openhab/runtime/bin/karaf  ${OPENHAB_STARTMODE}   ## OH3 start 
  ExecStop=-/home/dietpi/OH3-shutdown.sh                                 ## set SHUTDOWN_SWITCH=ON
  ExecStop=/usr/share/openhab/runtime/bin/karaf   stop                   ## OH3 stop

2.) bash> cat /home/dietpi/OH3-shutdown.sh #secured for user openhab to execute
  #!/bin/bash
  # set shutdown switch ON -> invoke shutdown rule
  curl -X POST --header "Content-Type: text/plain"                       \
               --header "Accept: application/json"                       \
                -d "ON"                                                  \ 
				"http://127.0.0.1:8023/rest/items/SHUTDOWN_SWITCH"       # port 8023 in my OH config
  sleep 3s ## wait 3 secs to allow rule "ORDERLY_SHUTDOWN" to be exexuted
  #

3.) Rules file:
  rule "ORDERLY_SHUTDOWN"
    when
      Item SHUTDOWN_SWITCH changed to ON
    then
      logInfo("SHUTDOWN", "SHUTDOWN in progress !")
      // other shutdown statements (max 3 seconds to run )
      // before rule execution stopped by "/usr/share/openhab/runtime/bin/karaf stop"
    end

I’m looking for a more reliable solution as OH is overwriting openhab.service with every (milestone-) release.
Any ideas on that?
Thank you very much in advance.

btw: I’m also using ExecStartPre|ExecStartPost|ExecStopPost in openhab.service

You can also setup another systemd service and make its start/stop dependent on the openhab.service (or any other).
But it’s unclear what you want to achieve. Shutdown your home cinema? OH?
Your post is confusing.

Yes, I want to shutdown/reset my whole home cinema equipment BEFORE OH does the shutdown of rule engine (like media lights off, main light on, AVR/media player shutdown, mqtt cleanup/LWT etc).
I’m simply searching for a way to fire a rule on shutdown as system shutdown rule triggers are no longer supported in OH3.

You’ve already started on the wrong track. OH is supposed to run 24/7. No need to shut it down.

2 Likes

I was confused by the post as well. If I had to restart OH for some reason, I would want it to NOT affect other equipment.

Perhaps this is an XY Problem. Why do you want to shutdown the cinema equipment before OH shuts down? Maybe there’s a better way to achieve the end goal without messing with .service files and such.