X10 Community Forum

📱🖥️PiX10Hub ( Always Evolving Open Source) => 💬General Discussion => 📝User created HG Scripts (programs/macros/widgets) => Topic started by: soxfan1966 on February 02, 2020, 09:23:46 AM

Title: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 02, 2020, 09:23:46 AM
I happened to noticed that the OpenWeatherMap widget was cutting off the sunset time when your preferences were to display the time in AM / PM as opposed to 24 hour.

While trying to fix that, I found that there is an OpenWeatehrMap value for Feels Like temp so I updated the program and widget to display those under the large temp display (current temp).

Looks like attached image - could use some help with the HTML formatting (was also thinking of displaying humidity with that).  Also would like to round the current temp so 33 would appear in place of 33.5.

I attached the updated program and widget (as txt files, will need to rename to Import) I have been working on too.  Any assistance would be appreciated.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 02, 2020, 09:42:24 AM
Nice to see others posting improvements to stock HG Programs. :)%
I never experienced the sunset/rise values getting chopped off but maybe I just don't watch those values
The Openweather Api also has a UV value which you may wish to add as well.
 #:)
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: petera on February 02, 2020, 09:49:52 AM
I happened to noticed that the OpenWeatherMap widget was cutting off the sunset time when your preferences were to display the time in AM / PM as opposed to 24 hour.

While trying to fix that, I found that there is an OpenWeatehrMap value for Feels Like temp so I updated the program and widget to display those under the large temp display (current temp).

Looks like attached image - could use some help with the HTML formatting (was also thinking of displaying humidity with that).  Also would like to round the current temp so 33 would appear in place of 33.5.

I attached the updated program and widget (as txt files, will need to rename to Import) I have been working on too.  Any assistance would be appreciated.

There's a number of experienced HTML coders over on the HomeGenie Club forum that I'm sure would be only to glad to help you with that. If you haven't joined up I recommend you do so.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 02, 2020, 10:03:01 AM
There actually is a thread on the Homegenie site for the Openweathermap modifications I started. Others have posted their samples to the thread as well.
https://homegenie.club/t/alternate-option-to-3-day-hi-low-weather-display/485
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 02, 2020, 11:50:22 AM
Also would like to round the current temp so 33 would appear in place of 33.5.

If you Google "C# math round" you'll get a number of examples. you may have to play to see which works best for you.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 02, 2020, 01:09:49 PM
I made a post over on the HomeGenie forum here:
https://homegenie.club/t/openweathermap-to-include-todays-high-temp-forecast-and-feels-like-temperature/586

But could not attach the program and widget as I got an error that new users can not upload attachments.  I was able to include the screen shot though.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 02, 2020, 01:15:52 PM
Most forums have a post limit that must be reached in order to post attachments this helps reduce spammers.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 02, 2020, 01:45:16 PM
Found the rounding, its actually quite simple.

temperature = Math.round(temperature, 2);

So do that for feels_like too and voila.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 02, 2020, 01:58:07 PM
The OpenWeatherMap API supplies a fair bit of info for users to play with. Nice to read you got the math.round to work the way you wished.
Usually you can find the code to do what you wish with Google it is just a mater of wording the search the right way. ;)
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 02, 2020, 02:03:35 PM
I also just noticed the wind speed and rain / precipitation is not converted to match the US measurements like temperature is (i.e. inches and not mm, mph and not kmh).

Not sure how to do that.   Lastly, the temp that displays in the dashboard (upper right corner) does not show the rounded temp.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 02, 2020, 02:13:59 PM
I also just noticed the wind speed and rain / precipitation is not converted to match the US measurements like temperature is (i.e. inches and not mm, mph and not kmh).

Not sure how to do that.   Lastly, the temp that displays in the dashboard (upper right corner) does not show the rounded temp.
Not sure where you did the math.round in widget or program code.
The Value in the top right of HG I believe is pulled from the program  as is the humidity.
I never played with the metric to imperial conversion in HG however did with other programs, a search in Google will yield some samples.
However I believe the API can send in metric or imperial so you may wish to look at what Gene was using for the calls.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 02, 2020, 02:26:17 PM
Was able to find a way to convert the windspeed and the rainmm to US.  Not sure if those are accurate or not, will need to check - but for display purposes it looks right.

Here is the updated screen shot and the program and widget attached.  All for now, time to go get ready to watch the Super Bowl (unfortunately the Patriots are not in it this year - which I assume most people are happy about at this stage - but should be a good game anyway).  If you are watching this year hope you enjoy it.

