Running time script every 30 secs

Moderator: leecollings

Post Reply
void
Posts: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Running time script every 30 secs

Post by void »

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: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Running time script every 30 secs

Post by Egregius »

Run it by cron.
* * * * * /path/script
* * * * * sleep 30 && /path/script
void
Posts: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void »

Oh can LUA scripts be started from the shell as well?
I thought it was an interal domoticz thingy.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Running time script every 30 secs

Post by Egregius »

Don't know about lua, I don't use that :lol:
Php does everything I want :mrgreen:
User avatar
jvdz
Posts: 2476
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Running time script every 30 secs

Post by jvdz »

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: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void »

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...
ThinkPad
Posts: 890
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 »

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...
I am not active on this forum anymore.
rimram31
Posts: 26
Joined: Sunday 04 October 2015 11:25
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: France
Contact:

Re: Running time script every 30 secs

Post by rimram31 »

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

Re: Running time script every 30 secs

Post by jvdz »

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: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void »

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: 26
Joined: Wednesday 04 November 2015 10:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Running time script every 30 secs

Post by void »

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