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.

Can somebody help me with a function, please?

Do you have questions about writing plugins or scripts in Python? Meet the coders here.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

Data type mismatch it seems, it works ok for me setting the value as int...and changing to string back and forth.

1) Try to manually delete the 'WC' key from registry and try again

2) Or change the code in the script as below (I'm not sure it will help)

Code: Select all

    res = eg.plugins.System.RegistryQuery(const1, const2+var1, const3, int(var2), const4)
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

I just realize, I have the original System plugin, you have your own patched version for the registry stuff....could that influence?
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

I don't know. Perhaps? The weird thing is that I don't see any references to an integer in the script you made. Is that automatically infered?
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

Is not so weird

The line you added to the system plugin
newValue = eg.ParseString(newValue)
is expecting a string

Maybe you should try the script with just strings

Code: Select all

def SetReg(var1, var2):
    const1 = 2147483649L
    const2 = u'Software\\Automatisering\\Styring av ovner\\'
    const3 = u'Modus'
    res = eg.plugins.System.RegistryChange(const1, const2+var1, const3, 0, None, var2)
    return res


def GetReg(var1, var2):
    const1 = 2147483649L
    const2 = u'Software\\Automatisering\\Styring av ovner\\'
    const3 = u'Modus'
    const4 = u''
    res = eg.plugins.System.RegistryQuery(const1, const2+var1, const3, var2, const4)
    return res

myRes = SetReg(u'WC',u'3')
print myRes

myRes = GetReg(u'WC',1)
print myRes
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

Closer! And I have managed to "tame" it. For some reason it created a DWORD, not a regular value, but that doesn't much matter. I had messed up one of the things - the get function needed to have Modus as the variable (so I can use it for Temp and other stuff as well). But using a small, dirty trick, I get this:

Code: Select all

def SetReg(var1, var2):
    const1 = 2147483649L
    const2 = u'Software\\Automatisering\\Styring av ovner\\'
    const3 = u'Modus'
    res = eg.plugins.System.RegistryChange(const1, const2+var1, const3, 0, None, var2)
    return res


def GetReg(var1, var2):
    const1 = 2147483649L
    const2 = u'Software\\Automatisering\\Styring av ovner\\'
    const3 = 1
    const4 = u''
    res = eg.plugins.System.RegistryQuery(const1, const2+var1, var2, const3, const4)
    return int(res)

myRes = SetReg(u'WC',u'3')
#print myRes

myRes = GetReg(u'WC',u'Modus')
print myRes
So now I can set and get! :D Thanks again, this is giving me something to do tonight, messing around with all the scripts. I am even considering having even only one script that covers all the rooms, with a translate table at the beginning, converting the ID number of the Viking sensors to the variable containing the name of the room. EG does run everything sequentially, right? So if two temps comes from the RFXtrx at the same time it won't mess up the script by running anything at the same time?
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

Only thing missing was to make it global, like this:

Code: Select all

eg.globals.SetReg = SetReg
eg.globals.GetReg = GetReg
I will put that in my startup sequence and then use only this for triggering:

Code: Select all

myRes = eg.globals.SetReg(u'WC',u'3')

Code: Select all

myRes = eg.globals.GetReg(u'WC',u'Modus')
Still creates DWORD values, but I get it back as integers, which I tested with this:

Code: Select all

myRes = eg.globals.GetReg(u'WC',u'Modus')
print myRes+100
And the result was 103, 102 and 101. :D
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

Good to hear!
EG does run everything sequentially, right? So if two temps comes from the RFXtrx at the same time it won't mess up the script by running anything at the same time?
Correct, it will run sequentially and RFXtrx will not provide two events at exactly the same time, there will be at least a small time diff in between which means that your script will run once for every event. If it is a very heavy script, it could be good to think twice about having everything in one or keep them splitted. I have had very big scripts running without a problem.
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

I'm thinking one script right now, with all the active Viking sensors as events. And I will have a translate table in the startup script that makes the ID of the Vikings into the name of the room. If I can find out how I can make that. I could of course do something like this:

Code: Select all

if eg.event.payload[0] = 4337:
	Rom = WC
	
if eg.event.payload[0] = 13312:
	Rom = Gjesterom
And so on, for each Viking. But I wonder if it isn't better with a translate table, which I could make if this was LUA! :mrgreen: Is there a similar function in Python that I can put in my startup script and automagically makes this happen:
Rom = eg.event.payload[0]
Print Rom
And then I get WC instead of 4337 as the output.
User avatar
Pako
Plugin Developer
Posts: 2294
Joined: Sat Nov 11, 2006 1:31 pm
Location: Czech Republic
Contact:

Re: Can somebody help me with a function, please?

Post by Pako »

Code: Select all

conv_table = {4337:"WC", 13312:"Gjesterom"}
Rom = conv_table[eg.event.payload[0]]
Pako
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

Thank you very much, Pako! I will implement this. I'm very close now, the only thing that I still can't get is why I'm getting the result [u'43776'] instead of just 43776 from this code:

Code: Select all

Sensor = eg.eventString.split(' ')
VikingID = [Sensor[4]]
When I do the same to payload, I only get the numbers, not the brackets and the u' ':

Code: Select all

my_data = eg.event.payload_copy.split(' ')
rom_temp = my_data[2] #temperature
rom_signal = my_data[6] #signal
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

Forgot to say what it works out of. This is the raw event string without changes when I do print (eg.eventString)

Code: Select all

RFXtrx.Type: Viking 02811 id: 32768
This is what I get when I have done Sensor = eg.eventString_copy.split(' ')

Code: Select all

[u'RFXtrx.Type:', u'Viking', u'02811', u'id:', u'13312']
I really don't understand why it changes so much because of the split, since the payload doesn't from the same method.
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

Yes, that is strange...
Mastiff
Experienced User
Posts: 872
Joined: Thu May 03, 2012 10:43 am

Re: Can somebody help me with a function, please?

Post by Mastiff »

Bingo! Thanks again! :mrgreen: How silly of me, two extra brackets and it's all messed up... I'm glad this stuff isn't for the self-drive system of my Tesla, which I hope to be able to afford in some years, when the final kid is out! :)
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

I'm not sure, just edited my reply...
krambriw
Plugin Developer
Posts: 2570
Joined: Sat Jun 30, 2007 2:51 pm
Location: Stockholm, Sweden
Contact:

Re: Can somebody help me with a function, please?

Post by krambriw »

Sensor = eg.eventString.split(' ')
VikingID = [Sensor[4]]
In the example above, we need first to understand what data types we have and then what operations we are applying. Your event string looks something like this:

Code: Select all

RFXtrx.Type: Viking 02811 id: 32768
Then you are applying a split(' ') on the string which means "create me a list with the elements you can find when splitting with a space"

So the result should become

Code: Select all

[u'RFXtrx.Type:', u'Viking', u'02811', u'id:', u'32768']
a list with a number of unicode strings

So far, so good

But then, when you are doing this
Sensor = eg.eventString.split(' ')
VikingID = [Sensor[4]]
you get what you ask for

The correct syntax should be
Sensor = eg.eventString.split(' ')
VikingID = Sensor[4]
#or if you want an int
VikingID = int(Sensor[4])
Post Reply