IF THEN ELSE? of JUMP IF?

If you have a question or need help, this is the place to be.

IF THEN ELSE? of JUMP IF?

Postby SlipStream » Thu Aug 25, 2011 6:47 am

I am a long time automation installer, and i have been trying to utilize EG for macros to run a home theater system. Now with almost all other remotes i have worked with there is some kind of a "flag" system where if said command is ran then said flag is enabled or disabled, then there is a if flag is enabled then do this or if disabled do that. is there a way to do this in EG, maybe enable/disable an item and have a check if that item is enabled or disabled then execute item/macro depending on its state?
SlipStream
 
Posts: 8
Joined: Fri Feb 19, 2010 2:21 am

Re: IF THEN ELSE? of JUMP IF?

Postby Pako » Thu Aug 25, 2011 7:52 am

Given that EventGhost is based on events, I recommend use Python script action.
There you can test any conditions. As a result, then use the function eg.TriggerEvent .
Pako
User avatar
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: IF THEN ELSE? of JUMP IF?

Postby SlipStream » Thu Aug 25, 2011 8:52 pm

can you give me an example and explain it or, can you point me to a place that can explain python scrypting, I am not familar with python. Thanks
SlipStream
 
Posts: 8
Joined: Fri Feb 19, 2010 2:21 am

Re: IF THEN ELSE? of JUMP IF?

Postby Livin » Fri Aug 26, 2011 12:01 am

fyi - your title does not really give a clue to what you are really looking for. ;)

You want to use variables. See this thread...

viewtopic.php?f=10&t=2376&p=19146&hilit=variable#p19146


what are your trying to automate?
setup... XBMC, W7MC for DVR & Live OTA TV, JRMC for multi-zone audio, EG, MiCasaVerde Vera3, USB-UIRT IR receiver, Harmony remote, 5.2 home theater system
User avatar
Livin
Experienced User
 
Posts: 749
Joined: Wed Oct 08, 2008 4:56 am

Re: IF THEN ELSE? of JUMP IF?

Postby skat » Fri Aug 26, 2011 4:47 am

Have a look at the built-in Jump action which can be controlled by the value of eg.result (True/False).
skat
 
Posts: 48
Joined: Thu Jun 23, 2011 10:11 am

Re: IF THEN ELSE? of JUMP IF?

Postby Pako » Fri Aug 26, 2011 7:54 am

SlipStream wrote:can you give me an example and explain it or, can you point me to a place that can explain python scrypting, I am not familar with python. Thanks
Attached is a simple example.
You have to add some events to macros Decision, MyVar_1 = True, MyVar_1 = False and Toggle MyVar_1 (or run them manually).
I think that if you do you study it, you'll know everything you need.

I think you do not need use the Persistent variables.

Pako
Attachments
IF_THEN_ELSE_example.xml
(2.3 KiB) Downloaded 322 times
User avatar
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: IF THEN ELSE? of JUMP IF?

Postby SlipStream » Sat Aug 27, 2011 7:03 am

Pako, thanks a bunch,its a little bulky but i think that will work. one thing i cant figure out is. is there a place to see the state of myvar_1 whether it is true or false?
SlipStream
 
Posts: 8
Joined: Fri Feb 19, 2010 2:21 am

Re: IF THEN ELSE? of JUMP IF?

Postby Livin » Sat Aug 27, 2011 8:56 pm

Pako,
I'll try this in a few days when I get home. It would be cool to have this as a plugin where the plugin asks the user for the conditions and it creates the code for the user.
setup... XBMC, W7MC for DVR & Live OTA TV, JRMC for multi-zone audio, EG, MiCasaVerde Vera3, USB-UIRT IR receiver, Harmony remote, 5.2 home theater system
User avatar
Livin
Experienced User
 
Posts: 749
Joined: Wed Oct 08, 2008 4:56 am

Re: IF THEN ELSE? of JUMP IF?

Postby Pako » Sun Aug 28, 2011 7:48 am

