HomeGenie Forum
General Category => Troubleshooting and Support => Topic started by: HGexperimenter on January 19, 2016, 02:02:26 AM
-
Is there an example using Program.Store / Get / List / Reset?
I want to be able to save some data and have it preserved in case of re-boot and an example using these functions would go a long way to helping understand how it is used.
Also with the Program Store List, is there an example to List all the Stored data (such as a wildcard List).
Thanks
Link to Helper: http://genielabs.github.io/HomeGenie/api/ape/a00014.html (http://genielabs.github.io/HomeGenie/api/ape/a00014.html)
Hi - Been a few days and a few have viewed this - any help would be great with an example of Program.Store() - thanks!
-
I assume that you would use it like a normal parameter.
Program.Store("test1").Value = 1;
Program.Store("test1").Remove;
I haven't tried it, so you'd have to test to verify syntax.
-
Thanks for the suggestion. That's what I thought...
It doesn't work:
Program.Store("test1").Value = 1;
Error: "The left-hand side of an assignment must be a variable, a property or an indexer"
I tried lots of variations - no luck.
-
Hi,
I tried something on an existing Sensor I had.. this seems to work
Program.Store("HomeAutomation.MyPVMonitor").Get("PVLoad").Value = "12";
var a = Program.Store("HomeAutomation.MyPVMonitor").Get("PVLoad").Value;
Program.Notify("test", a.ToString());
This at least displays the 12 :)
The sensor and parameter used are defined in another program (C#):
Startup Code:
Program.AddVirtualModule("HomeAutomation.MyPVMonitor", "1", "Sensor", "homegenie/generic/mypvmonitor");
Program Code
var myPVMonitor = Modules.InDomain("HomeAutomation.MyPVMonitor").WithAddress("1").Get();
var pvLoad = myPVMonitor.Parameter("MyPVMonitor.PVLoad");
I hope this helps you in the right direction ...
-
louis: Thank you! This works! (I see the "Get" is needed to create and save a store variable - would be nice to have a "Put"!)
It also only takes Strings (I think).
Here is a test program I created - it also lists the values in the particular Program Store and then resets it all at the end. I don't know if there is a way to get all the Program Store names though...
string storeName = "testStore"; // This is the name of a Program Store
// Test: Create a store and save a string value
Program.Store(storeName).Get("saveStore").Value = "1234.5";
var getIt = Program.Store(storeName).Get("saveStore").Value;
Program.Notify("Program Store", "GetIt: "+getIt.ToString());
Program.Store(storeName).Get("saveStore2").Value = "4567.8";
// Dump Program Store list
var list = Program.Store(storeName).List;
var count = list.Count;
Program.Notify("Program Store", "List size: "+count.ToString());
foreach (var storeItem in list) {
Program.Notify("Program Store", "Name:"+storeItem.Name.ToString()+" Value:"+storeItem.Value.ToString());
}
// Reset the store: removes all stored names and data
Program.Store(storeName).Reset();
Hope this helops others too :)
-
Addendum question: Where is the data stored?
I checked homegenie_stats.db - not there.
Some sort of C# list:
Trace to:
store.cs:
public TsList<ModuleParameter> Data;
and:
utility.cs
public class TsList<T> : System.Collections.Generic.List<T>
... but not sure if it is written to disk...
-
I'm not sure, but you might check modules.xml, this is where, I believe, parameter values are stored.
As it looks like the store is using some kind of parameter stuff ...
Good luck :)
Louis
-
Yes - gets saved there after some time.. Not right away. Might be a scheduled update of some sort.
-
I'd love to know when/how often that data gets stored, or if there is a way to trigger it. I have some thermostat scheduling stuff that needs to be stored in case of a power loss, and I can't seem to get the data store to be persistent. Anybody have any idea on how that works?