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.
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¶m=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.