Admin Controls

Hi All

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

Thank you

You can set the OFF in a startup rule.

But in some cases, the server isnt rebooted, its backed up so that wont work im afraid :frowning:

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.

Would this not work?


rule "Restart OH2"
when
        Item restartoh2 changed to ON
then
        executeCommandLine("sudo -u openhab sudo systemctl restart openhab2.service")
        restartoh2.postUpdate(OFF)
end

Hm. Why do you need to set restartoh2 if you don’t restart oh?

As soon as you restart oh / the whole server you can’t be sure that a postUpdate or sendCommand can set the new state.

This is true.

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

1 Like