How to get Zipabox to detect its own zombification and self-reboot
Quite often now (perhaps because I have a lot of rules), I notice that, after synchronising a new set of changes to rules, the Zipabox becomes partially zombified. It will continue to receive data from outside (from sensors, or from Google App Scripts that I have running to send information to it), but the rules that I have running on a constant cycle of ten minutes just stop working.
So I wondered if I could detect this state, and also whether I could get the Zipabox to reboot itself. The answer: yes, and yes :-)
For the reboot you'll need some sort of wireless socket. I deliberately chose one that is not intended for integration into home automation so that it will work completely independently of the Zipabox. I chose the TP-Link HS100/110. At first I just used it to reboot the Zipabox from my smartphone when I saw that it wasn't responding any more, but then I got a little more ambitious.
The TP-Link has the additional advantage of being able to accept commands in the form of HTTP requests, and being able to reboot itself. This is where I found the reboot command:
https://www.softscheck.com/en/reverse-engineering-tp-link-hs110/
In order to be able to send it commands, you need to obtain the device ID and the authentication token, and note the URL (which is probably https://eu-wap.tplinkcloud.com for most of us), all of which is explained here:
http://itnerd.space/2017/01/22/how-to-control-your-tp-link-hs100-smartplug-from-internet/
You just need to get this info once by sending a couple of HTTP commands, and you're ready to send HTTP requests. The reboot command is as follows:
POST
URL: https://eu-wap.tplinkcloud.com/?token=<YOUR AUTHENTICATION TOKEN>
Headers: Content-Type: application/json
Body:
{
"method":"passthrough",
"params":
{
"deviceId":"<YOUR DEVICE ID>",
"requestData":"{\"system\":{\"reboot\":{\"delay\":2}}}"
}
}
That's the self-reboot part. Just put that in a rule.
Now for the detection of zombification. Since I want to detect when my variable-setting rules are not working, I save a time stamp each time those rules run (see my date-time meter post on creating time stamps). Then I create another rule that detects when that time stamp is out of date. Since my external data sources are still updating even when the box is not responding properly, I can create a rule that reacts to changes in those data sources, have the rule check the time stamp, and if the time stamp is old, reboot the box. See attachment.
The rule checks a selection of external data sources to ensure that it gets called pretty frequently. I disable the check immediately after a reboot because the system takes a while to get itself together.
How to remotely de-zombify a Zipabox guide... awesome.
How to remotely de-zombify a Zipabox guide... awesome.
Well Dave, you just showed again how greatly you know the system and how to get around it...
Well Dave, you just showed again how greatly you know the system and how to get around it...
Forget to format the code. Sorry!
Forget to format the code. Sorry!
David, this date-time meter is a virtual meter and current date-time acts as counter?
Or, are you able to store date time in virtual meter?
thanx, Martin
David, this date-time meter is a virtual meter and current date-time acts as counter?
Or, are you able to store date time in virtual meter?
thanx, Martin
This is my post on the date-time meter:
https://community.zipato.com/topic/a-method-for-creating-manipulable-time-and-date-values
It works very well and I use it all over the place.
Yesterday I was puzzled in by a claim in this post:
https://community.zipato.com/topic/creating-a-rule-using-sunsetsunrise-for-outdoor-lights
that you can store time values in variables. In my experience, that doesn't work. I'll check it out in case Zipato have fixed something.
This is my post on the date-time meter:
https://community.zipato.com/topic/a-method-for-creating-manipulable-time-and-date-values
It works very well and I use it all over the place.
Yesterday I was puzzled in by a claim in this post:
https://community.zipato.com/topic/creating-a-rule-using-sunsetsunrise-for-outdoor-lights
that you can store time values in variables. In my experience, that doesn't work. I'll check it out in case Zipato have fixed something.
For anyone thinking of implementing my scheme, it ran into a bit of a snag: the TP-Link token expires fairly frequently. I'd already set up a Google App Script that monitors the updates to a Google Sheet where the Zipabox logs important data every ten minutes. If it sees that there hasn't been an update for a while, it sends me a message. I decided to extend that to make the script reboot the Zipabox directly. From a script, getting a new token is not a problem. I force the renewal of the token each week, and if I get the expired token error, I also renew it and try again. I store the token in another Google Sheet which I use to note down when my calls to weather services have failed recently.
To complete this solution, I invoke the reboot part of the Google App Script from the RebootSelf rule in the Zipabox. And it apparently works!
I will just post the reboot part here for now. If you also want the part that monitors the log, let me know.
For anyone thinking of implementing my scheme, it ran into a bit of a snag: the TP-Link token expires fairly frequently. I'd already set up a Google App Script that monitors the updates to a Google Sheet where the Zipabox logs important data every ten minutes. If it sees that there hasn't been an update for a while, it sends me a message. I decided to extend that to make the script reboot the Zipabox directly. From a script, getting a new token is not a problem. I force the renewal of the token each week, and if I get the expired token error, I also renew it and try again. I store the token in another Google Sheet which I use to note down when my calls to weather services have failed recently.
To complete this solution, I invoke the reboot part of the Google App Script from the RebootSelf rule in the Zipabox. And it apparently works!
I will just post the reboot part here for now. If you also want the part that monitors the log, let me know.
This is the rule that calls the app script. The GaS must be made accessible to anyone, even anonymous (I think). Otherwise you can't invoke it from outside.
This is the rule that calls the app script. The GaS must be made accessible to anyone, even anonymous (I think). Otherwise you can't invoke it from outside.
Replies have been locked on this page!