Author Topic: Simple guide to scheduled reboot and reboot from phone app  (Read 1028 times)

Offline thief

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +3/-0
Simple guide to scheduled reboot and reboot from phone app
« on: February 22, 2018, 03:07:30 am »
This goes for UI7

Scheduled Reboot

1. Go to Scenes -> Add Scene
2. Click schedule and set the interval and click "validate"
3. Click "Next Step"
4. Click "Next Step"
5. Click "No Loop Code Defined" and type in os.execute( 'reboot' ) and click "Save Lua"
6. select room and name your scene and click fininsh


Manual Reboot

1. Go to Scenes -> Add Scene
2. Click "Manual"
3. Click "Next Step"
4. Click "Next Step"
5. Click "No Loop Code defined" and type in os.execute( 'reboot' ) and click "Save Lua"
6. select room and name your scene and click fininsh

Now you can run that scene from your mobile to manually reboot Vera.


Offline Cor

  • Hero Member
  • *****
  • Posts: 1184
  • Karma: +7/-4
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #1 on: February 22, 2018, 03:31:00 am »
Beware; when there is no internet connection , it is not good to reboot the vera.

This code first checks if there is internet connection, otherwise it doesn't reboot.
Before someone made this script for me , once the vera was stuck due to no internet connection after a reboot.


Code: [Select]
local ping = os.execute("ping -c 1 8.8.8.8")
if ping ~= 0 then
  luup.log("Auto Reboot: Network down. Aborted.")
else
  luup.log("Auto Reboot: Network OK. Rebooting in 2 seconds.")
  luup.sleep(2000)
  os.execute("reboot")
end

Cor

Offline thief

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +3/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #2 on: February 22, 2018, 03:46:29 am »
Thank you!
You mean like this:

Scheduled Reboot

1. Go to Scenes -> Add Scene
2. Click schedule and set the interval and click "validate"
3. Click "Next Step"
4. Click "Next Step"
5. Click "No Loop Code Defined" and type in:
local ping = os.execute("ping -c 1 8.8.8.8")
if ping ~= 0 then
  luup.log("Auto Reboot: Network down. Aborted.")
else
  luup.log("Auto Reboot: Network OK. Rebooting in 2 seconds.")
  luup.sleep(2000)
  os.execute("reboot")
end

and click "Save Lua"
6. select room and name your scene and click fininsh


But this also means it wont reboot if Google is down "(8.8.8,8)"   :)

« Last Edit: February 22, 2018, 03:50:15 am by thief »

Offline Cor

  • Hero Member
  • *****
  • Posts: 1184
  • Karma: +7/-4
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #3 on: February 22, 2018, 06:23:59 am »
Correct .... but you don't want to reboot your vera without internet .... something to do that vera needs a time from internet when rebooting.

I for example  have a schedule for daily reboot at 0330, but you can also leave it open and just use it for a manuel reboot.

Cor
« Last Edit: February 22, 2018, 06:54:34 am by Cor »

Offline thief

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +3/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #4 on: February 22, 2018, 08:18:36 am »
Yes, know about that time thing.

On the other hand, one can't even reboot it remotly if there is no internet :)

My scheduled reboots are twice a week at 04:00

I just want to be able to reboot every device remotely if I'm away, rarely needed option but still.
And that goes for all internet connected devices: Modem, router, Vera, Alexa, NVR etc.
Now I'm all set with that :)
« Last Edit: February 22, 2018, 08:33:13 am by thief »

Offline HSD99

  • Full Member
  • ***
  • Posts: 226
  • Karma: +6/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #5 on: February 22, 2018, 10:59:19 am »
Vera contacts OpenWRT NTP servers on a boot---there is no hardware RTC. Vera will be cranky if it can't contact the time servers. Using a scene to remotely reboot assumes a couple of things:  1) Vera has network connectivity, and 2) Vera is running well enough to accept the remote command.

I use the os.command method for a daily scheduled reboot---you can also use the same scene run manually, of course, to reboot on demand. I run a local NTP server, so outside connectivity isn't needed to reboot. There are some threads on the forum that cover this topic. For the scheduled reboot, adding the network check code is a must if you don't run your own NTP.  Even so, I use that code to test the NTP server before attempting the reboot.

If Vera isn't running, then options are obviously limited for a reboot. My Vera's are on network-connected power relays that ping the units once per minute. If 2 pings are missed, it will power cycle the unit. They can also be controlled from the network, including remotely. All the key network equipment is set up like this.

