more G-Labs products

Author Topic: Weather-Widget - no API-Key needed  (Read 7864 times)

April 07, 2014, 01:14:59 AM
Read 7864 times

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
Hey Gene et all,

I had some more time to experiment this weekend and I found another web service from http://openweathermap.org/ that offers some more data than weatherunderground and requires no API key to work.

So I wrote another widget - this time in C# to get some better understanding for this language.

Also, I experimented with an approach to have a fully scalable design which is solely based on the font-size of the topmost element (the widget <a> in this case). Every element, text and even graphic scales relative to this and makes best use of the available space without loosing the layout when scaling up or down. I gonna experiment a bit more on this and once I?m happy with it, I will most likely adapt the SunCalc to this layout as well.

The second idea I wanted to try was to also use one color code as a base and have all shadings and images behave relative to this as well. So you can provide any hue-value you like and everything ?scales? in relation to this - color-wise.

This is also why, I?d like to have a popup to configure at least some settings directly on this page (I?m thinking of a color wheel as used for the z-wave lamps and setting the city name as for now). This is also where I have a problem and hope for some guidance from your side (see below).

Last not least: I added a manual refresh icon on the right panel side (analog to other modules).

Information provided by the widget is:
  • Country of City
  • Long/Lat (useful for SunCalc)
  • Description of current weather condition
  • Icon according to day/night and current weather situation
  • Temperature (incl. daily min/max)
  • Windspeed (incl. gust)
  • Wind direction
  • Pressure (incl. ground- and sea-level)
  • Humidity
  • Cloudiness
  • Rain/Snow within the last 1/3/24-hour or since midnight

What values are displayed specifically is up to the data provided by the local station within the selected city.

  • Again I implemented full localization with element tooltips (currently eng/ger).
  • Also you can choose between metric and imperial display.

Source and Screenshots are included below.



This leads me to the three problems I?m hoping to get some ideas from your side:

(1) When importing the script it will not start but display an error. Yet, when I open the source for editing and just hit ?update? it shows success and works fine. No idea what is causing this?

Code: [Select]
Errors:
1. Object reference not set to an instance of an object
2. at HomeGenie.Automation.ProgramEngine.EvaluateProgramCondition (System.Object evalArguments) [0x00000] in :0
Program disabled, fix errors first.

(2) When I try to call HG.WebApp.GroupModules.UpdateModule from ?onchange? of one form element within the preferences popup the settings won?t get saved. I see them as been updated in the widget Data, though. And also this exact code works from within the json. I saw from the fibaro example, I could implement and call a webservice, yet I?d like to try without since - judging by the functions available - it should be doable this way as well, right?

see line 82ff of openweathermap.json for details on this.

(3) Last thing: There seems to be a problem with the decoding of special characters within the json-feed (utf-8 in this case) of a webservice-call. You can see the ?? in the german screenshot. I tried to fix that within the C#-Part of my script, but this seems to be to late already. I left it uncommented in the source so maybe this helps at some other point of the source-code?

Code: [Select]
Program.Parameter("jkUtils.OpenWeatherMap.Weather.Description").Value = Regex.Replace(
data.weather[0].description,
@"\u(?<value>[0-9a-f]{4})",
match => {
string digits = match.Groups["value"].Value;
int number = int.Parse(digits, NumberStyles.HexNumber);
return char.ConvertFromUtf32(number);
})  ?? "";

 
« Last Edit: April 28, 2014, 12:54:25 AM by Jan »

April 07, 2014, 07:19:08 PM
Reply #1

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi Jan,

cool! I like this! =)

Quote
This leads me to the three problems I?m hoping to get some ideas from your side:

(1) When importing the script it will not start but display an error. Yet, when I open the source for editing and just hit ?update? it shows success and works fine. No idea what is causing this?

(2) When I try to call HG.WebApp.GroupModules.UpdateModule from ?onchange? of one form element within the preferences popup the settings won?t get saved. I see them as been updated in the widget Data, though. And also this exact code works from within the json. I saw from the fibaro example, I could implement and call a webservice, yet I?d like to try without since - judging by the functions available - it should be doable this way as well, right?

(3) Last thing: There seems to be a problem with the decoding of special characters within the json-feed (utf-8 in this case) of a webservice-call. You can see the ?? in the german screenshot. I tried to fix that within the C#-Part of my script, but this seems to be to late already. I left it uncommented in the source so maybe this helps at some other point of the source-code?

1) this is a known issue that happen when you import a program, it will be fixed soon
2) currently you can do:

Code: [Select]
HG.WebApp.GroupModules.ModulePropertyAdd(module, propertyName, propertyValue);
var prop = HG.WebApp.Utility.GetModulePropertyByName(module, propertyName);
prop.NeedsUpdate = 'true';
HG.WebApp.GroupModules.UpdateModule(module);

I know this is a bit weird, so I will make ModulePropertyAdd return the property or automatically set NeedsUpdate to true.

3) I'll check this out and let you know.

Some suggestion about the html layout.
Avoid using fixed with elements: a widget should fit on any device, so find a way of making elements wrap on smaller screens.
See attacched pics.

I am planning to add a program "Location Setting" that will store location data (city, lat, lon) so that other programs can use these settings instead of having on input fields.

I like the gfx on your widgets they're clean and well looking.

Thanks for sharing this =)
g.

April 07, 2014, 09:27:32 PM
Reply #2

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
Hey Gene,

Thanks for the help and the feedback!

Quote
Avoid using fixed with elements: a widget should fit on any device, so find a way of making elements wrap on smaller screens.
See attacched pics.

