Lua script Set after 120 if ..?

Moderator: leecollings

Post Reply
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Lua script Set after 120 if ..?

Post by henning84 »

Heii


I usually use blocky to program my functions, but want to use a function which is not possible in blocky. Thinking Lua is more advanced so I suppose it is possible here. But dont not know :)

I want this.

Dimmer 50 %
Wait 120 sek
dimmer 100% if dimmer not = off
wait 2 sek
Turn off Dimmer if dimmer not equal = Off

Is that possible..?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script Set after 120 if ..?

Post by dannybloe »

Sure... easiest way is using dzVents.

You can do stuff like:

Code: Select all

domoticz.devices['myDimmer'].dimTo(50).for_min(2)
See Timing options
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

domoticz.devices['myDimmer'].dimTo(50).for_min(2)
Here you dont have the "If dimmer not = OFF"

I want the script to wait 120 sec and check the state of a switch again, before the action..
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script Set after 120 if ..?

Post by dannybloe »

henning84 wrote:domoticz.devices['myDimmer'].dimTo(50).for_min(2)
Here you dont have the "If dimmer not = OFF"

I want the script to wait 120 sec and check the state of a switch again, before the action..
You cannot wait INSIDE a script for a(nother) device to change state. If a device changes state it will trigger a script. When that script is run you don't get state updates. Basically all states are frozen during script execution.

If you want to achieve something like this you have to do something with flags or something like that. Like you set a flag (a dummy switch or a variable or a dzVents persistent variable) and check in the next script cycle if that flag is set. So let's say you have a script that runs every two minutes. At some point you switch on a light in that script, you set a flag and the next time the script runs you check for the light and if the flag is set and then do your thing.

From what you have described I'm not able to figure out exactly what it is you want to do so I cannot help in a more detailed manner than just giving some ideas.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua script Set after 120 if ..?

Post by Egregius »

Quite simple in my pass2php script:

Code: Select all

//Dimmer 50 %
sl($i['mydimmer'],50);
//Wait 120 sek
sleep(120);
//dimmer 100% if dimmer not = off
if($s['mydimmer']!='Off') sl($i['mydimmer'],100);
//wait 2 sek
sleep(2);
//Turn off Dimmer if dimmer not equal = Off
if($s['mydimmer']!='Off') sl($i['mydimmer'],0);
 
But I'd like to know the purpose of this action...
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script Set after 120 if ..?

Post by dannybloe »

Egregius wrote:Quite simple in my pass2php script:
But I'd like to know the purpose of this action...
Yes, you tell me! I have no idea what you want to achieve with this script. It doesn't make any sense to me.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

Egregius wrote:Quite simple in my pass2php script:

Code: Select all

//Dimmer 50 %
sl($i['mydimmer'],50);
//Wait 120 sek
sleep(120);
//dimmer 100% if dimmer not = off
if($s['mydimmer']!='Off') sl($i['mydimmer'],100);
//wait 2 sek
sleep(2);
//Turn off Dimmer if dimmer not equal = Off
if($s['mydimmer']!='Off') sl($i['mydimmer'],0);
But I'd like to know the purpose of this action...
Perfect - and the sleep will not "freeze" domoticz..? Have read a thread where sleep in Lua will freeze domoticz while it sleep.


I know it dont make sense :) But the script is for my light in the kitchen, when i turn off my tv in the evening - it turn on the light in the kitchen (Normaly i dont have any light on when i watch tv, so it is quite dark when the tv turn off.) A kind of "directing light" :) But if i turn off the kitchen light when i leave the room, i dont want the script to turn on the light and turn it off 2 sec later.
Hope it make sense - my english is not so good.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Lua script Set after 120 if ..?

Post by dannybloe »

henning84 wrote:
Egregius wrote:Quite simple in my pass2php script:

Code: Select all

//Dimmer 50 %
sl($i['mydimmer'],50);
//Wait 120 sek
sleep(120);
//dimmer 100% if dimmer not = off
if($s['mydimmer']!='Off') sl($i['mydimmer'],100);
//wait 2 sek
sleep(2);
//Turn off Dimmer if dimmer not equal = Off
if($s['mydimmer']!='Off') sl($i['mydimmer'],0);
 
But I'd like to know the purpose of this action...
Perfect - and the sleep will not "freeze" domoticz..? Have read a thread where sleep in Lua will freeze domoticz while it sleep.


I know it dont make sense :) But the script is for my light in the kitchen, when i turn off my tv in the evening - it turn on the light in the kitchen (Normaly i dont have any light on when i watch tv, so it is quite dark when the tv turn off.) A kind of "directing light" :) But if i turn off the kitchen light when i leave the room, i dont want the script to turn on the light and turn it off 2 sec later.
Hope it make sense - my english is not so good.
Eh.. haha... not really (english is fine). This is getting interesting...
Can you tell me exactly the sequence/situation (if you want of course)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

Like i already told.
When i turn off my tv, it turn on the light in the kitchen.
I leave the road - 120 sec later the script dimme the light 100% (so it 100% next time i turn it on), 2 sec later it turn it off. - But some time i turn off the light my self, then i dont want the script to turn it back on and 2 sec later turn it off.

General it nice to make a IF in a "Set after XX" action..

Like

If phone OFF (ping)
Wait 2 min
If phone still off do "some thing here"
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua script Set after 120 if ..?

Post by Egregius »

Turn off tv = turn on kitchen light. That I understand.
But why does it have to go to 100% for 2 seconds? Edit: now I get it :)
Because pass2php is run seperately of domoticz it doesn't freeze anything.
Because the lua part of that script is so small it's really lightning fast and can do anything you can imagine.
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

it cut be nice to have some more "advance" opportunities in Blockly script.

How do pass2php work..? seems not really I can find something about it.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua script Set after 120 if ..?

Post by Egregius »

Blockly is for simple beginners stuff.
As soon as you want stuff really the way you want it you need to go scripting.
Because I didn't want to learn lua and knew php I came up with my pass2php script.
Afterwirds I did some speed tests and it seems by far the fastest solution to have advanced script.
With both blockly and lua the response times grow with each script you add, with pass2php not because for domoticz there's only one small lua script to handle, all the rest is done externally by the php enterpreter.
Script, code and help for pass2php in http://www.domoticz.com/forum/viewtopic ... 23&t=12343 please.
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

Thanks - i will have a look at it.

I can not PHP or LUA - so i have to start from the scratch - then blockly it seems like the easiest but also the most restrictions :/
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua script Set after 120 if ..?

Post by Egregius »

I find blockly difficult and unclear :P
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

advantage Blockly you are not required to know the code, just drag and drop. Ih PHP/LUA i have to write all the code by you self :)
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

will the pass2php work on windows..? I run Domoticz on a windows 7.
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua script Set after 120 if ..?

Post by Egregius »

Ieuw :roll: :?

Probably it will, if you get php working. Maybe with something like wamp server? Never used php on windows before. Linux rules for server applications :D
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

i am 100% windows man - sorry :)
User avatar
Egregius
Posts: 2592
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Lua script Set after 120 if ..?

Post by Egregius »

You do have Raspberry indicated as target system...
And that just because you don't know any better :P
henning84
Posts: 13
Joined: Thursday 22 October 2015 14:17
Target OS: Windows
Domoticz version:
Contact:

Re: Lua script Set after 120 if ..?

Post by henning84 »

i start on a Raspberry - but move to Windows. I have a server on 24/7 anyway.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest