[Node-RED] Domoticz WatchDog

Moderator: leecollings

Post Reply
Kingo71
Posts: 4
Joined: Thursday 18 October 2018 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

[Node-RED] Domoticz WatchDog

Post by Kingo71 »

Hi guys,

I started to play with Domoticz since last month and I got an issue get working Monit on my system, the start/stop script never worked properly.
Tried all the possible solutions found here in the forum but no avail.
Then I wrote the below flow in Node-RED as watchdog for domoticz.
node_red_domoticz_watchdog.PNG
node_red_domoticz_watchdog.PNG (38.12 KiB) Viewed 5528 times

Code: Select all

[{"id":"ae6352f9.6edf3","type":"tab","label":"Domoticz WatchDog","disabled":false,"info":""},{"id":"2e16bbcc.cb53b4","type":"inject","z":"ae6352f9.6edf3","name":"Get Domoticz Status","topic":"","payload":"","payloadType":"date","repeat":"180","crontab":"","once":true,"onceDelay":"200","x":160,"y":180,"wires":[["324c34e8.6e551c"]]},{"id":"324c34e8.6e551c","type":"http request","z":"ae6352f9.6edf3","name":"Get Domoticz Status","method":"GET","ret":"obj","url":"http://127.0.0.1:8080/json.htm?type=command&param=getversion","tls":"","x":380,"y":180,"wires":[["63308ba2.2c40b4"]]},{"id":"63308ba2.2c40b4","type":"switch","z":"ae6352f9.6edf3","name":"Check Domoticz Status","property":"payload.status","propertyType":"msg","rules":[{"t":"eq","v":"OK","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":640,"y":180,"wires":[["a50365e7.c0ce98"],["c550a469.a07458"]]},{"id":"f438df63.ced4a","type":"debug","z":"ae6352f9.6edf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1070,"y":360,"wires":[]},{"id":"c550a469.a07458","type":"function","z":"ae6352f9.6edf3","name":"Count","func":"// initialise the counter to 0 if it doesn't exist already\nvar count = flow.get('count')||0;\ncount += 1;\n// store the value back\nflow.set('count',count);\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":320,"wires":[["9ace0833.a0d808"]]},{"id":"a50365e7.c0ce98","type":"function","z":"ae6352f9.6edf3","name":"Count Reset","func":"// Reset the counter\nvar count = 0;\nflow.set('count',count);\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":160,"wires":[[]]},{"id":"9ace0833.a0d808","type":"switch","z":"ae6352f9.6edf3","name":"Count Evaluation","property":"count","propertyType":"msg","rules":[{"t":"gte","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":320,"wires":[["c7c8bfcf.9404e"]]},{"id":"c7c8bfcf.9404e","type":"exec","z":"ae6352f9.6edf3","command":"sudo /etc/init.d/domoticz.sh","addpay":false,"append":"stop","useSpawn":"false","timer":"30","oldrc":false,"name":"Domoticz stop","x":840,"y":320,"wires":[["f438df63.ced4a"],[],["1129b055.dd96"]]},{"id":"1129b055.dd96","type":"exec","z":"ae6352f9.6edf3","command":"sudo /etc/init.d/domoticz.sh","addpay":false,"append":"start","useSpawn":"false","timer":"","oldrc":false,"name":"Domoticz start","x":840,"y":400,"wires":[["f438df63.ced4a"],["18ed1d87.154272"],["18ed1d87.154272"]]},{"id":"18ed1d87.154272","type":"function","z":"ae6352f9.6edf3","name":"Count Reset","func":"// Reset the counter\nvar count = 0;\nflow.set('count',count);\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":420,"wires":[[]]}]

The flow is waiting for 3 minutes when start for the first time, letting Domoticz start for the first time when you boot up your system.
Then every 3 minutes is checking for Domoticz status trough the Json message returned by the API.
If the response is "OK" the error count is resettled to 0 otherwise the counter is rised by 1 and if reach 2 or more the next node is launched.
The 2 next nodes are going to launch the domoticz.sh script to stop and then start the service, a debug node will show the result of the script and the error count will be resettled to 0 and the flow finish.

Node-RED is required without any extra node to be installed.

Hope can help somebody struggling with Monit!

Greetings,

Angelo.
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by emme »

wow...
it looks cool!!!!
I'll give it a try.... I do never like monit :P :P
The most dangerous phrase in any language is:
"We always done this way"
Kingo71
Posts: 4
Joined: Thursday 18 October 2018 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by Kingo71 »

emme wrote: Thursday 18 October 2018 10:43 wow...
it looks cool!!!!
I'll give it a try.... I do never like monit :P :P
Me neither!
I hope it will work fine for you.
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by alanlsmith »

Thank you for this. I’ve tested it with my 2 Domoticz instances and it works very well on a Pi and Ubuntu machine.

I have added a 30 second delay between the stop and start commands as running immediately after each other the start command was ignored as the stop command was still being completed.

I’ve also used the idea of this flow to create a flow to ‘power cycle’ the machine running Domoticz in the case of a ‘freeze’ or in the case of my Ubuntu machine, a loss of Wi-Fi.
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
Kingo71
Posts: 4
Joined: Thursday 18 October 2018 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by Kingo71 »

Glad to see that was useful for you!
I have added a 30 second delay between the stop and start commands as running immediately after each other the start command was ignored as the stop command was still being completed.
The EXEC node has 2 options: Trigger the output when the command is complete or send it while the command is executed.
In my case i setup it as the first option, so will trigger the next node only when the stop script is complete.
For me is working fine, maybe your EXEC node is of a different version?
alanlsmith
Posts: 132
Joined: Monday 07 August 2017 17:17
Target OS: Linux
Domoticz version: Latest β
Location: Near London (Saaarf!)
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by alanlsmith »

I’m sorry, I should have paid more attention. I completely missed the ‘output after command completed’ setting. What I now realise happened is that there is a 30 second timeout on the exec node and when I tested it Domoticz on my Ubuntu machine took longer that 30 seconds to complete so the timeout ended and the output from the node continued along the flow. So I added the delay.

Now I see that I could have just increased the timeout to suit.

<Edited for spelling>
Last edited by alanlsmith on Thursday 25 October 2018 21:00, edited 2 times in total.
Domoticz Latest β, RPi 4B with 110Gb SSD for Domoticz, RPi 4B with 110Gb SSD for Node-Red & a RPi 2B for logging / IP addressing. RFXCOM, PiZiGate, Z-Wave, Harmony, Hue lamps and a bit of Broadlink.
Kingo71
Posts: 4
Joined: Thursday 18 October 2018 10:03
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by Kingo71 »

What I now realise happened is that there is a 30 second timeout on the exec node and when I tested it Domoticz on my Ubuntu machine took longer that 30 seconds to complete so the timeout ended and the output from the node continued oalong the flow.
Good to know! I tried it on a raspberry and the script complete immediately, so the 30 seconds timeout was more than enough for me.

Now, thanks to your feedback, we know that depend of the environment might be needed to rise the timeout.

Thank you!
Andrex
Posts: 92
Joined: Thursday 18 February 2016 9:11
Target OS: Linux
Domoticz version:
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by Andrex »

Kingo71 wrote: Thursday 18 October 2018 10:30

Code: Select all

[{"id":"ae6352f9.6edf3","type":"tab","label":"Domoticz WatchDog","disabled":false,"info":""},{"id":"2e16bbcc.cb53b4","type":"inject","z":"ae6352f9.6edf3","name":"Get Domoticz Status","topic":"","payload":"","payloadType":"date","repeat":"180","crontab":"","once":true,"onceDelay":"200","x":160,"y":180,"wires":[["324c34e8.6e551c"]]},{"id":"324c34e8.6e551c","type":"http request","z":"ae6352f9.6edf3","name":"Get Domoticz Status","method":"GET","ret":"obj","url":"http://127.0.0.1:8080/json.htm?type=command&param=getversion","tls":"","x":380,"y":180,"wires":[["63308ba2.2c40b4"]]},{"id":"63308ba2.2c40b4","type":"switch","z":"ae6352f9.6edf3","name":"Check Domoticz Status","property":"payload.status","propertyType":"msg","rules":[{"t":"eq","v":"OK","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":640,"y":180,"wires":[["a50365e7.c0ce98"],["c550a469.a07458"]]},{"id":"f438df63.ced4a","type":"debug","z":"ae6352f9.6edf3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":1070,"y":360,"wires":[]},{"id":"c550a469.a07458","type":"function","z":"ae6352f9.6edf3","name":"Count","func":"// initialise the counter to 0 if it doesn't exist already\nvar count = flow.get('count')||0;\ncount += 1;\n// store the value back\nflow.set('count',count);\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"x":470,"y":320,"wires":[["9ace0833.a0d808"]]},{"id":"a50365e7.c0ce98","type":"function","z":"ae6352f9.6edf3","name":"Count Reset","func":"// Reset the counter\nvar count = 0;\nflow.set('count',count);\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":160,"wires":[[]]},{"id":"9ace0833.a0d808","type":"switch","z":"ae6352f9.6edf3","name":"Count Evaluation","property":"count","propertyType":"msg","rules":[{"t":"gte","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":650,"y":320,"wires":[["c7c8bfcf.9404e"]]},{"id":"c7c8bfcf.9404e","type":"exec","z":"ae6352f9.6edf3","command":"sudo /etc/init.d/domoticz.sh","addpay":false,"append":"stop","useSpawn":"false","timer":"30","oldrc":false,"name":"Domoticz stop","x":840,"y":320,"wires":[["f438df63.ced4a"],[],["1129b055.dd96"]]},{"id":"1129b055.dd96","type":"exec","z":"ae6352f9.6edf3","command":"sudo /etc/init.d/domoticz.sh","addpay":false,"append":"start","useSpawn":"false","timer":"","oldrc":false,"name":"Domoticz start","x":840,"y":400,"wires":[["f438df63.ced4a"],["18ed1d87.154272"],["18ed1d87.154272"]]},{"id":"18ed1d87.154272","type":"function","z":"ae6352f9.6edf3","name":"Count Reset","func":"// Reset the counter\nvar count = 0;\nflow.set('count',count);\n// make it part of the outgoing msg object\nmsg.count = count;\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":420,"wires":[[]]}]
Hi,
I can't import the flow. When I click on the Import button, it just disappear without any warning.
I'm able to import/export other flows.
What could be wrong?
Derik
Posts: 1602
Joined: Friday 18 October 2013 23:33
Target OS: Raspberry Pi / ODroid
Domoticz version: BETA
Location: Arnhem/Nijmegen Nederland
Contact:

Re: [Node-RED] Domoticz WatchDog

Post by Derik »

i try this also.
Only i get the fow not working
My first flow
So perhaps i do somethnig wrong
Xu4: Beta Extreme antenna RFXcomE,WU Fi Ping ip P1 Gen5 PVOutput Harmony HUE SolarmanPv OTG Winddelen Alive ESP Buienradar MySensors WOL Winddelen counting RPi: Beta SMAspot RFlinkTest Domoticz ...Different backups
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest