Page 1 of 1

os.execute.aftersec

Posted: Tuesday 21 November 2017 7:35
by markjgabb
is there a way to get a delayed os.execute working in dzvents atm i have the following

os.execute('espeak welcome-home').afterSec(20)
but it seems to ifnore the aftersec and just runs it instantly.....
also not sure how to make longer that one word arguments os the os.execute as it will only take one word at the moment

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 8:11
by dannybloe
os.execute is an os function that is not managed at all by dzVents. So no, that's not working unfortunately. Maybe you can create some bash function with an internal delay and execute that instead from your script.

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 8:12
by markjgabb
that sounds like a likely way to do it...simple and it works :D

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 8:28
by BakSeeDaa
Below is an example how it can be done. This specific example calls an url using curl on a linux platform. The important thing is to release the control back to Domoticz immediately.

Code: Select all

local delay = 5
local url = 'http://somwebsite.com'
os.execute('(sleep '..delay..';curl -s "'..url..'" > /dev/null)&')

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 8:49
by markjgabb
have used this method and its works wonderfully thanks guys for the advice......now to laugh at wifes reaction when house welcomes her home later on

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 10:51
by BakSeeDaa
markjgabb wrote: Tuesday 21 November 2017 8:49 have used this method and its works wonderfully thanks guys for the advice......now to laugh at wifes reaction when house welcomes her home later on
We should not underestimate the importance of WAF for the future of home automation. ;)

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 13:49
by poudenes
BakSeeDaa wrote: Tuesday 21 November 2017 8:28 Below is an example how it can be done. This specific example calls an url using curl on a linux platform. The important thing is to release the control back to Domoticz immediately.

Code: Select all

local delay = 5
local url = 'http://somwebsite.com'
os.execute('(sleep '..delay..';curl -s "'..url..'" > /dev/null)&')
What is the reason you put this a the end: > /dev/null)&
I use os.execute as well but then just the URL :

Code: Select all

os.execute('curl "http://127.0.0.1:8081/json.htm?type=command&param=setcolbrightnessvalue&idx=3&hue=18&brightness=50&iswhite=false"')

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 14:59
by BakSeeDaa
poudenes wrote: Tuesday 21 November 2017 13:49
What is the reason you put this a the end: > /dev/null)&
I use os.execute as well but then just the URL :

Code: Select all

os.execute('curl "http://127.0.0.1:8081/json.htm?type=command&param=setcolbrightnessvalue&idx=3&hue=18&brightness=50&iswhite=false"')
It's a redirection (discard) of the command output (not necessary) followed by the ampersand sign that will cause the command to run in the background. (prevents delays caused by waiting for the command to finish)

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 15:01
by poudenes
BakSeeDaa wrote: Tuesday 21 November 2017 14:59
poudenes wrote: Tuesday 21 November 2017 13:49
What is the reason you put this a the end: > /dev/null)&
I use os.execute as well but then just the URL :

Code: Select all

os.execute('curl "http://127.0.0.1:8081/json.htm?type=command&param=setcolbrightnessvalue&idx=3&hue=18&brightness=50&iswhite=false"')
It's a redirection (discard) of the command output (not necessary) followed by the ampersand sign that will cause the command to run in the background. (prevents delays caused by waiting for the command to finish)
Thanks for the "always" great help!!!. I will add them as well then :)

Re: os.execute.aftersec

Posted: Tuesday 21 November 2017 15:44
by BakSeeDaa
poudenes wrote: Tuesday 21 November 2017 15:01 Thanks for the "always" great help!!!. I will add them as well then :)
Your'e welcome. Don't forget the inner parenthesis which is crucial for it to work.

Re: os.execute.aftersec

Posted: Wednesday 22 November 2017 9:47
by poudenes
BakSeeDaa wrote: Tuesday 21 November 2017 15:44
poudenes wrote: Tuesday 21 November 2017 15:01 Thanks for the "always" great help!!!. I will add them as well then :)
Your'e welcome. Don't forget the inner parenthesis which is crucial for it to work.
So it will look like this then :)

Code: Select all

os.execute('(curl -s  "http://127.0.0.1:8081/........iswhite=false" > /dev/null)&')

Re: os.execute.aftersec

Posted: Wednesday 22 November 2017 10:48
by Nautilus
This should be enough when you don't need the separate sleep command:

Code: Select all

os.execute('curl -s "http://127.0.0.1:8081/json.htm?type=command&param=setcolbrightnessvalue&idx=3&hue=18&brightness=50&iswhite=false" &')

Re: os.execute.aftersec

Posted: Sunday 23 September 2018 6:19
by ben53252642
Using this in a Lua script to run multiple commands using os.execute, thanks!

Code: Select all

os.execute ('(/bin/sleep 4 && /usr/bin/curl -s "http://192.168.0.5:1880/hueapi?devicename=lightstripmainbathmirror&state=on&brightness=254&r=0&g=0&b=0&colortemp=351&transition=0.5")&')