There are possible downsides to a remote reboot. The forum has some horror stories of folks who had a remote unit fail the reboot, necessitating a long trip to the remote location to debug the problem.

Offline rigpapa

  • Sr. Member
  • ****
  • Posts: 402
  • Karma: +57/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #6 on: February 22, 2018, 12:41:16 pm »
Code: [Select]
local ping = os.execute("ping -c 1 8.8.8.8")
if ping ~= 0 then
  luup.log("Auto Reboot: Network down. Aborted.")
else
  luup.log("Auto Reboot: Network OK. Rebooting in 2 seconds.")
  luup.sleep(2000)
  os.execute("reboot")
end

A shorter, simpler version of this is:

Code: [Select]
os.execute("ping -c 1 && reboot")

The reboot command will not run unless the exit status of ping is 0 (can reach Google).
Author of Rachio, Deus Ex Machina II, Intesis WMP Gateway, SiteSensor, DelayLight, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline thief

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +3/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #7 on: February 22, 2018, 04:36:25 pm »
Nice, what does the "&&" stand for?

Offline HSD99

  • Full Member
  • ***
  • Posts: 226
  • Karma: +6/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #8 on: February 22, 2018, 04:42:13 pm »
Logical AND operator

Offline jswim788

  • Hero Member
  • *****
  • Posts: 735
  • Karma: +49/-2
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #9 on: February 22, 2018, 06:41:53 pm »
from: https://www.gnu.org/software/bash/manual/html_node/Lists.html

An AND list has the form

command1 && command2
command2 is executed if, and only if, command1 returns an exit status of zero.

Offline thief

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +3/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #10 on: February 23, 2018, 01:04:12 am »
But where in this line does it ping google ?: os.execute("ping -c 1 && reboot")

Could somebody post the real/right/best/working line of code to put in?

Maybe with some cache clearing included?
« Last Edit: February 23, 2018, 01:35:24 am by thief »

Offline rigpapa

  • Sr. Member
  • ****
  • Posts: 402
  • Karma: +57/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #11 on: February 23, 2018, 07:26:31 am »
But where in this line does it ping google ?: os.execute("ping -c 1 && reboot")

Sorry! My bad...

Code: [Select]
os.execute("ping -c 1 8.8.8.8 && reboot")
Author of Rachio, Deus Ex Machina II, Intesis WMP Gateway, SiteSensor, DelayLight, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline rigpapa

  • Sr. Member
  • ****
  • Posts: 402
  • Karma: +57/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #12 on: February 23, 2018, 07:27:25 am »
Maybe with some cache clearing included?

What cache are you referring to?
Author of Rachio, Deus Ex Machina II, Intesis WMP Gateway, SiteSensor, DelayLight, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.

Offline thief

  • Jr. Member
  • **
  • Posts: 85
  • Karma: +3/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #13 on: February 23, 2018, 07:37:12 am »
I'm new to this so I'm not sure, but i read a post where somebody had some kind of script that cleared unnecessary files/cache before
scheduled reboot. Some kind of "maintenance"

Don't know if it's necessary, but would gladly put that in the reboot lua if it helps Vera function properly.
Like starting from as "clean table" as possible. :)

The script was: os.execute("echo 3 > /proc/sys/vm/drop_caches")

Just dont know if that helps anything, and how to put that in to the rest of the script ?

And thanks Rigpapa and Cor for the scripts.
« Last Edit: February 23, 2018, 07:42:00 am by thief »

Offline rigpapa

  • Sr. Member
  • ****
  • Posts: 402
  • Karma: +57/-0
Re: Simple guide to scheduled reboot and reboot from phone app
« Reply #14 on: February 23, 2018, 10:54:19 am »
That would flush a bunch of caches that are volatile, so they're being flushed by the reboot anyway. Flushing them may have some use if you're not rebooting, maybe reducing memory use temporarily, but these are well-managed caches and unless you're really strapped for RAM for some immediate purpose, flushing them is more likely to create a momentary negative impact on system performance.
Author of Rachio, Deus Ex Machina II, Intesis WMP Gateway, SiteSensor, DelayLight, Auto Virtual Thermostat and VirtualSensor plugins. Vera Plus w/100+ Z-wave devices. Vera3 sandbox.