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