Two triggers to disable/enable macro

If you have a question or need help, this is the place to be.
Samme
Posts: 33
Joined: Tue Nov 22, 2011 9:07 am

Two triggers to disable/enable macro

Post by Samme » Tue Oct 23, 2012 10:08 am

Hi everyone!

I guess I need some python-scripting support again...

What I wan't to do is: When both "rfid.person1.is.away" and "rfid.person2.is.away" has triggered I want a macro (or trigger), lets call it "No one home" to be enabled or disabled (or triggered).

Can anyone help me with this?

Thanks!

themaster1
Experienced User
Posts: 133
Joined: Wed Feb 03, 2010 9:02 pm

Re: Two triggers to disable/enable macro

Post by themaster1 » Tue Oct 23, 2012 2:44 pm

can you post your current .xml config maybe 'cause i don't understand the way you explain it
what are rfid.person1-2.is.away ? (actions, events or what)

Samme
Posts: 33
Joined: Tue Nov 22, 2011 9:07 am

Re: Two triggers to disable/enable macro

Post by Samme » Tue Oct 23, 2012 4:25 pm

Ohh, sorry, when those two, "rfid..." which are triggers, each connected to a macro, when both has been triggered, it should generate a new trigger that is connected with a third macro!

Are you with me?

Or, if I'll put it like this!

I leave home, and then I put me rfid-key to the reader, which sets "me" as out of the house, then when my girlfriend leaves home two hours later she does the same thing, first when we're both out of the house, things should start to happen.

User avatar
Livin
Experienced User
Posts: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: Two triggers to disable/enable macro

Post by Livin » Tue Oct 23, 2012 8:02 pm

Use variables.. Each event should set a variable for each person you want to track. Then create a Macro that checks the variables when any variable is set... Thus if a person leaves a macro sets the variable P1 to Away, then the same macro checks all the variables, if they are all set to away then it triggers your House Empty macro.
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: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: Two triggers to disable/enable macro

Post by Livin » Tue Oct 23, 2012 8:04 pm

Even better... Have only one variable that is binary... Increment it every time someone is detected to leave, then the macro only have to check one variable for a specific value.. Whatever the # of people is.
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

Samme
Posts: 33
Joined: Tue Nov 22, 2011 9:07 am

Re: Two triggers to disable/enable macro

Post by Samme » Wed Oct 24, 2012 6:05 am

Sounds like good solutions both of them! But since I don't know any python it's kinda hard, do you have some sample code achieving this that I could look at and try?

Thanks!

User avatar
Livin
Experienced User
Posts: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: Two triggers to disable/enable macro

Post by Livin » Wed Oct 24, 2012 6:14 am

there are several examples... just do a quick search of the forum.
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

Samme
Posts: 33
Joined: Tue Nov 22, 2011 9:07 am

Re: Two triggers to disable/enable macro

Post by Samme » Wed Oct 24, 2012 6:46 am

Been searching around, but I didn't find anything similar to what you suggested, it's probably just me who doesn't find it.

Maybe one could store the values of the variable in a file, then, if EG for some reason is restared, it could read from the file to see which is or/were home/away before it restarted.

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Two triggers to disable/enable macro

Post by krambriw » Wed Oct 24, 2012 2:51 pm

I assume that you would receive some events also for each person coming home!?

Like you have "rfid.person1.is.away" and "rfid.person2.is.away" you would need "rfid.person1.is.home" and "rfid.person2.is.home".

Also to make it more generic and easier to make a script to keep track of the house status, could you try so that the events has the format like rfid.away 'person1' and rfid.home 'person1'

The event suffix should hold the state and the payload the actual id of the person. In this way it will be easy to count the people coming home and leaving.

As soon as the first person comes home, the counter is incrementing and an event "house not empty" can be triggered.

When people start leaving the counter is decremented until it reaches zero, then a new event "house empty" can be triggered.

Best regards, Walter

User avatar
Livin
Experienced User
Posts: 792
Joined: Wed Oct 08, 2008 4:56 am

Re: Two triggers to disable/enable macro

Post by Livin » Wed Oct 24, 2012 3:27 pm

Samme wrote:Been searching around, but I didn't find anything similar to what you suggested, it's probably just me who doesn't find it.