Thanks
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: petera on February 02, 2020, 05:32:30 PM
Jeez youíre flying through HG. Just waiting until your C#, Python and JavaScript skills are up to speed and you will become a net contributor to the HG project. Your quick learning skills will be greatly appreciated over at the HomeGenie Club forum. HG is an application you either take to quickly or struggle through painstakingly.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: petera on February 02, 2020, 06:08:12 PM
For anyone trying out @soxfan1966 modified weather utility ensure you export a copy of the originals before you import this modified version should you ever want to revert to the originals as it makes life a lot easier.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 03, 2020, 06:52:44 AM
Should also note that my programs include the Fahrenheit character fix.

Tried finding where the temperature in the top right corner comes from and rounding he weather.temp field in the OpenWeatherProgram but that did not seem to affect it.  It may be pulling in the value directly somewhere else that would need to be updated.

The attached image is what I am referring to (upper right corner on the Dashboard you have the Weather Widget displaying on.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 04, 2020, 01:03:52 PM
I think I found where this temperature display on the Dashboard header is getting its value from.

In the BaseFiles/Common/html/js/app/homegenie.webapp.utility.js file (which I found here: https://github.com/genielabs/HomeGenie/tree/master/BaseFiles/Common/html/js/app)

it builds a variable called temp based on the temperatureUnit field (C or F) and then uses this code:

displayvalue = (temp * 1).toFixed(1) + '°';

I did some searching and it looks like that .ToFixed(1) function is rounding the value to 1 digit after the decimal point.  If it were toFixed(0) it would round to zero decimal places.
Lines 261 and 265 if you are interested.

I tested this here:

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_tofixed

So I think that would fix it, problem is it looks like its a core HG file and not a widget or program, so it means editing the file on the pi itself to make that change and then re-starting the service so it takes affect.

I can give that a whirl when I have a chance and see what happens.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: bkenobi on February 04, 2020, 01:19:43 PM
Nice work.  Java script is interpretted code rather than compiled.  It is embedded in html and if you look at the path you found, the code should be something you can change on your RPi and test.  Yes, you should probably stop the service, make the change, and start HG again.  You should keep in mind that if Gene updates HG it is possible your update could be lost.  You could submit a change request in the Issues section if you think that might be a common request.  I personally don't think it's valuable having any decimal places for either the current or predicted temperatures.  The temperature where it is measured won't be the same 10' away or 10 seconds later (to that accuracy), so why include it.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 04, 2020, 02:32:20 PM
 #:) you just keep plugging away. I think we created a Eveready coding bunny  rofl
 >!
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 04, 2020, 04:33:35 PM
Well, that seemed like the likely place but there must be somewhere else its doing something similar.  I made the changes as I noted, stopped the service and then started it again but no luck.  Still displaying the temp with 1 decimal place in the Dashboard header.

I will try poking around some more, probably tomorrow.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: bkenobi on February 04, 2020, 05:19:03 PM
The temperature is most likely stored in a float and only changed to a 1-digit decimal when displayed.  I don't know if changing it to round down to 0-places will affect anything on the display side for the widget since the widget will presumably format the output as needed.  Seems like the widget is where you should be focusing on, but I haven't looked so I'm not sure.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 04, 2020, 05:27:19 PM
I believe the API supplies a 2 decimal value HG converts that to 1 decimal. If you play with the program side and chage the value to a value with no decimal that nuber gets displayed in the widget and the
HG header bar. So I suspect that is where you need to do your math.round. remember values will only change after a pull.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 05, 2020, 06:22:06 AM
I had found another field using the ToFixed(1) that I changed to ToFixed(0) under temperature just above the other 2 lines I had changed (which were in Format temperature).

Then I restarted the service again - but same results.

Oddly, this morning I pulled up the HomeGenie page (from a web browser, not the android app) and the temps displaying in the Dashboard header and drop down selection both showed the temperature with 0 decimal places.   I get to work and pull up the HomeGenie page from a web browser on my work pc and the temps show 1 decimal place.  Not sure why, will see if there is some other place where a different display is used for mobile vs desktop ?

Images attached - the rounded temp displays are from my phone whereas the ones with 1 decimal place are from my work pc.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 05, 2020, 09:01:03 AM
I was inspecting the HTML code that is running on my work pc (a nice feature in Chrome btw) and was able to find the field for the temperature that is being displayed with the decimals.  The field is called hg-indicator-temperature and it is the same field in both the Home menu selection (where you pick a dashboard) and in the upper right corner of the Dashboard.

Trying to look at where this field / value is coming from.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: bkenobi on February 05, 2020, 12:26:09 PM
Remember that HG sometimes requires clearing the cache to work when it breaks.  I wonder if your changes were being effective, but your browser wasn't pulling up the new code.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: petera on February 05, 2020, 12:53:51 PM

I generally find restarting the service after an edit and save helps too. The difference in how an element is displayed in different browsers has always been an issue in HG. Looking through previous code samples will show how these differences were catered for and hard coded into the relevant programs.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 05, 2020, 02:22:14 PM
Good call on the browser cache.  I cleared my cache (not history etc, just the cache - I use Chrome) and then loaded HG again.  It took a lot longer to load (which was expected) but the temperature on the Dashboard dropdown and the upper right corner of the Dashboard both are displaying with no decimal places.

If someone wants to verify the code fix for me, I could submit a pull request over on the HG site.  Haven't done one of those before so I would feel more fomfortable if someone had a chance to validate my findings if possible.

Thanks
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: petera on February 05, 2020, 02:57:23 PM
Good call on the browser cache.  I cleared my cache (not history etc, just the cache - I use Chrome) and then loaded HG again.  It took a lot longer to load (which was expected) but the temperature on the Dashboard dropdown and the upper right corner of the Dashboard both are displaying with no decimal places.

If someone wants to verify the code fix for me, I could submit a pull request over on the HG site.  Haven't done one of those before so I would feel more fomfortable if someone had a chance to validate my findings if possible.

Thanks

Submit the pull request anyway. The author will validate and approve it for inclusion it if he feels it will be of general use to others. Not all pull requests do get approved for obvious reasons and the author is not very active these days so donít expect immediate attention.

Many HG users have their own customised versions of HG running but donít see the need to submit these customisations.

Now that youíre well beyond the novice stage I suggest getting more active over on the HomeGenie Club forum where a number of new members have joined who are well versed in C# and Python as well as those who are already established where you can exchange ideas. Youíll see from the posts yourself.

Happy productivity to you and HG.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 06, 2020, 12:59:38 PM
I will post the pull request and also add some more info for my post on the Home Genie Club too (and take a look around there).

It happened to be snowing this morning (well, freezing rain but that gets reported as snow).  I noticed the Weather Widget only shows 0 in of rain.

So I played around with it some more and have a version 2.0 for my changes now (see image)

I will show Snow (the word, as there is no icon for the white snow like rain) with the rate if its > o otherwise the snow info should not appear.  I also noticed it can be snowing and raining in the reported info, so I will show both if that is true, and similar to what I did with the snow rate, if the rain rate is 0 I will not show it.  I also am reporting the rain and snow rates with 2 decimal places as we were getting less than an inch of each and it made sense to show a number and not just 0.

And then I played around with the formatting (i.e. moved the wind speed under the weather icon, indented things) so it hopefully looks nicer.  Updated program and widget also attached if you are interested.

Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: petera on February 06, 2020, 01:08:36 PM
If I get a chance Iíll give it a spin. Iíve locked down my HG installation for now and am back working with both Home Assistant and Vera.

I dispensed with the Raspberry Pi Zero W as its performance with HG is sluggish. Itís now running on a Raspberry Pi 3b+ and the difference is very noticeable.

A few more posts over on the HG forum and you will be able to post your OW code contributions so get posting.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 06, 2020, 01:23:25 PM
Pull request for the Temp to display with no decimal places in the Dashboard has been posted:
https://github.com/genielabs/HomeGenie/pull/398

Thanks
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: bkenobi on February 06, 2020, 10:32:28 PM
This is great! I am going to look more into open weather map now since weather underground changed. I'm still missing the precipitation totals which is really important to me.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: Tuicemen on February 07, 2020, 07:49:23 AM
Gene included much of the data available in the openweather api in this weather underground replacement, it just was never all added to the widget. Soxfan1966 and I began looking into the openweatherĺ api and possible pulls about a year ago. As I was working on the WeatherAlert program. We noticed the humidity pull was missing and added it to the three day forecast and allowed it to display in the header. Soxfan1966 has continued playing with the widget adding some of the info Gene never made use of and done a great job with.
This is a good example of how the end user can customize existing HGwidgets. It also shows HG has alot of hidden possibilities just waiting to be tapped into.
Title: Re: OpenWeatherMap to include Today's High Temp forecast and Feels Like Temp
Post by: soxfan1966 on February 07, 2020, 12:07:30 PM
Here is an updated version with a slight fix for the rain info - in the original one, the icon was still displaying even when the value was not. This fixes that