LUA script question?

Moderator: leecollings

Post Reply
Walduss
Posts: 4
Joined: Monday 21 November 2016 23:09
Target OS: Linux
Domoticz version: Stable
Contact:

LUA script question?

Post 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
User avatar
jvdz
Posts: 2334
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: LUA script question?

Post 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
New Garbage collection scripts: https://github.com/jvanderzande/GarbageCalendar
Walduss
Posts: 4
Joined: Monday 21 November 2016 23:09
Target OS: Linux
Domoticz version: Stable
Contact:

Re: LUA script question?

Post 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
jake
Posts: 744
Joined: Saturday 30 May 2015 22:40
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Contact:

Re: LUA script question?

Post by jake »

I use the built in ping option in Domoticz. No need for scripting at all
Walduss
Posts: 4
Joined: Monday 21 November 2016 23:09
Target OS: Linux
Domoticz version: Stable
Contact:

Re: LUA script question?

Post 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...
User avatar
HansieNL
Posts: 964
Joined: Monday 28 September 2015 15:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: LUA script question?

Post 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
Blah blah blah
Walduss
Posts: 4
Joined: Monday 21 November 2016 23:09
Target OS: Linux
Domoticz version: Stable
Contact:

Re: LUA script question?

Post by Walduss »

Thanks a lot for helping!!
It works very good !
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest