I have a Admin section in my UI to do some basic OH tasks like Backups, Restarts etc.
I have them working fine, but I’m wondering how I can automatically send a postupdate/send to OFF, once the command has been executed?
If I have a rule, would the preferred approach just be a sleep, then a postupdate command?
E.G:
rule "Restart Server"
when
Item restartserver changed to ON
then
executeCommandLine("sudo -u openhab sudo shutdown -r now")
restartserver.postUpdate(OFF)
end
You can create a file in the filesystem if the pc really reboots. Check inside of OH if the file exists after starting of OH (rule trigger systm started) and set the item to OFF.
rule "Restart OH2"
when
Item restartoh2 changed to ON
then
executeCommandLine("sudo -u openhab sudo systemctl restart openhab2.service")
restartoh2.postUpdate(OFF)
end
Are you trying to shutdown some other OH server or are you trying to restart the OH server that is currently running the Rule? Because if it’s the former, everything stops on the executeCommandLine. Most of the time even the executeCommandLine stops before it’s done and OH may not come back online.
No because the restartoh2.postUpdate(OFF) never gets a chance to execute.
You have to do something before the executeCommandLine.
Do the postUpdate before the executeCommandLine. And add a short thread::Sleep 100ms should be sufficient for persistence. Make sure you persist that item for restoreOnStartup