new version, 2 thinks changed/added
Version 19062001 only switch the device ON / OFF when timeout was exceeded, but did this only once. Now on every fail after timeout setting it checks the status of your device, and set it back in sync, if needed.
For windows the ping script needs to be different.
This is added. But a manual action to activate or deactivated what you need
Port function not added. Not yet for now, but when it will, i don't know
Code: Select all
--[[Version: 19062701
Script works in dzVents --> timer.
With this script it is possible to do a ping to multi netwerk devices.
The script does 1 ping to each device, when the script is triggerd.
It doesn't do a continuous ping every second untill timeouts.
Setup the settings needed and/or wanted.
There is a line which says: -- Don't change things undernead this line
If you have no idea how the scripts works, please lissen to this.
If you know how it works and have ideas, please post them on http://www.domoticz.com/forum/viewtopic.php?f=59&t=28420
]]--
return {
on = {
--devices = {'Trigger device'},
--timer = { "every 10 minutes" },
timer = {'every minute'},
},
data = { timeoutcount = { initial = {} } },
execute = function(dz, device)
-- SETTINGS:
-- Setup the device and the IP-address which this device has.
-- When wanted to switch a (dummy) device with this script, be aware that the device name is exactly the same as your (dummy) device
-- Device name IP-adres
local devices_ping = {
['Dummy1'] = 'XXX.XXX.XXX.XXX',
['Dummy2'] = 'XXX.XXX.XXX.XXX',
-- ['Dummy3'] = 'XXX.XXX.XXX.XXX',
}
-- How many timeouts, before a notification or switch off will be executed.
local timeout = 10
-- This is the name which the notification starts with
local notifyHead = 'Ping-tool'
-- Switch dummy device
-- When this is set to true, than the script will switch the pinged devices. Besure that the device is pressent in domoticz.
-- When you don't want to switch a device, set it to false.
-- When true, than at ping success the switch will be ON, when failed the switch will be OFF.
local dummydev = true
-- Telegram settings
-- Set true for sending telegram, set false for NOT sending telegram.
local telegram = false
-- Email settings (domoticz email settings have to be filled in)
-- Set true for sending email, set false for NOT sending email.
local email = false
local mailaddress = '[email protected]'
-- Don't change things undernead this line
local timeoutcount = dz.data.timeoutcount -- short reference
for deviceName, ipaddr in pairs(devices_ping) do
ping_success=""
ping_success=os.execute('ping -c1 -w1 ' .. ipaddr) -- For domoticz on Pi
-- ping_success=os.execute('ping ' ..ipaddr.. ' -w 100') -- For domoticz on Windows
if timeoutcount[deviceName] == nil then
timeoutcount[deviceName] = 0
end
if ping_success then
if timeoutcount[deviceName] == 0 then
print("ping "..deviceName.." succes ")
else
print("ping "..deviceName.." succes, device is back.")
timeoutcount[deviceName] = 0 -- reset the counter
if telegram then
dz.notify(notifyHead, notifyHead ..", ".. deviceName .." is back.",dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz ping tool', '' ..notifyHead.. ', '.. deviceName .." is back.", ''..mailaddress..'')
end
end
if dummydev then
if dz.devices(deviceName).state == 'Off' then
dz.devices(deviceName).switchOn()
end
end
elseif timeoutcount[deviceName] < timeout then
timeoutcount[deviceName] = timeoutcount[deviceName] + 1
print ("ping ".. deviceName .." ".. timeoutcount[deviceName] .." times failed.")
end
if timeoutcount[deviceName] >= timeout then
print ("ping ".. deviceName .." has " ..timeoutcount[deviceName].. " timeouts, this exceeds the timeout number setting.")
if dummydev then
if dz.devices(deviceName).state == 'On' then
dz.devices(deviceName).switchOff()
end
end
if telegram then
dz.notify(notifyHead, notifyHead ..", ".. deviceName .." has " ..timeout.. " timeouts, this exceeds the timeout counter.",dz.PRIORITY_NORMAL,nil,nil,dz.NSS_TELEGRAM)
end
if email then
dz.email('Domoticz ping tool', '' ..notifyHead.. ', '.. deviceName .." has " ..timeout.. " timeouts, this exceeds the timeout counter.", ''..mailaddress..'')
end
end
end
end
}
--[[
History
19062701 - Changed dummydev, so it will be in sync with status.
- Domoticz windows ping function added
19062001 - Start of scripts
]]--