Page 1 of 1
LUA script question?
Posted: Friday 24 March 2017 13:37
by Walduss
Hi guys
Could someone explain me this strange behavior?
I have dummy switch which show me state of internet connection.
I used script to update it as below
Code: Select all
commandArray = {}
ping_success=os.execute('ping -c1 8.8.8.8')
if ping_success then
print("ping success")
commandArray['Internet']='On'
else
print("ping fail")
ommandArray['Internet']='Off'
end
return commandArray
I named it as: script_time_internet, so it will be executed every min.
But in log in switch i have data every 3 seconds. Why not every 1min?
Code: Select all
2017-03-23 13:12:44 On
2017-03-23 13:12:40 On
2017-03-23 13:12:37 On
2017-03-23 13:12:34 On
2017-03-23 13:12:31 On
2017-03-23 13:12:28 On
2017-03-23 13:12:25 On
2017-03-23 13:12:22 On
2017-03-23 13:12:19 On
What magic is here that it runs every 3sec not 1min?
Regards
Re: LUA script question?
Posted: Friday 24 March 2017 13:48
by jvdz
You created this script in the internal editor and have All under the Lua dropdown?
This means the this script will trigger on ALL events, so whenever any device changes or Time changes.
Change All to Time should fix it.
2 comments:
I would only set the dummy switch when it is not the same, so test against the current value.
.. but more importantly: I would never add a script to the event system as it is single threaded, meaning that all your scripts/logic will be delayed in responding till the ping command is finished (which seems to be about 3 seconds in your case)
Jos
Re: LUA script question?
Posted: Friday 24 March 2017 14:22
by Walduss
Thanks Jos for suggestions.
I created in internal editor but need to check if this is set to "ALL".
I would only set the dummy switch when it is not the same, so test against the current value.
This is good point but first I wanted to understand why I got this results, so for sure I will optimize this script and set new value only when will be different than current.
.. but more importantly: I would never add a script to the event system as it is single threaded, meaning that all your scripts/logic will be delayed in responding till the ping command is finished (which seems to be about 3 seconds in your case)
I'm still fresh in this topic, can you write more about it? How to do this in more efficient way?
It will be nice to avoid mistakes on the begining
Regards
Re: LUA script question?
Posted: Friday 24 March 2017 18:16
by jake
I use the built in ping option in Domoticz. No need for scripting at all
Re: LUA script question?
Posted: Saturday 25 March 2017 0:11
by Walduss
Mystery solved

I didn't check time option in built in editor. Thx.
I use the built in ping option in Domoticz. No need for scripting at all
Where I can find it? I check all option but I don't see it...
Re: LUA script question?
Posted: Saturday 25 March 2017 2:30
by HansieNL
Hardware - Type - System Alive Check
I use the following settings:
Settings
Poll Interval: 30
Ping Time-out: 1000
Node
Timeout: 60 or 90
Re: LUA script question?
Posted: Saturday 25 March 2017 13:23
by Walduss
Thanks a lot for helping!!
It works very good !