This time I directly saw what you mean and will look into that.  ;)

Quote
I am planning to add a program "Location Setting" that will store location data (city, lat, lon) so that other programs can use these settings instead of having on input fields.

That would be great. In my particular case, a user might still want to add some more description to the city name, e.g. New York US vs. New York UK. But none the less: A centrally stored city name (etc) could still work as a default value, so that the user would only need to provide a more specific value if the other wouldn't resolve to the expected data.

j.

April 28, 2014, 12:51:55 AM
Reply #3

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
Hey Gene,

I have been quite busy the last weeks. But finally I found some time to rework the script so that it now adapts to the screen size as you proposed. I also made some general improvements as well.

Take a look at it if you like...  :)

Best,
jan

April 28, 2014, 10:14:47 AM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
I can just say "Wow!" =)
This is gonna replace the WUnderground Widget in future releases.
I'll be working on automatic widget localization so I'll change just some line in your code and then make this widget the standard one for weather.
Thanks for this great app!

Cheers,
g.

April 28, 2014, 11:09:27 AM
Reply #5

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
Glad to hear that you like it!

For the localization:
Does this also mean, that there will be a chance to localize the text for the input fields, description, etc in the configuration section? This would be great, since then you could fully localize a widget.

I'm not fully through with the localization example to German for this widget. The popup texts are not yet localized. But I think, I'll hold on for now and wait for the new localization method first.

One more issue that's still present: the UTF encoded JSON gets special characters messed up (see attached image).

I also fixed a little bug in the display of detailed display of local pressures and attached the html file.

Best,
jan

May 05, 2014, 01:35:47 AM
Reply #6

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
I just updated to r371 and found that this widget was not yet included.  I was looking forward to playing with it.    ;D

May 06, 2014, 11:46:32 PM
Reply #7

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Next update will include this.
Unfortunately I can't make this widget the default weather widget right now because otherwise on a fresh install the android client won't show it correctly.
The aim would be to add Jens' weather widget to the android app as well.
Then it will replace the Weather Underground one.

Cheers,
g.

May 08, 2014, 11:49:47 PM
Reply #8

Jan

  • **
  • Information
  • Jr. Member
  • Posts: 34
Hi there,

I made some more improvements to the widget (tendency, source, improve reflow/resize) and cleaned some clutter.

All the aspects I originally planned to implement are now included.
Therefore I bumped the version number to 2.0 and consider it completed for now.

Have fun,
jan
« Last Edit: May 08, 2014, 11:59:13 PM by Jan »

May 09, 2014, 08:14:57 PM
Reply #9

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
Hi Jan,

your new widgets are both now included in r372.

See: http://www.homegenie.it/forum/index.php?topic=129.msg1063#msg1063

I've made some little modification to the code.

- removed localization instructions from the code of both widgets
- added some if to the Solar Altitude trigger code

Cheers,
g.

November 04, 2014, 05:11:51 PM
Reply #10

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
This may just be me, but I'm seeing errors in my mono log relating to this widget.  I just checked the widget itself and I'm seeing an error code in the editor.

Code: [Select]
Error
Line 0, Column 0 (Trigger Code):
     at System.Collections.Generic.List`1+Enumerator[HomeGenie.Data.ModuleParameter].MoveNext () [0x00000] in :0
     at HomeGenie.Automation.Scripting.ProgramHelper.Setup (System.Action functionBlock) [0x00000] in :0

I've seen a similar looking error for Gene's widget to turn lights on at 100%.  The mono version of that error is:
Code: [Select]
2014-11-03T18:26:01.4585020-08:00 HomeAutomation.HomeGenie.Automation 84 Automation Program Runtime.Error TC:   at System.Collections.Generic.List`1+Enumerator[HomeGenie.Data.ModuleParameter].MoveNext () [0x00000] in <filename unknown>:0    at HomeGenie.Automation.Scripting.ProgramHelper.Setup (System.Action functionBlock) [0x00000] in <filename unknown>:0

Any thoughts on this?  I could post more details if you have any suggestions.

August 18, 2015, 11:54:22 PM
Reply #11

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
There is a slight bug in the widget as far as units that are displayed when using British units.  Wind speed is provided from OpenWeather in mph according to the documentation but the widget reports kph.

If you are going to fix that anyway (a very small tweak), perhaps you could add an additional line to the unit conversion to change hPa to inHg (the standard measure of pressure for aviation in the US and what I'm most familiar with.  I applied the correction factor but the units displayed are incorrect.  In looking at the widget I can see the reason is that the units are hard coded rather than applied to a label.  Unfortunately, I do not know html nor JS to be able to correct the widget and submit an update.

Code: [Select]
          if (displayCelsius.ToLower() == "true") {
            Program.Parameter("jkUtils.OpenWeatherMap.Main.Pressure").Value = data.main.pressure ?? "";
             //optional values
             Program.Parameter("jkUtils.OpenWeatherMap.Main.PressureSea").Value = data.main.sea_level ?? "";
             Program.Parameter("jkUtils.OpenWeatherMap.Main.PressureGround").Value = data.main.grnd_level ?? "";
          } else {
            Program.Parameter("jkUtils.OpenWeatherMap.Main.Pressure").Value = data.main.pressure/33.864 ?? "";
             //optional values
             Program.Parameter("jkUtils.OpenWeatherMap.Main.PressureSea").Value = data.main.sea_level/33.864 ?? "";
             Program.Parameter("jkUtils.OpenWeatherMap.Main.PressureGround").Value = data.main.grnd_level/33.864 ?? "";
          }