Here is something for you to get started with:
Big thanks to medyk8ns on the forum for enabling the newtonsoft json call.
Code starts here:
private System.Reflection.MethodInfo _deserializeObjectMethodInfo;
public System.Reflection.MethodInfo DeserializeObjectMethodInfo
{
get
{
if (_deserializeObjectMethodInfo == null)
{
var assembly = System.Reflection.Assembly.LoadFrom("Newtonsoft.Json.dll");
var jobjectType = assembly.GetType("Newtonsoft.Json.JsonConvert");
_deserializeObjectMethodInfo = jobjectType.GetMethods().SingleOrDefault(m => m.Name == "DeserializeObject" && !m.IsGenericMethod && m.ReturnType==typeof(object) && m.GetParameters().Count()==1);
//can also use Parse method from JObject
//var jobjectType = assembly.GetType("Newtonsoft.Json.Linq.JObject");
//_deserializeObjectMethodInfo= jobjectType.GetMethod("Parse");
}
return _deserializeObjectMethodInfo;
}
}
public void Run()
{
{
using (System.Net.WebClient webClient = new System.Net.WebClient())
{
System.Net.WebClient n = new System.Net.WebClient();
var json = n.DownloadString("
api.sunrise-sunset.org/json?lat=36.72016...tted=0&date=tomorrow
");
dynamic valueOriginal = DeserializeObjectMethodInfo.Invoke(this, new object[] { json });
DateTime SunRise = valueOriginal.results.sunrise;
DateTime SunSet = valueOriginal.results.sunset;
string valueRise = SunRise.ToString("HH:mm");
string valueSet = SunSet.ToString("HH:mm");
Console.WriteLine("Sunrise is at: " + valueRise);
Console.WriteLine("Sunset is at: " + valueSet);
ModuleHelper.SetProperty(Domains.VIRTUAL, "N20S0", "Time.Sunrise", valueRise );
ModuleHelper.SetProperty(Domains.VIRTUAL, "N20S0", "Time.Sunset", valueSet );
}
}
}
On the EasyIOT side I created a little workaround and used custom properties to create values in a virtual sensor.
So you create a new sensor mine was N20S0 so you will need to change the code to reflect yours. In config on the sensor you can click on the sensor and make it an analog output... then click the configure gear on the side and add two new paramiters name the paramiters Time.Sunrise and Time.sunset. This will fill in the sensor values for the code..
This is in the run section of the code so it will need a cron job to run...as the values only change once a day I would run it only once....time is up to you...