Files
Domoticz/lua/Archives/script_time_ping2.old
2025-03-06 11:09:58 +01:00

79 lines
1.9 KiB
Plaintext
Executable File

--Initialise la commande de retour finale
commandArray={}
--Mode deboggage (affichage des messages)
debug=true
--Prefixe pour les sorties de log
prefixe="(PING) "
--recupere les minutes
time=os.time()
minutes=tonumber(os.date('%M',time))
if (minutes == 0 or minutes == 10 or minutes == 20 or minutes == 30 or minutes == 40 or minutes == 50) then
--Tableau des périphériques à "pinguer"
-- Key = adresse ip à pinguer
-- Value = périphérique virtuel à switcher
local ping={}
ping['volumio']='Volumio2'
ping['achille']='Achille'
ping['akhenaton']='Akhenaton'
ping['hackintosh']='Hackintosh'
ping['xbmc']='Xbmc'
ping['akhesa']='Akhesa'
ping['theo']='Theo'
ping['s3-mini']='Moi'
ping['manon']='Manon'
ping['domi1']='Domi1'
ping['domi2']='Domi2'
ping['soutihp']='ImprimanteHp'
ping['192.168.0.17']='Telechambre'
-- Pas de ping de la box ?? == Panne de courant
--ping['192.168.1.1']='PanneCourant'
--ping['192.168.0.20']='Presence Camera Interieure'
--ping['192.168.0.21']='Presence Camera Exterieure'
--ping['192.168.0.100']='Presence Raspberry'
AuMoinsUnPing=false
--pour chaque entree du tableau
for ip, switch in pairs(ping) do
--Le Ping ! : -c1 = Un seul ping , -w1 délai d'une seconde d'attente de réponse
ping_success=os.execute('ping -c1 -w1 '..ip)
--Si le ping à répondu
if ping_success then
AuMoinsUnPing=true
if(debug==true)then
print(prefixe.."ping success "..switch)
end
--si le switch etait sur off on l'allume
if(otherdevices[switch]=='Off') then
commandArray[switch]='On'
end
else
--Si pas de réponse
if(debug==true)then
print(prefixe.."ping fail "..switch)
end
--si le switch etait sur oN on l'eteind
if(otherdevices[switch]=='On') then
commandArray[switch]='Off'
end
end
end
if AuMoinsUnPing then
commandArray['PanneCourant']='Off'
else
commandArray['PanneCourant']='On'
end
end
return commandArray