SlipStream wrote:Pako, thanks a bunch,its a little bulky but i think that will work. one thing i cant figure out is. is there a place to see the state of myvar_1 whether it is true or false?
Sure, it's very simple.
You can create the following macro (action Python Command):
Macro-Status.gif
Macro-Status.gif (2.06 KiB) Viewed 1892 times
When you need to know the state of a variable, you just run this macro.
The result you will see in the logger.

Pako
User avatar
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: IF THEN ELSE? of JUMP IF?

Postby SlipStream » Wed Aug 31, 2011 12:41 am

Pako,
Thanks for all your help, i think i have a good grip on this system now, what i did for a live status update, is in the folder for the variable script, i mad a bunch of comments, named them according to what i need, then in the macro that gets triggered by the event that got fired off by the if statment, i placed disable/enable commands, so now i can just open that folder and see all the status of the variables on the fly.

One thing i am having an issue with, is these if statments have two parts the event that it fires off if it is true and the event that it fires off if it is false. Is there a way to if the if statement fire off an event if say the condition was true or false, but if the "else" was the oposite dont do anything. I still need the if logic intact, what i have been doing for the time being is this

Code: Select all
if eg.globals.Tv:
    eg.TriggerEvent("Tv-True")
else:
    eg.TriggerEvent("DoNothing")


the reason i need this is the tv-false variable might be part of another macro which is triggered by that event. so what has been happening is in the top condidtion i can state that to be tv-true or tv-false then the else i just use "DoNothing" as the event which is not linked to anything. this way i have a switch which is, if said variable is true/false do this, else do nothing. My question is this, is this the cleanest way of doing this or is there something more simple?
SlipStream
 
Posts: 8
Joined: Fri Feb 19, 2010 2:21 am

Re: IF THEN ELSE? of JUMP IF?

Postby SlipStream » Wed Aug 31, 2011 2:09 am

Also if you can take a look at this, tell me what you think.

This is all the work put together to function. This is designed to be a "smart" controller for an entertainment center including a tv, bluray, cable, and a receiver. You can execute the different macros in the macro folder to do a desired fuction, and then you can see the virtual status of the device on the flags/status folder. the comments that are named per device will enable/disable depending if there variable counterpart goes true/false. that will give you some sense of the device being in a state of on/enabled or off/disabled. Now the biggest reason i did this was to be able to fire a simple macro and have it check the virtual status of a device and fire a specfic command due to the status/state of that device or do nothing if it is already in the desider state. Even if the user hits the same macro again it wont behave the same because the device states have changed so it wont fire the same commands again to screw everything up.
Attachments
Entertainment Center.xml
(12.74 KiB) Downloaded 100 times
SlipStream
 
Posts: 8
Joined: Fri Feb 19, 2010 2:21 am

Re: IF THEN ELSE? of JUMP IF?

Postby Pako » Wed Aug 31, 2011 6:18 am

SlipStream wrote: ...the reason i need this is the tv-false variable might be part of another macro which is triggered by that event. so what has been happening is in the top condidtion i can state that to be tv-true or tv-false then the else i just use "DoNothing" as the event which is not linked to anything. this way i have a switch which is, if said variable is true/false do this, else do nothing. My question is this, is this the cleanest way of doing this or is there something more simple?
My English is poor so I'm not sure, that I understand this well. If you do not need (it is not used in any macro) the event Main.DoNothing, of course you can make the simplification:
Code: Select all
if eg.globals.Tv:
    eg.TriggerEvent("Tv-True")
Pako
User avatar
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic

Re: IF THEN ELSE? of JUMP IF?

Postby Pako » Wed Aug 31, 2011 7:15 am

SlipStream wrote:Also if you can take a look at this, tell me what you think.
I, unfortunately, probably not quite understand the logic of your solution.
However, (if I did not make a mistake) my simplification should do exactly the same work.

Pako
Attachments
Entertainment Center Simplification.xml
(10.39 KiB) Downloaded 145 times
User avatar
Pako
Plugin Developer
 
Posts: 1282
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic


Return to General Support

Who is online

Users browsing this forum: Google Adsense [Bot], krambriw and 2 guests