Dynamic Icon change

8 years 6 months ago - 8 years 6 months ago #2339 by NightOne
Dynamic Icon change was created by NightOne
Hi all,

Just thought I would share something that is simple and works quit well.... I wrote an external program that gets the local weather from forecast.io and uploads all the data to EasyIOT server, I could probably do the whole thing in automation but I dont have the skill.
The summary of the weather comes back as clear text and reads something like "Drizzle", "Rain", "Cloudy" etc etc... so what I have done is create corrisponding icons in the custom folder that match the name of the summary, so i have a file called "Drizzle.png" etc etc....you will see why in a moment.

I created a small automation script that changes the setting of the icon when the summary changes.....so when it says Drizzle for example you get a nice little icon with a cloud and rain.

I hope someone finds this useful

Code Here:

public void Setup()
{

EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if (m.Domain == Domains.VIRTUAL && m.Address == "N2S0" && p.Property == "Sensor.AnalogValue"){

if (p.Value.Contains("%20"))
{
string n = p.Value.Replace("%20"," ");
ModuleHelper.SetProperty(Domains.VIRTUAL, "N2S0", "Sensor.AnalogValue", n);
EventHelper.SetEvent(Domains.VIRTUAL, "N2S0", "Sensor.AnalogValue");
}

ModuleHelper.SetProperty(Domains.VIRTUAL, "N2S0", "Settings.Icon", p.Value +".png");
EventHelper.SetEvent(Domains.VIRTUAL, "N2S0", "Settings.Icon");


}
return true;

});

}

public void Run()
{
}

Please Log in or Create an account to join the conversation.

8 years 6 months ago #2348 by EasyIoT
Replied by EasyIoT on topic Dynamic Icon change

NightOne wrote: Hi all,

Just thought I would share something that is simple and works quit well.... I wrote an external program that gets the local weather from forecast.io and uploads all the data to EasyIOT server, I could probably do the whole thing in automation but I dont have the skill.
The summary of the weather comes back as clear text and reads something like "Drizzle", "Rain", "Cloudy" etc etc... so what I have done is create corrisponding icons in the custom folder that match the name of the summary, so i have a file called "Drizzle.png" etc etc....you will see why in a moment.

I created a small automation script that changes the setting of the icon when the summary changes.....so when it says Drizzle for example you get a nice little icon with a cloud and rain.

I hope someone finds this useful

Code Here:

public void Setup()
{

EventHelper.ModuleChangedHandler((o, m, p) =>
{
Console.WriteLine(m.Address + " in program id "+ Program.ProgramId.ToString()+ " property "+ p.Property + " value " + p.Value);
if (m.Domain == Domains.VIRTUAL && m.Address == "N2S0" && p.Property == "Sensor.AnalogValue"){


ModuleHelper.SetProperty(Domains.VIRTUAL, "N2S0", "Settings.Icon", p.Value +".png");
EventHelper.SetEvent(Domains.VIRTUAL, "N2S0", "Settings.Icon");


}
return true;

});

}

public void Run()
{
}


Nice idea.

Please Log in or Create an account to join the conversation.

Time to create page: 0.233 seconds

Forum latest

  • No posts to display.