Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details

If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.

Macro Wait until event or condition

If you have a question or need help, this is the place to be.
Post Reply
jlutsky
Posts: 16
Joined: Sun Mar 08, 2015 10:43 am

Macro Wait until event or condition

Post by jlutsky »

Hello!

I have a macro with a python script that I want to delay running until a certain variable condition is met once the macro is initially triggered. Is there a way to "Wait for Event" or program some sort of loop that continues to check the variable condition until it's met, and re-trigger the same macro, without locking up the rest of the system?
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Macro Wait until event or condition

Post by Pako »

This requires some scripting.
But maybe it can be done differently if you tell us the details of your intentions.

Pako
jlutsky
Posts: 16
Joined: Sun Mar 08, 2015 10:43 am

Re: Macro Wait until event or condition

Post by jlutsky »

Pako wrote:This requires some scripting.
But maybe it can be done differently if you tell us the details of your intentions.

Pako
-First I trigger a 'Speech' macro via HTTP and send along a string via payload to speak out loud. The speech macro first toggles on a z-wave relay device via the Vera plugin to activate my house speaker system before speaking. Then after speaking it toggles off the z-wave relay.
-Then I trigger a 2nd macro via HTTP that powers down an amplifier via RS232. The thing is, even though I send both HTTP triggers one after another, to separate macros, I need to wait until the z-wave relay has been toggled back off in the first macro before the 2nd macro does it's RS232 stuff.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Macro Wait until event or condition

Post by Pako »

I made a picture that would illustrate the situation.
jlutsky01.png
jlutsky01.png (13.11 KiB) Viewed 4940 times
I understand this correctly?
Here offer other important issues, otherwise I can not continue.
How will I know, that the z-wave relay is off ?
The time between the command to toggle off the z-wave relay and its real switch-off is highly variable?

Pako
jlutsky
Posts: 16
Joined: Sun Mar 08, 2015 10:43 am

Re: Macro Wait until event or condition

Post by jlutsky »

Pako wrote:I made a picture that would illustrate the situation.
The attachment jlutsky01.png is no longer available
I understand this correctly?
Here offer other important issues, otherwise I can not continue.
How will I know, that the z-wave relay is off ?
The time between the command to toggle off the z-wave relay and its real switch-off is highly variable?

Pako
Here is a screen grab of my specific setup.

On my Vera, I send off 2 HTTP requests to EventGhost, one right after the other.

http://192.168.x.x:8082/?House.Speak&TextToSpeakOutLoud
http://192.168.x.x:8082/?MonoAmp.Control&0&Power&0

Even though both HTTP events are being triggered from my Vera at the same time, the 2nd event 'MonoAmp.Control' needs to wait to execute it's python script until the first event 'House.Speak' finishes speaking, and subsequently triggers the 'Relay Off' macro.
Attachments
eggrab.jpg
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Macro Wait until event or condition

Post by Pako »

I do not understand the configuration.
1) Why do you need that event HTTP.MnoAmp.Control, when both events (along with HTTP.House.Speak) you are sending at the same time?
2) Why the event Speek.SpeakingFinished.0 is not used directly in the macro MonoAmp.Control?
3) What is the point of the variable IsSpeaking ? It is used anywhere else?

Pako
jlutsky
Posts: 16
Joined: Sun Mar 08, 2015 10:43 am

Re: Macro Wait until event or condition

Post by jlutsky »

Pako wrote:I do not understand the configuration.
1) Why do you need that event HTTP.MnoAmp.Control, when both events (along with HTTP.House.Speak) you are sending at the same time?
2) Why the event Speek.SpeakingFinished.0 is not used directly in the macro MonoAmp.Control?
3) What is the point of the variable IsSpeaking ? It is used anywhere else?

Pako
1-2) In other scenarios I sent just HTTP.House.Speak without any MonoAmp control. And in other scenarios I send just HTTP.MnoAmp.Control without speaking anything. They have independent uses, in addition to being used together sometimes.
3) IsSpeaking was a hold over variable from something else. I can get rid of that now.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Macro Wait until event or condition

Post by Pako »

I have a supplementary question:
It is possible (in this particular case) omit the event HTTP.MonoAmp.Control?
If so, it seems that the problem is solved.
Into the macro MonoAmp.Control simply add another event (Speek.SpeakingFinished.0).

Pako
jlutsky
Posts: 16
Joined: Sun Mar 08, 2015 10:43 am

Re: Macro Wait until event or condition

Post by jlutsky »

Pako wrote:I have a supplementary question:
It is possible (in this particular case) omit the event HTTP.MonoAmp.Control?
If so, it seems that the problem is solved.
Into the macro MonoAmp.Control simply add another event (Speek.SpeakingFinished.0).

Pako
No, because I need to pass several parameters to the MonoAmp.control macro as well. Parameters like the channel to control, the command (like power or volume) and a value. These parameters change, and I send them via the HTTP URL.

... I actually think I found a solution using the following python script for MonoAmp.Control. The only issue here is that it stores the initial payload in global variables. I'd much rather pass the payload directly each time, but Timer plugin doesn't support payload. If another HTTP.MonoAmp.Control event gets triggered while the first one is still going, the global variables don't work right.

import urllib

def run():
if eg.globals.MonoAmpPA == 0:
eg.globals.i = 0
if eg.globals.Channel == 0:
url = 'http://192.168.0.4:50230/api/Command?command=' + eg.globals.Command + '&value=' + eg.globals.Value
rllib.urlopen(url)
else:
url = 'http://192.168.0.4:50230/api/Command?unit=1&channel=' + eg.globals.Channel + '&command=' + eg.globals.Command + '&value=' + eg.globals.Value
urllib.urlopen(url)
#print url
else:
#strEvent = "u\'ReTry[" + xChannel + "," + xCommand + "," + xValue + "]\'"
#eg.plugins.Timer.TimerAction(u'SomeName', 0, 1, 1.0, strEvent, False, True, 1, u'00:00:00')
eg.plugins.Timer.TimerAction(u'SomeName', 0, 1, 1.0, u'Timer.ReTry', False, True, 1, u'00:00:00')

if eg.globals.i == 0:
eg.globals.i = 1
eg.globals.Channel = eg.event.payload[0]
eg.globals.Command = eg.event.payload[1]
eg.globals.Value = eg.event.payload[2]

run()
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Macro Wait until event or condition

Post by Pako »

I think this is a better way:
1) The payload you can attach to the event HTTP.House.Speak
2) In the macro House.Speak you can add something like

Code: Select all

eg.globals.myPayload = eg.event.payload[1:]
3) The script in the macro MonoAmp.Control can start with something like this:

Code: Select all

payload = eg.event.payload if eg.event.payload is not None else eg.globals.myPayload
Pako
Post Reply