Variante script Ping avec variable a éditer pour 5 bouton de presence
Publié : 19 janv. 2016, 22:55
Salut,
Une variante du script de ping de téléphone ou autre.
On créer 5 bouton virtuel via interrupteurs/ajout manuel/Matériel:Dummy/type d'interrupteur:on/off/x10/.......
Puis dans putty faire un:
Puis on colle avec le bouton droit de la sourie ou un clic sur la molette le script:
Si vous ne voulez pas d'écriture dans les log supprimer les Print
Editer vos variables dans la zone "variables a éditer"
Puis ctrl+O
puis entree
puis ctrl+x
puis un:
Donc si le téléphone est "Pinguer" le bouton passe a ON et le prochain Ping seras exécuté dans 10min, si non détecté prochain Ping dans 1 minute.
Si vous aussi vous avez un raspberry avec kodi d'installé sur votre TV vous pouvez éditer votre interrupteur et dans Off mettre:
Un clic sur votre interrupteur vous eteindra le Pi gérant Kodi.
Tranquilou.
Une variante du script de ping de téléphone ou autre.
On créer 5 bouton virtuel via interrupteurs/ajout manuel/Matériel:Dummy/type d'interrupteur:on/off/x10/.......
Puis dans putty faire un:
Code : Tout sélectionner
sudo nano /home/pi/domoticz/scripts/lua/script_time_ping.luaCode : Tout sélectionner
--------------------------------
------ Variables à éditer ------
--------------------------------
ip1 = '192.168.0.20' --1er Ip a pinguer
local nom_inter1 = 'Présence_Titia' --Interrupteur activé par Ip1
ip2 = '192.168.0.14' --2eme Ip a pinguer
local nom_inter2 = 'Présence_Nas' --Interrupteur activé par Ip2
ip3 = '192.168.0.12' --3eme Ip a pinguer
local nom_inter3 = 'Présence_Ordi' --Interrupteur activé par Ip3
ip4 = '192.168.0.15' --4eme Ip a pinguer
local nom_inter4 = 'Présence_Kodi' --Interrupteur activé par Ip4
ip5 = '192.168.0.16' --5eme Ip a pinguer
local nom_inter5 = 'Présence_2DS' --Interrupteur activé par Ip5
--------------------------------
-- Fin des variables à éditer --
--------------------------------
commandArray={}
--Cette fonction calcule la différence de temps (en secondes) entre maintenant et la date passée en paramètre.
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
--Si le téléphone n'est pas détecté ou qu'il est présent depuis plus de 10 minutes (600 secondes),
--alors on vérifie à nouveau sa présence
if (otherdevices[nom_inter1]=='Off' or (otherdevices[nom_inter1]=='On' and timedifference(otherdevices_lastupdate[nom_inter1]) > 600)) then
ping_success_tel1=os.execute('ping -c1 -w1 '.. ip1 ..'')
if ping_success_tel1 then
commandArray[nom_inter1]='On'
print(' '.. nom_inter1 ..' détecté!')
else
print(' '.. nom_inter1 ..' absent!')
if otherdevices[nom_inter1]=='On' then --On ne passe l'interrupteur virtuel à Off que s'il est sur On.
commandArray[nom_inter1]='Off'
print(' '.. nom_inter1 ..' perdu!')
end
end
end
if (otherdevices[nom_inter1]=='On' and timedifference(otherdevices_lastupdate[nom_inter1]) < 600) then
print(' '.. nom_inter1 ..' Ping < a 10min!')
end
--Ping 2ème ip
if (otherdevices[nom_inter2]=='Off' or (otherdevices[nom_inter2]=='On' and timedifference(otherdevices_lastupdate[nom_inter2]) > 600)) then
ping_success_tel2=os.execute('ping -c1 -w1 '.. ip2 ..'')
if ping_success_tel2 then
commandArray[nom_inter2]='On'
print(' '.. nom_inter2 ..' détecté!')
else
print(' '.. nom_inter2 ..' absent!')
if otherdevices[nom_inter2]=='On' then --On ne passe l'interrupteur virtuel à Off que s'il est sur On.
commandArray[nom_inter2]='Off'
print(' '.. nom_inter2 ..' perdu!')
end
end
end
if (otherdevices[nom_inter2]=='On' and timedifference(otherdevices_lastupdate[nom_inter2]) < 600) then
print(' '.. nom_inter2 ..' Ping < a 10min!')
end
--Ping 3ème ip
if (otherdevices[nom_inter3]=='Off' or (otherdevices[nom_inter3]=='On' and timedifference(otherdevices_lastupdate[nom_inter3]) > 600)) then
ping_success_tel3=os.execute('ping -c1 -w1 '.. ip3 ..'')
if ping_success_tel3 then
commandArray[nom_inter3]='On'
print(' '.. nom_inter3 ..' détecté!')
else
print(' '.. nom_inter3 ..' absent!')
if otherdevices[nom_inter3]=='On' then --On ne passe l'interrupteur virtuel à Off que s'il est sur On.
commandArray[nom_inter3]='Off'
print(' '.. nom_inter3 ..' perdu!')
end
end
end
if (otherdevices[nom_inter3]=='On' and timedifference(otherdevices_lastupdate[nom_inter3]) < 600) then
print(' '.. nom_inter3 ..' Ping < a 10min!')
end
--Ping 4ème ip
if (otherdevices[nom_inter4]=='Off' or (otherdevices[nom_inter4]=='On' and timedifference(otherdevices_lastupdate[nom_inter4]) > 600)) then
ping_success_tel4=os.execute('ping -c1 -w1 '.. ip4 ..'')
if ping_success_tel4 then
commandArray[nom_inter4]='On'
print(' '.. nom_inter4 ..' détecté!')
else
print(' '.. nom_inter4 ..' absent!')
if otherdevices[nom_inter4]=='On' then --On ne passe l'interrupteur virtuel à Off que s'il est sur On.
commandArray[nom_inter4]='Off'
print(' '.. nom_inter4 ..' perdu!')
end
end
end
if (otherdevices[nom_inter4]=='On' and timedifference(otherdevices_lastupdate[nom_inter4]) < 600) then
print(' '.. nom_inter4 ..' Ping < a 10min!')
end
--Ping 5ème ip
if (otherdevices[nom_inter5]=='Off' or (otherdevices[nom_inter5]=='On' and timedifference(otherdevices_lastupdate[nom_inter5]) > 600)) then
ping_success_tel5=os.execute('ping -c1 -w1 '.. ip5 ..'')
if ping_success_tel5 then
commandArray[nom_inter5]='On'
print(' '.. nom_inter5 ..' détecté!')
else
print(' '.. nom_inter5 ..' absent!')
if otherdevices[nom_inter5]=='On' then --On ne passe l'interrupteur virtuel à Off que s'il est sur On.
commandArray[nom_inter5]='Off'
print(' '.. nom_inter5 ..' perdu!')
end
end
end
if (otherdevices[nom_inter5]=='On' and timedifference(otherdevices_lastupdate[nom_inter5]) < 600) then
print(' '.. nom_inter5 ..' Ping < a 10min!')
end
return commandArrayEditer vos variables dans la zone "variables a éditer"
Puis ctrl+O
puis entree
puis ctrl+x
puis un:
Code : Tout sélectionner
sudo chmod +x /home/pi/domoticz/scripts/lua/script_time_ping.luaSi vous aussi vous avez un raspberry avec kodi d'installé sur votre TV vous pouvez éditer votre interrupteur et dans Off mettre:
Code : Tout sélectionner
http://192.168.0.15/jsonrpc?request=%7B%22jsonrpc%22:%222.0%22,%22method%22:%22System.Shutdown%22,%22id%22:1%7DTranquilou.