Parsing JSON data is very easy in HomeGenie, take a look at the Weather Underground or OpenWeatherData APPs.
Another simple example is my Youless Energy monitor APP.
Thank you for the answer!
I'm starting to create a new program starting from the OpenWeatherData as example. I've written the following hgx file. It will be imported correctly, but trying to check the values I should supply (input), the tab is empty.
I expect to be able to add these values after enabling the program: url, LeafNodeId01, LeafNodeId01Enabled, LeafNodeId02, LeafNodeId02Enabled...
But the "OPTIONS" tab is empty, seems broken, OPTIONS totally missing.
What's wrong?
The Widget (Program.AddControlWidget("xefil/xefilhomearduino/xefilhomearduino")
actually doesn't exist but should in any case show me the popup to enter the data, or not?
HEre my code:
<?xml version="1.0" encoding="utf-16"?>
<ProgramBlock xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ConditionType>OnTrue</ConditionType>
<Conditions />
<Commands />
<ScriptCondition>Program.Setup( () => {
// list the program as custom weather widget
Program.AddControlWidget("xefil/xefilhomearduino/xefilhomearduino");
// set input fields parameters
Program.AddInputField("URL", "http://192.168.1.1/test.xml", "Arduino 00 Leaf Station URL");
Program.AddInputField("LeafNodeId01", "0", "Arduino 1st Leaf");
Program.AddInputField("LeafNodeId01Enabled", "TRUE", "Arduino 1st Leaf Enabled? Set TRUE for YES, FALSE for NO");
Program.AddInputField("LeafNodeId02", "2", "Arduino 2nd Leaf");
Program.AddInputField("LeafNodeId02Enabled", "TRUE", "Arduino 2nd Leaf Enabled? Set TRUE for YES, FALSE for NO");
// setup program parameters
// Leaf 01
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Node").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Cmd").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasDHT11").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT11_H").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT11_T").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasRelay").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay01").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay02").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay03").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay04").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasDHT22").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT22_H").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT22_T").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasOneWire").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Dallas01").Value = "";
// Leaf 02
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Node").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Cmd").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasDHT11").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT11_H").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT11_T").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasRelay").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay01").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay02").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay03").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay04").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasDHT22").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT22_H").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT22_T").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasOneWire").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Dallas01").Value = "";
Program.Parameter("xefil.XefilHomeArduino.LastUpdated").Value = "";
});
return true;
</ScriptCondition>
<ScriptSource>
Func<bool> _checkWeather = new Func<bool>(()=>{
Program.RunAsyncTask(()=>
{
string webserviceurl = Program.InputField("URL").Value;
TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1));
int UTCTimeNow = (int)t.TotalSeconds;
string UCTTimeNowString = UTCTimeNow.ToString();
Program.Parameter("xefil.XefilHomeArduino.LastUpdated").Value = UCTTimeNowString; //last_updated;
try
{
// get data
var data = Net.WebService(webserviceurl).GetData();
//check for update in data
//if(data.dt.ToString() != Program.Parameter("jkUtils.OpenWeatherMap.Dt").Value ) {
if(0 != 1 ) {
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Node").Value = data.nodes.node ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Cmd").Value = data.nodes.cmd ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasDHT11").Value = data.nodes.has_dht11 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT11_H").Value = data.nodes.DHT11_H ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT11_T").Value = data.nodes.DHT11_T ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasRelay").Value = data.nodes.has_relay ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay01").Value = data.nodes.relay01 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay02").Value = data.nodes.relay02 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay03").Value = data.nodes.relay03 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Relay04").Value = data.nodes.relay04 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasDHT22").Value = data.nodes.has_dht22 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT22_H").Value = data.nodes.DHT22_H ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.DHT22_T").Value = data.nodes.DHT22_T ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.HasOneWire").Value = data.nodes.has_onewire ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId01.Dallas01").Value = data.nodes.dallas01 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Node").Value = data.nodes.node ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Cmd").Value = data.nodes.cmd ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasDHT11").Value = data.nodes.has_dht11 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT11_H").Value = data.nodes.DHT11_H ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT11_T").Value = data.nodes.DHT11_T ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasRelay").Value = data.nodes.has_relay ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay01").Value = data.nodes.relay01 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay02").Value = data.nodes.relay02 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay03").Value = data.nodes.relay03 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Relay04").Value = data.nodes.relay04 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasDHT22").Value = data.nodes.has_dht22 ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT22_H").Value = data.nodes.DHT22_H ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.DHT22_T").Value = data.nodes.DHT22_T ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.HasOneWire").Value = data.nodes.has_onewire ?? "";
Program.Parameter("xefil.XefilHomeArduino.LeafNodeId02.Dallas01").Value = data.nodes.dallas01 ?? "";
}
Program.Notify("xefil: XefilHomeArduino","Data has been updated.");
}
catch (Exception e)
{
Program.Notify("xefil: XefilHomeArduino", "Update of data failed.");
DEBUG: Program.Notify("XefilHomeArduino ERROR!", e.Message);
Console.WriteLine( e.Message );
//Pause(10);
}
});
return true;
});
//
// web service calls handling
//
When.WebServiceCallReceived("HomeAutomation.HomeGenie.Automation", (args) => //"HomeGenie.SecuritySystem", ( args ) =>
{
string[] reqs = ((string)args).Split('/');
var res = "";
try
{
string command = reqs[2];
string pid = reqs[1];
if (pid == Program.Module.Address)
{
switch(command)
{
case "Control.On":
break;
case "Control.Off":
break;
case "Control.Refresh":
//Program.Notify("jkutils: OpenWeatherMap","Update triggered.");
_checkWeather();
break;
}
}
}
catch (Exception ex)
{
res = "{ 'ResponseValue' : 'ERROR: " ex.Message " " ex.StackTrace "' }";
}
// unable to process request
return res;
});
while (Program.IsEnabled)
{
_checkWeather();
Pause(Program.InputField("UpdateInterval").DecimalValue * 60); // pause before next check
//Pause(10);
}
</ScriptSource>
<ScriptErrors />
<IsRunning>true</IsRunning>
<Features />
<LastConditionEvaluationResult>true</LastConditionEvaluationResult>
<Domain>HomeAutomation.HomeGenie.Automation</Domain>
<Address>1979</Address>
<Name>xefil - XefilHomeArduino</Name>
<Description>Gathers data from XefilHomeArduino</Description>
<Group>Contrib</Group>
<ActivationTime>2014-12-29T15:00:00.000000Z</ActivationTime>
<TriggerTime>2014-12-29T15:00:00.000000Z</TriggerTime>
<Type>CSharp</Type>
<IsEnabled>true</IsEnabled>
</ProgramBlock>
Thanks for the help!
Simon