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.
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.
Dealing with State Information in EventGhost
Dealing with State Information in EventGhost
I am interested in moving more of my home automation to EventGhost, but I was wondering how other people are dealing with state information. That is, I have a many devices in my house that I will be controlling and I want to keep track of various pieces of information about these devices. For instance, I have a few dozen z-wave lights and need to keep track of if the are on or off, and what level they are at if they are dimmers.
I've been using EventGhost for quite some time now and am very happy with how it deals with Events. It seems like it isn't that hard to deal with a small amount of state information (I do this already to switch what program I'm controlling with IR), but dealing with large amounts of state information doesn't seem easy to handle. I'm currious how other people handle this.
I think I am looking at is adding more control over my Vera to EventGhost. I'd like to do this so I can later build an integrated web frontend to ALL of my house. Right now my A/V control (mostly EventGhost) and Lighting (mostly Vera) are are almost completly seperate.
I've been using EventGhost for quite some time now and am very happy with how it deals with Events. It seems like it isn't that hard to deal with a small amount of state information (I do this already to switch what program I'm controlling with IR), but dealing with large amounts of state information doesn't seem easy to handle. I'm currious how other people handle this.
I think I am looking at is adding more control over my Vera to EventGhost. I'd like to do this so I can later build an integrated web frontend to ALL of my house. Right now my A/V control (mostly EventGhost) and Lighting (mostly Vera) are are almost completly seperate.
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Dealing with State Information in EventGhost
Hi,
I think it is easy to handle current states. Myself I am using dictionaries.
In runtime, everything is of course not a problem but to be able to keep latest states, I make the dictionary persistent so that it is always saved to disk. At restart, the latest known states are recovered.
But you only have to do this for states where you can not ask devices for current state. For z-wave, is it not possible at startup to ask the devices? If so you put the response in a runtime dictionary only when EG starts and during runtime you update the states when they change.
If really needed, I think it is also be possible to add support for databases. I have read some postings here where users have successfully connected to MySQL. If you search the net, I would be surprised if there are no python libraries that supports ODBC.
Best regards, Walter
I think it is easy to handle current states. Myself I am using dictionaries.
In runtime, everything is of course not a problem but to be able to keep latest states, I make the dictionary persistent so that it is always saved to disk. At restart, the latest known states are recovered.
But you only have to do this for states where you can not ask devices for current state. For z-wave, is it not possible at startup to ask the devices? If so you put the response in a runtime dictionary only when EG starts and during runtime you update the states when they change.
If really needed, I think it is also be possible to add support for databases. I have read some postings here where users have successfully connected to MySQL. If you search the net, I would be surprised if there are no python libraries that supports ODBC.
Best regards, Walter
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
Re: Dealing with State Information in EventGhost
You are absolutely right, I can very easily reload the state at runtime. I am using the Mi Casa Verde Vera 2 controller to handle z-wave and I can access its state any time with JSON. Once I connect to it it is also very easy to stay up to date. I currently have a simple Python program using Twisted that is a client to the Vera and keeps up to date with changes to the devices.
I saw some of Pako and your work on Websockets and that was actually what motivated me to look at moving everything to EventGhost. Currently I have two versions of my code, one that uses SQLite (with :memory:, not saving anything to disk) and one that uses only dictionaries. Either way works well but I got tired of having to write SQL queries and with only a few dozen devices I figured dictionaries were easier. Before moving this to EventGhost I need to figure out to move from my (very) simple Twisted based web interface to EventGhost.
I saw some of Pako and your work on Websockets and that was actually what motivated me to look at moving everything to EventGhost. Currently I have two versions of my code, one that uses SQLite (with :memory:, not saving anything to disk) and one that uses only dictionaries. Either way works well but I got tired of having to write SQL queries and with only a few dozen devices I figured dictionaries were easier. Before moving this to EventGhost I need to figure out to move from my (very) simple Twisted based web interface to EventGhost.
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Dealing with State Information in EventGhost
If you find out that you need to make your dictionary persistent, EG is supporting this very nicely.
Lets say that you need a dictionary where you need to store states:
In your script/plugin you could typically add something like this:
In your plugin code init method you could then add:
Then when you use this dictionary you would access it the following way:
When reading:
When adding/updating:
When you exit EG, it will be saved automatically to disk.
Websockets are great. Typically if you have a web page for your house automation and you update single elements when states are changing, it is working excellent. I'm still waiting for iPad's to become cheaper so I can glue a couple of them on the walls in strategic places in my house. In the mean time, I fine tune my web page to look better.
And I use (as from yesterday) Growl for Windows (free) and Prowl for the iPhone to send important messages from EG to the iPhone. This is really recommended. There is a Growl plugin for EG in the Plugin section and Prowl is only about 3$ in the AppStore. If you have an Android, I think you can use "notify my android", maybe that one is free.
I think those technologies in combination makes a perfect combo; at home and under normal conditions and for daily operations, you have some nice touch pads with a web gui using websockets. Those important events/alarms you really need to know about wherever you are, you send them using Growl.
Best regards, Walter
Lets say that you need a dictionary where you need to store states:
In your script/plugin you could typically add something like this:
Code: Select all
class CurrentStateData(eg.PersistentData):
my_states_persistent = {}
Code: Select all
self.my_states_runtime = CurrentStateData.my_states_persistent
When reading:
Code: Select all
a_state = self.my_states_runtime[an_index]Code: Select all
self.my_states_runtime[an_index] = a_stateWebsockets are great. Typically if you have a web page for your house automation and you update single elements when states are changing, it is working excellent. I'm still waiting for iPad's to become cheaper so I can glue a couple of them on the walls in strategic places in my house. In the mean time, I fine tune my web page to look better.
And I use (as from yesterday) Growl for Windows (free) and Prowl for the iPhone to send important messages from EG to the iPhone. This is really recommended. There is a Growl plugin for EG in the Plugin section and Prowl is only about 3$ in the AppStore. If you have an Android, I think you can use "notify my android", maybe that one is free.
I think those technologies in combination makes a perfect combo; at home and under normal conditions and for daily operations, you have some nice touch pads with a web gui using websockets. Those important events/alarms you really need to know about wherever you are, you send them using Growl.
Best regards, Walter
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
Re: Dealing with State Information in EventGhost
I am trying to create a presistant dictionary in a script (not plugin). It this possible? If yes, how?
Thanks,
kalia
Thanks,
kalia
Re: Dealing with State Information in EventGhost
You might look at this Persistent Variables plug-in and see if it does what you need.kalia wrote:I am trying to create a presistant dictionary in a script (not plugin). It this possible? If yes, how?
Thanks,
kalia
Re: Dealing with State Information in EventGhost
I tried the Persistent Variables plug-in:
It did not work. I get the following errors:
It did not work. I get the following errors:
Re: Dealing with State Information in EventGhost
Hi!! i've recently post in an other thread about it viewtopic.php?f=10&t=6257
It's a way to do it knowing very little codeing of python. Very little.
Bye!!
It's a way to do it knowing very little codeing of python. Very little.
Bye!!
Re: Dealing with State Information in EventGhost
Thanks for the reply Juanson. I am trying to stay away from writing to external text files. The dictionary contains a few hundred items. I need to access the items using the key very quickly. There is too much of lag in writing to and reading from a large text file. Furthermore, the values of keys can change, so updating the text file also slows down the process for me.juanson wrote:Hi!! i've recently post in an other thread about it viewtopic.php?f=10&t=6257
It's a way to do it knowing very little codeing of python. Very little.
Bye!!
Anyone else have any suggestions. My last resort is to use a database (MySQL). But I have a feeling that will also be a little slow.
Kalia
Re: Dealing with State Information in EventGhost
How else could it be done if you want a variable to be available between EG sessions? You would NOT need to write to the file every time your variable changed, but you would only need to read it when EG starts up.kalia wrote: I am trying to stay away from writing to external text files.
Or have I misunderstood your question, "I am trying to create a presistant dictionary in a script (not plugin)"? If the dictionary is static, not changing, then the solution is trivial. Put your dictionary definition using the action Python Command in your Autostart section. For example, "eg.globals.MyDictionary = {'a':1,'b':2,'c':3}" . eg.globals. variables are available inside EG python scripts. Edit: Never mind. I see that you said that the values change.
Edit: Fixed above to "NOT need"
Last edited by kkl on Sat Aug 23, 2014 1:48 pm, edited 1 time in total.
-
krambriw
- Plugin Developer
- Posts: 2570
- Joined: Sat Jun 30, 2007 2:51 pm
- Location: Stockholm, Sweden
- Contact:
Re: Dealing with State Information in EventGhost
I have sometimes used 'shelve' and 'pickle'. Those makes it a bit simpler to store to file system from python. Both are supported out of the box
import shelve
import pickle
import shelve
import pickle
My released plugins
https://drive.google.com/drive/folders/ ... y01eVBKeHM
https://drive.google.com/drive/folders/ ... y01eVBKeHM
Re: Dealing with State Information in EventGhost
Thanks for the suggestion krambriw. The 'shelve' modules looks promising. I will test it out when I have some time.krambriw wrote:I have sometimes used 'shelve' and 'pickle'. Those makes it a bit simpler to store to file system from python. Both are supported out of the box
import shelve
import pickle
Thanks,
Kalia