Beginner's guide to an openHABian reboot/shutdown switch

I totally agree and also don’t like giving super powers to low-level users. However, when you implement the system for non-technical users, you cannot tell them “log in to the server via SSH and restart it”. You need to provide a user-friendly option, otherwise they will simply go and pull the plug.
OpenHAB should provide such a friendly (and secure) option by default instead of making us look for workarounds.

I personally believe that systems (even highly available ones) should be rebooted periodically for performance reasons, but that’s not part of this discussion and you’re right about pointing out that (doing it this way) is potentially harmful.

I’ll take a look at this.

Well, yes. :slight_smile: But as there is no option for now…

  1. login to the GNU/Linux platform where openHAB is active.
  2. if not already installed, install sudo
  3. grant access for the openhab user by editing the sudoers file. Use visudo for this purpose.
  4. setup a line like this: openhab ALL (ALL) NOPASSWD /sbin/reboot
    at the correct context (search for root in the file)
  5. install exec and create the correct thing to use the script
  6. edit the whitelist to allow openHAB exec to execute sudo /sbin/reboot
  7. link an item to the thing and setup a Switch Widget to use the exec channel ‘run’

No need for root. Stay save, but give the user control.
But please be aware that maybe the UI is not reachable anymore, so there might be a better way to restart openHAB by building a script which can be executed remotely (just by a double click on the Desktop Icon :wink: maybe with a simple “Are you sure?” )

2 Likes

Definitely no.
Reboots are not needed and do more harm than good. A simple accessible reboot switch just makes the lazy part in everybody surface and quickly get in control instead of taking the painful route to really debug your problem. This is even more true for beginners. That’s not the OH way of doing things.
And that is why most of us (openHABian developers, experienced supporters) with discernment will not support users in getting there.

I also disagree with this. If performance degrades over time, that’s just sign of another uncaught bug (mem leak or some such) or bad software design and your time is better invested into looking after that.

@z9th3, did you ever solve this? I’m doing a fresh install on an RPi4 and have run into the same issues with the openhab user requesting a password. @Udo_Hartmann’s suggestion unfortunately isn’t working for me.

I’m suspecting that this guide might need to be rewritten to use the Exec binding, but I’m not sure if that will work either.

@rpwong sorry for the late reply, I have not worked on this issue anymore so I don’t have any good news to report. My need for automatic reboots has decreased because it seems my current system is more stable.

This was my key to success:

1 Like

Thanks @sihui! I’ll try it out this weekend. I rarely need to reboot these days, but the shutdown command is nice to have on occasion. Mostly, I’d like to update the guide so that it works for others.

for this I added following rule

rule “piStartup_systemstatus”

when System started or

Time cron "0/15 * * * * ?"

then

postUpdate(Flag_System, NULL)

end

Did you ever get this figured out? Sorry, I’ve been away from the forums for a long time, and I’m just getting caught up.

On my installation, it was not enough to use

openhab ALL=(ALL) NOPASSWD: /sbin/systemctl

For some reason I had to use

openhab ALL=(ALL) NOPASSWD: ALL

to allow a rule to call ‘sudo -S systemctl restart openhab2.service’. No idea why allowing only systemctl is not enough.

Hello, your example works great for a long time on OH2.5 … But on OH3 I’m having an error:

2021-01-27 13: 36: 19.614 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID ‘system-1’ failed: An error occurred during the script execution: array element type mismatch in system

I would know how to help me solve it, I miss “restart” in the UI.
Thanks!

That’s because executeCommandLine has changed in OH3. So instead of:

executeCommandLine("sudo@@poweroff")

It’s now:

executeCommandLine("sudo", "poweroff")

Every phrase is now put into quotations, and the @@ for spaces no longer works.

4 Likes

Hi @rpwong

Thanks for jumping in on that one! Ive not gone to OH3 yet, so you’ve saved hunting down a problem when I do! :slight_smile:

I’ve put a link into your post on my post further up, so hopefully people will find the change.

Thanks!

Man, thank you very much!
Sorry my noob

It worked perfect!

executeCommandLine is the only thing that doesn’t hold up if someone transfers their existing config files to OH3. Rather than updating this tutorial, I’ll probably write an OH3-specific version and reference this one.

EDIT: I changed my mind and just updated the rules with OH3-specific versions of executeCommandLine.

2 Likes

The same with me. Anybody have an idea?

No idea. I replicated this when I built a new OH3 system on openHABian, and everything above worked just fine.

Hello,
i have started the migration from my OH2.5 to OH3 and have also implemented the reboot/shutdown switch and it’s working fine.Now i also want to replace the sitemap by a page but have not found a way how to setup a page especilly for

Switch item=Restart_Shutdown	mappings=["1"="Restart", "2"="Shutdown"]
Switch item=Restart_confirm		mappings=["ON"="Yes","OFF"="No"]	visibility=[Restart_Shutdown=="1"]
Switch item=Shutdown_confirm	mappings=["ON"="Yes","OFF"="No"]	visibility=[Restart_Shutdown=="2"]

Any hints what widget should be used and how to get e.g. the mappings into a page are welcome.

I found a solution when searching for somthing else.
In the item defintion you need to add Metadata | State Description and here in the field Options put

"ERROR"="ERROR"
"WARN"="WARN"
"INFO"="INFO"
"DEBUG"="DEBUG"
"TRACE"="TRACE"

In a PAGE you can add a LIST CARD and in the LIST CARD you should use LABEL LIST ITEM for each log swich item.
When you display the page, klick on the Item Label displayed in the page and you get the list from the Option field for your selection

how can i add a delay?