I spent a lot of time tryng to finalise a LUA script.
This script ping an ip address and depending of the result switch on/off a switch.
I use a user variable to validate the result after few tries arroud 5 is a good count to have a revelant test, sometime one or two pings are not sufficient.
The LUA script is activated each minute by Domoticz and make a test period of 5mn, (one ping each minute is a revelant test I think) .
The user variable Var_Ping_PC1 is not updated to zero when the count is achieved.
Code: Select all
commandArray['Variable:Var_Ping_PC1'] = '0'
Code: Select all
commandArray={}
debug=1
if(otherdevices['Ping_PC1']=='Off') then
ping_success=os.execute('ping -n 1 -w 1000 10.10.0.8')
if ping_success then
else
commandArray['Variable:Var_Ping_PC1'] = tostring(uservariables["Var_Ping_PC1"] + 1)
if uservariables["Var_Ping_PC1"] > 4 then
commandArray['OpenURL']='https://smsapi.free-mobile.fr/sendmsg?user=MyName&pass=123456&msg=Pas%20de%20ping%20vers%20PC1'
print(' Pas de ping vers PC1' ..uservariables["Var_Ping_PC1"])
commandArray['Ping_PC1']='On'
commandArray['Variable:Var_Ping_PC1'] = '0'
print('Var_Ping_PC1 = ' ..uservariables["Var_Ping_PC1"])
end
end
end
return commandArray