Maybe one could store the values of the variable in a file, then, if EG for some reason is restared, it could read from the file to see which is or/were home/away before it restarted.
there are many, many threads on python scripting with EG, variables ant the like...
http://www.eventghost.org/forum/viewtop ... f=2&t=3413 (If/Then)
viewtopic.php?f=10&t=2376&p=19146&hilit=variable#p19146 (persistent variables)
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

Samme
Posts: 33
Joined: Tue Nov 22, 2011 9:07 am

Re: Two triggers to disable/enable macro

Post by Samme » Thu Oct 25, 2012 6:31 pm

Thanks for your help and directions! I've read a lot at the forum and the web, for the last two days! But I'm not that smart at these things...anyway...

I've rearranged the triggers according to Walters idea,

So now I have Rfid.Away.Person1 0 and Rfid.Home.Person1 1

So how do I pass the payload from Rfid.Home.Person1 1 to be saved in my variable? So that eg.globals.AllAway = 0 increases and decreases?

Thankful for all and any help in the right direction!

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Two triggers to disable/enable macro

Post by krambriw » Thu Oct 25, 2012 6:40 pm

So now I have Rfid.Away.Person1 0 and Rfid.Home.Person1 1
Sorry, this is not what I asked for, I asked for this

Code: Select all

 Rfid.Away Person1 and Rfid.Home Person1
Once you have it, I will make a sample script that you can try out


BestR Walter

Samme
Posts: 33
Joined: Tue Nov 22, 2011 9:07 am

Re: Two triggers to disable/enable macro

Post by Samme » Thu Oct 25, 2012 6:58 pm

Hmm, well now I have this:

Code: Select all

eg.TriggerEvent("Josefin", payload=1, prefix="Rfid.Home", source=eg)
eg.TriggerEvent("Josefin", payload=0, prefix="Rfid.Away", source=eg)
Do you mean like this:

Code: Select all

eg.TriggerEvent("Home", payload="Josefin", prefix="Rfid", source=eg)
eg.TriggerEvent("Away", payload="Josefin", prefix="Rfid", source=eg)

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Two triggers to disable/enable macro

Post by krambriw » Fri Oct 26, 2012 4:51 am

eg.TriggerEvent("Home", payload="Josefin", prefix="Rfid", source=eg)
eg.TriggerEvent("Away", payload="Josefin", prefix="Rfid", source=eg)
Perfect, I will start writing a script based on that

BestR Walter

krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Two triggers to disable/enable macro

Post by krambriw » Fri Oct 26, 2012 6:33 am

So here is the first proposed solution to control presence in your house. Look at the picture below:
Image2.jpg
Image2.jpg (10.76 KiB) Viewed 9028 times
You create 3 macros,
- first holding the python script that you copy & paste from below and the two possible events that can happen when people are using their rfid tags
- second macro with the event 'Main.HousePresenceControl|Away' and the actions you need to do when house gets empty
- third macro with the event 'Main.HousePresenceControl|Home' and the actions you need to do as soon as someone is coming home

Function will be as follows:

The script is counting when people are leaving and coming home. When there are nobody at home anymore the event 'Main.HousePresenceControl|Away' is triggered.

When the house is empty and the first person arrives home, another event 'Main.HousePresenceControl|Home' is triggered.

The two events are then used in the other two macros you have created to do the things that are needed for the two states (like turning on / off lights etc).

This solution works fine as long as you do not edit the script or restart EG (or the computer). The default state is empty house.

To make this thing survive restarts, we need to introduce persistence as indicated by Livin. It is nothing complicated (except that the script will have some more code and that you need to add that plugin pVar) but I think we shall make that in a second step once you are familiar with the script and the functions described above.

BestR Walter

Code: Select all

#A simple house presence control

name = 'HousePresenceControl'
newEvent = str(eg.event.suffix)
newPayload = eg.event.payload

try:
    counter
    status 
except NameError:
    counter = 0
    status = ''

if newEvent == 'Home':
    counter += 1

if newEvent == 'Away':
    counter -= 1
    if counter < 0:
        counter = 0    

if counter == 0 and (status == 'Home' or status == ''): 
        status = 'Away'
        eg.TriggerEvent(
            name
            +"|"
            +status
        )

if counter == 1 and (status == 'Away' or status == ''): 
        status = 'Home'
        eg.TriggerEvent(
            name
            +"|"
            +status
        )


Post Reply