Lua Ping presence script keeps running

Moderator: leecollings

Post Reply
desertdog
Posts: 84
Joined: Sunday 14 August 2016 13:45
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.1
Location: Netherlands
Contact:

Lua Ping presence script keeps running

Post by desertdog »

I am using this basic lua ping presence script which works fine except it keeps sending a ping every second. Scripts are normally fired once every minute, so how do I stop this script after one ping? Even beter would be if this script only ran once every 5 or 10 minutes. How do I achieve that?

Code: Select all

commandArray = {}

ping_success=os.execute('ping -c1 192.168.1.101')
if ping_success then
print("macbook  is online")
commandArray['testping']='On'
else
print("macbook offline")
commandArray['testping']='Off' 
end

return commandArray
User avatar
jvdz
Posts: 2333
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Lua Ping presence script keeps running

Post by jvdz »

Is this created with the internal Editor? If so, you probably have All in the dorpdownbox under LUA and need to change that to "Time".
I wouldn't recommend to have this script ran with the eventsystem as that is single threaded and could create a delay for other events.

Jos

ps, I would also add a test whether the switch actually needs to be changed:

Code: Select all

commandArray = {}

ping_success = os.execute('ping -c1 192.168.1.101')
if ping_success then
	if otherdevices['testping'] == 'Off' then
		print("macbook  is online")
		commandArray['testping'] = 'On'
	end
else
	if otherdevices['testping'] == 'On' then
		print("macbook offline")
		commandArray['testping'] = 'Off'
	end
end

return commandArray
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest