Running time script every 30 secs

Post Reply
void
Posts: 32
Joined: Wednesday 04 November 2015 11:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Running time script every 30 secs

Post by void » Monday 30 November 2015 21:50

Hi,

Anyone knows if it is possible to run the time based scripts more often?
For instance, twice per minute instead of 'only' one time?
I noticed my presence detection isn't fast enough.

Cheers.

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Running time script every 30 secs

Post by Egregius » Monday 30 November 2015 23:19

Run it by cron.
* * * * * /path/script
* * * * * sleep 30 && /path/script

void
Posts: 32
Joined: Wednesday 04 November 2015 11:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void » Tuesday 01 December 2015 9:53

Oh can LUA scripts be started from the shell as well?
I thought it was an interal domoticz thingy.

User avatar
Egregius
Posts: 2739
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: Running time script every 30 secs

Post by Egregius » Tuesday 01 December 2015 19:25

Don't know about lua, I don't use that :lol:
Php does everything I want :mrgreen:

User avatar
jvdz
Posts: 1447
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Running time script every 30 secs

Post by jvdz » Tuesday 01 December 2015 20:07

void wrote:Oh can LUA scripts be started from the shell as well?
I thought it was an interal domoticz thingy.
Yes you can but won't have the event tables available so need to use JSON call to request information or send commands from/to Domoticz.

Jos

void
Posts: 32
Joined: Wednesday 04 November 2015 11:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void » Wednesday 02 December 2015 11:21

Do you have an example Jos?
I thought it would be easyer to call a second bash script in the LUA that slept for x-seconds, but LUA is screaming in the logs that the script is running longer then 10 seconds.
Apparently that's a bad thing...

User avatar
ThinkPad
Posts: 1754
Joined: Tuesday 30 September 2014 8:49
Target OS: Linux
Domoticz version: beta
Location: The Netherlands
Contact:

Re: Running time script every 30 secs

Post by ThinkPad » Wednesday 02 December 2015 12:44

I don't know how your presence detection works, but maybe you can convert the script to a 'script_device_presence.lua' instead of a 'script_time_presence.lua' ?
A script_device is ran on EVERY device update, so much faster.

Then in the script, check for your device if it has changed:

if devicechanged(['switch1234']== 'On')
rest of your script...
ThinkTheme - theme for Domoticz
My (Dutch) blog: http://thinkpad.tweakblogs.net - My Domoticz scripts: Bitbucket
I'm not (very) active anymore on this forum as i don't use Domoticz anymore.

rimram31
Posts: 9
Joined: Sunday 04 October 2015 11:25
Target OS: Raspberry Pi
Domoticz version:
Location: France
Contact:

Re: Running time script every 30 secs

Post by rimram31 » Wednesday 02 December 2015 16:39

Perhaps both :-)

Having a shell script checking presence every xx s and, when happened, only setting on a domoticz dummy device so a domoticz lua script later make the rest of the job.

User avatar
jvdz
Posts: 1447
Joined: Tuesday 30 December 2014 20:25
Target OS: Raspberry Pi
Domoticz version: Stable
Location: Westland/Netherlands
Contact:

Re: Running time script every 30 secs

Post by jvdz » Wednesday 02 December 2015 17:45

void wrote:Do you have an example Jos?
I thought it would be easyer to call a second bash script in the LUA that slept for x-seconds, but LUA is screaming in the logs that the script is running longer then 10 seconds.
Apparently that's a bad thing...
You could look at the scripts that simon (and me for the menu extension) build for DTGBOT. ( https://www.domoticz.com/wiki/Remote_Co ... legram_Bot)
There are several functions in there to retrieve device status and set devices.

Jos

void
Posts: 32
Joined: Wednesday 04 November 2015 11:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void » Thursday 03 December 2015 9:44

ThinkPad wrote:I don't know how your presence detection works, but maybe you can convert the script to a 'script_device_presence.lua' instead of a 'script_time_presence.lua' ?
A script_device is ran on EVERY device update, so much faster.

Then in the script, check for your device if it has changed:

if devicechanged(['switch1234']== 'On')
rest of your script...
It's this one viewtopic.php?f=23&t=5256
Every <time based, so 1 minute> the LUA runs arp-scan and updates the dummy switches.

Perhaps changing to a device script might work, I'll check it out.
Thanks!

void
Posts: 32
Joined: Wednesday 04 November 2015 11:26
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void » Thursday 03 December 2015 12:56

It works in basic, but it's running multiple times simultainiously now.
Log:
2015-12-03 11:42:25.233 LUA: SGS6; now:2015-12-03 11:42:24; last seen: 2015-12-03 11:39:23
2015-12-03 11:42:25.235 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Presence.lua
2015-12-03 11:42:26.403 LUA: SGS6; now:2015-12-03 11:42:25; last seen: 2015-12-03 11:39:23
2015-12-03 11:42:26.405 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Presence.lua
2015-12-03 11:42:27.564 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Presence.lua
2015-12-03 11:42:27.572 LUA: *** No trusted phones connected to wireless, enabling alarm and turning off lights ***
2015-12-03 11:42:27.764 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Arm.lua
2015-12-03 11:42:26.414 (DUMMY) Lighting 1 (SGS6)
2015-12-03 11:42:28.934 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Presence.lua
2015-12-03 11:42:30.134 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Presence.lua
2015-12-03 11:42:30.142 LUA: *** No trusted phones connected to wireless, enabling alarm and turning off lights ***
2015-12-03 11:42:30.289 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Arm.lua
2015-12-03 11:42:28.942 (DUMMY) Lighting 1 (SGS6)
As you can see the detection of the phone (Device name is SGS6) gets triggered twice, with 200ms apart.
This results in a double notification from the Telegram bot and other triggers such as turning off all the lights being executed two times right after eachother.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests