X10 Community Forum

📱🖥️PiX10Hub => 💬General Discussion => 📝User created HG Scripts (programs/macros/widgets) => Topic started by: soxfan1966 on May 22, 2020, 07:00:14 AM

Title: Updated Weather Program and Widget
Post by: soxfan1966 on May 22, 2020, 07:00:14 AM
Good morning all,

I have been messing around with the standard Weather Widget and associated program for the last several weeks.  I had noticed an issue where the forecast for the left most column would be off later in the afternoon (it was advancing to the next day).  There is a post elsewhere that gets into some of the details, but I wanted to share what I have now with people in case they wanted to try this out and provide any feedback.

My updated version provides 3 separate forecasts for each day - morning, afternoon and evening.  This data still comes from OpenWeatherMap.  The standard widget uses the 12pm (noon) time to get the forecast data.  My version allows you to pick between 2 times for each of the daily forecasts:
morning = 6am or 9am
afternoon = noon or 3pm
evening = 6pm or 9pm

Note: The hourly data provided by OpenWeatherMap is every 3 hours, starting at midnight (so midnight, 3am, 6am, 9am, etc).

My version also starts with today, at least while the forecast data for today is still available whereas the standard widget starts with tomorrow, and once past noon it would advance to the following day (the Last Update date on the bottom of the widget would actually display tomorrow's date when this happens, even though its still today).

When the forecast data for today (morning or afternoon) is no longer available, that area in the widget will appear blank.  The attached image shows this for the morning forecast for today.  Once the evening forecast data is not available, then it is advanced to the following day (and the other 2 days also move forward 1 day).

Note: if you look at the code, there are a number of debugging widget DIVs and Program.Notify calls that I commented out but left in the code, if you uncomment those you can see the date/time each forecast for each day was last updated, as well as an option for Debugging mode which allows you to see what date/time for the forecast data is matched with the displayed day.  There are 9 days of data, 1-3 are the morning, 4-6 are the afternoon and 7-9 are evening.  Going to Configure / Widgets and pulling up the new Weather Widget (homegenie/generic/weather) and then click the hamburger icon next to the "bind to module" will allow you to see the Debug fields as long as the Debug option is enabled.

Other Changes:
1) I use the same humidity icon on the widget as HG does on the Dashboard, it looks like 2 raindrops.
2) I am displaying the feels like low forecast temp (there is a known issue with the OpenWeatherMaps data where the high and low temps are the same - no idea why, but there is no getting around it).  The icon for the forecast low is the down arrow followed by ~ to attempt to identify its an approximate low.
3) the current forecast string has been updated to displayed as mixed case as opposed to lower case:  So "Clear Sky" and not "clear sky", no particular reason other than it bugged me.
4) There is a new Widget option for "Fahrenheit Enable" - this will correctly (I believe) allow the display of C or F data and icons without the need to update the standard widget code (a reported bug).
5) There is a new Widget option for "Temperature Rounding Enable" - if set, it will round and truncate the temp values to whole numbers.
* the display of the temperature in the HG Dashboard while using the widget data is done in its own code, I attempted to correct the issue of rounding / truncating with this same change but not convinced it worked, there is a post on the HG board with info on how to make the change to the system programs to round that temp if needed.  Also, the conversion of the temp for F vs C is also in the HG programs, so I had to essentially leave the retrieval of the temperature field used by HG in place and use a new set of fields for the widget, where the widget specific ones are based on the imperial or metric based on the choice of the Fahrenheit enable whereas the HG used ones are always metric and then converted.
6) Precipitation Rate option was intended to allow for user choice if the precipitation info was based on the 1h or 3h values - unfortunately we have not had recent rain for me to verify this but it should work.
7) I mentioned the forecast time options above already (morning, afternoon and evening time choices)
8) The Precipitation Last 3 Days option currently does not do anything (I was / am working on a way to try and display the precipitation for the last 3 days, thought it would be useful this time of year as I need to monitor how I water my lawn).

I think that's it - the code for the program and the widget, while still mostly based on the original, has been cleaned up with my changes and I tried to comment where it made sense to help explain things.

Last note:  If you upload this new program it will be program number 1030 and I added "Soxfan1966 version" to the name.  Its possible for you to have both the standard and my version running (I still have the original version installed but not running).  If you chose to inactivate the standard one, and you use tuicemen's Weather Alerter program then you will need to update that so that it references the new version of the weather program.

I am also going to post this over on the Home Genie Club Forum.  Feedback and suggestions welcome.

Thanks :)

Once downloaded, rename the attached files as follows so you can import them into HG:
1) homegenie_weather_generic.txt to homegenie_weather_generic.zip
2) 1030-OpenWeatherMap_-_Soxfan1966_Version.txt to 1030-OpenWeatherMap_-_Soxfan1966_Version.hgx
Title: Re: Updated Weather Program and Widget
Post by: Tuicemen on May 22, 2020, 08:19:35 AM
Nice work! Thanks for sharing. #:)
Title: Re: Updated Weather Program and Widget
Post by: mike on December 16, 2020, 02:55:17 PM
Hi Soxfan,

I would like to try your program!  My std HG openweathermap program works so I have basic setup stuff right.

I imported your .hgx program and imported the .zip to widgets page and although I cannot see it in the list, it did allow your widget module to be added to one of my groups. 

I am not sure, but I think openweathermaps may need 'location' in addition to my API key?  I see you seem to program asking for location in the startup page of the program, but I cannot find anywhere to enter it?  So it is not working yet.

In addition, there seems to be some error message popping up in white box on left top of screen when I try to change settings, but I have not yet found a way to bring it on the creen - only a small portion of the box shows?

Hate to bother you with this but your changes look great and I want to add them if I can!

Thanks.
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 16, 2020, 04:04:31 PM
I may need to upload the most recent version of the program and widget but the both should show up in the lists if you added them.  Do you also have the jk utils solar utility program ?
Title: Re: Updated Weather Program and Widget
Post by: mike on December 16, 2020, 04:28:38 PM
I HAD jk utils on zero w HG system but recently updated to pi4 and I did not add it - I will!  tnx
Title: Re: Updated Weather Program and Widget
Post by: mike on December 17, 2020, 11:14:38 AM
I may need to upload the most recent version of the program and widget but the both should show up in the lists if you added them.  Do you also have the jk utils solar utility program ?

I installed prog34 openweathermap and that loaded jk utils.  It shows up in the widget list now;  it said it downloaded info correctly, and shows data when I added the widget to my group.

openweathermap still is working and downloading its weather information.

I cannot get your program to work yet...  a couple clues:

1) when I restart it from its settings page it pops up that white box, mostly offscreen, at top left telling what error but it is too far off screen to read anything other than "read 'property value of" and then a blue "20" on next line?

2) Looking at your widget in widget directory or in group, I see it is not changed to F, is is not rounded numbers as I set in settings, so it seems the program is not working correctly?

Would you mind sending your latest version?  Thank you very much!
Title: Re: Updated Weather Program and Widget
Post by: mike on December 18, 2020, 11:14:00 AM
Soxfan1966, Would you mind sending your latest version?  Thank you very much!
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 18, 2020, 11:45:00 AM
Mike,

I have attached my latest program and widget (note that the widget needs to point to my version of the weather program too).

NOTE: The homegenie_generic_weather.txt file needs to be renamed homegenie_generic_weather.zip, and the 1030-OpenWeatherMap_-_Soxfan1966_Version.txt file needs to be renamed 1030-OpenWeatherMap_-_Soxfan1966_Version.hgx before importing them into HomeGenie.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 12:33:47 PM
So I installed your latest from last post:  still same error I think.  This time I could find it:  clicking on the widget in the widget directory, I can see the whole error message:

TypeError:  Cannot read
'property VALUE' OF NULL:
lINE 7313, COLUMN 20

But your program only has 315 lines?

It shows the error is line 315...  I have never seen those [] brackets used before so I deleted it and its mate on line 1...  then line 3 showed error...  so I commented it out then line 5, then ditto and about every 3rd line showed error as I commented until I could not comment anymore as it got into real code...

Do you think this is something to do with pi4?

Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 12:36:28 PM
What are your settings for the program / widget as well asmthe jk.utils program ?
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 12:59:25 PM
Can't find where I entered the JKutil data but I will show its widget in next post.

Hmmm...   I just caught yours posting a message for 5 sec saying it is not configured?  Not sure where to config other than the wheel icon in the group - as I said before, it does not ask for location like JKutil and the orig weather one does...
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:00:47 PM
I think the jk.utils settings may be under the Maintenance settings - it's the lat and lon.
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:01:34 PM
You are missing the API key setting too
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:04:13 PM
guess I can try copying the 10 pages of settings that show 3 at a time like shown if that would help? (top 2 are from your program) last one is from JKutil (shows part of my API key)
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:05:15 PM
I think the jk.utils settings may be under the Maintenance settings - it's the lat and lon.

lat/long is set.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:06:44 PM
You are missing the API key setting too

that is set in JKutil and also the original openweathermap:  I never saw a place to enter it in your version - or the city unless I use the 3 bars on config-group page.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:09:09 PM
I will try putting the api key and city and c/F =1 answer into the 3bar parameter list on config group page (remember, changing c/f on actual group page shows 1 for F but still shows 0 on settings page.
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:10:12 PM
You need the API key in my weather program too
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:18:21 PM
You need the API key in my weather program too

Funny, now your program shows spot to enter API key!  See below!  It didnt have that a bit ago! 
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:20:25 PM
maybe I need to restart HG?  will try...  that did not help.

Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:21:06 PM
FYI - u probably don't want to show your API key, you should edit that post and xxxx it out.
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:22:04 PM
...  you can try restarting the widget and if that doesn't work then try restarting H.G.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:33:54 PM
restarting HG did not change it.

You can see orig openweather works and so does JKutil...  no matter what I do your widget seems broken on my pi4 with that dang error on a line that does not exist.
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:40:47 PM
I'm not sure what the problem is.  What version of raspian are you running?  What version of HomeGenie?
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 01:53:42 PM
latest HG (1.3 stable 19).  running 8/20/2020 latest Buster.  Pi4 w/2GBram.
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:55:17 PM
Try stopping the default weather program amd removing the dedst weather widget and see what happens
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 01:57:28 PM
Here is what my weather widget looks like.  I haven't changed the code for this since spring or early summer.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 02:17:09 PM
Nice.   We think alike:  I just deleted the orig openweather prog and widget, as well as yours, just leaving JKutil.  imported your prog and widget again.  set api key & Farenheit=1 and location use long/lat=1

JKutil continues to show Dayton ok.

Your still crashes on line 7313 that does not exist!

DANG!
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 02:19:53 PM
on restarts of your version I also get this error popup if it is a clue?
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 19, 2020, 02:22:44 PM
It's not building a valid API call.   I will have to take a look so e more, but I'm not in front of of computer so it probably won't be until Monday
Title: Re: Updated Weather Program and Widget
Post by: mike on December 19, 2020, 03:42:12 PM
Thanks!   Sorry.  I tried all 3 of my valid API keys, no difference.  I'd help diagnose if I could!  I compared the Javascript code to the original and see where you added stuff.  Original works (same API key).  I deleted all your javascript and replaced it with the original.  No more error showed but still did not work.  I am not sure what the HTML code does?  Does that build the widget and the javascript is the code to fill it in maybe?

Thanks for helping!  Your version is so much better!
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 21, 2020, 11:16:29 AM
OK, I looked into this a bit this morning.  I do not see anything wrong with the code on my eld, and the program (my version) has been working with no issues for awhile.

Here are my current settings, maybe there is one that is different than what you have and it is causing the problem.

In HomeGenie Maintenance page, under System Options I have the Longitude and Latitude defined for my area, and under the User Interface I have Fahrenheit and Month/Day/Year 12hr am/pm as my settings.

In the jkUtils - Solar Altitude Program I have the Latitude and Longitude settings defined (same as what I have on the Maintenace page, but both are defined).

I have the standard OpenWeatherMap program Disabled (the button for it is gray).

The Soxfan1966 version of the OpenWeatherMap program is active (the button is green) .
Here are my settings for my program:
Debug Mode = 0 (disabled)
Fahrenheit Enable = 1
Forecast time - Afternoon = 12
Forecast time - Evening = 21
Forecast time - morning = 6
Language = EN
Location - Use Lat & Lon for data = 1
OpenWeatherMap API Key = defined (use your own key here)
Precipitation Last 3 Days = 0 (I used this is the summer to track rainfall for watering my lawn, so it was working when this was 1 too)
Precipitation Last 3 Days - Target = 0.65
Precipitation Rate = 1
Temperature Rounding Enable = 1
Update Interval = 30

Under Widgets there are 2 entries - one for the standard and one for mine.
1) homegenie/environment/weather = this is the standard widget and uses the standard program (the bind to module is OpenWeatherMap).  I do not have this on my HomeGenie Dashboard(s).

2) homegenie/generic/weather = this is my version of the widget and uses my version of the program (the bind to module is OpenWeatherMap - Soxfan1966 Version).

Can you check all of those settings on your end and update as needed and let me know the results.  Thanks





Title: Re: Updated Weather Program and Widget
Post by: mike on December 26, 2020, 12:33:16 PM
I am feeling the issue may be the widget code instead of the program code?  Not sure what that splice error is...

So summary is all settings pretty much identical to yours.  Trying to point jkUtils to different program didn't work so left it pointing at jkUtil program.

Your program just insists on not getting data;  not sure where it is waiting on data from.  Screen shot attached...  Problem is "Unable to get data from service.  Object reference not set to an instance of an object." 

SOUNDS LIKE YOUR PROGRAM CANNOT FIND THE IP ADDRESS OR DOMAIN OF OPENWEATHERMAP.ORG...   

I have 3 API keys I made years ago;  jkUtils uses any and gets the info, but maybe I need a newer one for your call?  I will make a new API key and try that...

If I knew which line of code the above error referred to...

Can you check all of those settings on your end and update as needed and let me know the results.  Thanks

BIG THANK YOU FOR THIS INFO!    I will go down your list one by one and check them off!

In HomeGenie Maintenance page, under System Options I have the Longitude and Latitude defined for my area
- MINE IS ALSO SET


under the User Interface I have Fahrenheit and Month/Day/Year 12hr am/pm as my settings.
- BOTH MINE OPPOSITE - i CHANGED

In the jkUtils - Solar Altitude Program I have the Latitude and Longitude settings defined (same as what I have on the Maintenace page, but both are defined).
- I RECALL ONCE THERE MAYBE DIFFERENT VERSIONS OF jkUtils?  Mine does not ask for long/latitude - but it shows it on the widget!  It picked up the close by city rather than MY entered values - which is fine, close enough...

I have the standard OpenWeatherMap program Disabled (the button for it is gray).
- I TRIED BOTH WAYS;  LATEST NOW I HAVE IT DELETED.

The Soxfan1966 version of the OpenWeatherMap program is active (the button is green) .
- YES, BOTH jkUtils & YOUR PROGRAM ARE GREEN.

Here are my settings for my program:
Debug Mode = 0 (disabled)
Fahrenheit Enable = 1
Forecast time - Afternoon = 12
Forecast time - Evening = 21
Forecast time - morning = 6
Language = EN
Location - Use Lat & Lon for data = 1
OpenWeatherMap API Key = defined (use your own key here)
Precipitation Last 3 Days = 0 (I used this is the summer to track rainfall for watering my lawn, so it was working when this was 1 too)
Precipitation Last 3 Days - Target = 0.65
Precipitation Rate = 1
Temperature Rounding Enable = 1
Update Interval = 30
- ALL SET SAME HERE

Under Widgets there are 2 entries - one for the standard and one for mine.
1) homegenie/environment/weather = this is the standard widget and uses the standard program (the bind to module is OpenWeatherMap).  I do not have this on my HomeGenie Dashboard(s).
- I BELIEVE I USED TO HAVE THIS ONE BEFORE i DELETED THE STANDARD PROGRAM.  NOT THERE NOW.

2) homegenie/generic/weather = this is my version of the widget and uses my version of the program (the bind to module is OpenWeatherMap - Soxfan1966 Version).
- YEP, GOT IT, AS WELL AS A "jkUtils/OpenWeatherMap/OpenWeatherMap"
- I WONDER IF I SHOULD MAYBE try to point the jkUtils widget to your program instead?  not possible.

Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 27, 2020, 09:22:48 AM
The issue is that the call to the API is not getting all of the fields / info it needs to make a valid call and therefore there is no data being returned to parse.

I don't think the issue is in the code (widget or program) unless it's related to one of the settings - which you said all match mine

In one of your earlier screen shots of the settings/parameters you did not have the long/lat settings defined in my widget and your API key was missing.  Can you check those again?

You may also want to try deleting the program and widget and then import them again to make sure nothing got messed up when you were tinkering.

From there, if you can screen shot your params/settings again I can try setting things on my end to match yours and possibly track down what the issue is.  Not sure what else you can try at this point, sorry.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 27, 2020, 09:45:32 AM
any clue in farenheight not changing? 
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 27, 2020, 09:48:57 AM
You need the HG system setting (preference) to be Fahrenheit too I believe.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 27, 2020, 09:50:34 AM
got both set to F   (:
Title: Re: Updated Weather Program and Widget
Post by: soxfan1966 on December 27, 2020, 09:52:31 AM
If the program is not getting data from the API call it defaults to hardcoded data in the display.  It may be that.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 27, 2020, 01:01:37 PM
Thank you for trying to help me get it running.  Time to throw in the towel here.  Deleted yours, original (#34), & jkUtils, reinstalled all 3 again, put in API keys, city.  Same as before. Just not meant to be!

TypeError: Cannot read property 'Value' of null
Line 7313, Column 20

Title: Re: Updated Weather Program and Widget
Post by: petera on December 27, 2020, 06:29:07 PM
Thank you for trying to help me get it running.  Time to throw in the towel here.  Deleted yours, original (#34), & jkUtils, reinstalled all 3 again, put in API keys, city.  Same as before. Just not meant to be!

TypeError: Cannot read property 'Value' of null
Line 7313, Column 20

Have you tried restoring your SD card to a last know working version. From reading your endeavours here it sounded like you were giving it a good hammering taking chunks of code out to make it work. Maybe following soxfan instructions with a last known stable setup you may have success. If itís worked on one setup thereís no reason why it canít work on yours.
Title: Re: Updated Weather Program and Widget
Post by: bkenobi on December 27, 2020, 06:58:46 PM
Just a thought, but when you get to a point where things are working ok, you could use rpi-clone to create a backup card that you can step back to if you break things.  I personally opt for both a backup sd and writing down every command that I've decided is correct into a script of sorts.  When you get to a point where it's too broken, you then have 2 options to get back up and running.  If you are just flailing by throwing commands against the wall without writing down what you've done, you'll never get what you want because even if you succeed this time, the next thing you touch will break your card.
Title: Re: Updated Weather Program and Widget
Post by: petera on December 27, 2020, 08:31:17 PM
When you randomly use the sudo command it has consequences if you're not sure what you're doing. There's a lot of so called solutions to problems on the web and many of them are either ill conceived, out of date or just damn lazy hacks to get things working.

Try avoid going for the first solution. Read a number of solutions carefully and weigh up what best fits your problem. There's nothing worse than poorly documented code hacks. They provide little logic and when challenged the authors stock answer is, ah they just worked.

As I mentioned above and have mentioned many times go back to the point where your system was stable and follow the instructions as given. Clearly you need to delete what you had originally in place and replace it with soxfan solution. He did all the hard work so your don't have to. The only difference in his setup and yours is possibly a location and an Api key.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 29, 2020, 02:53:17 PM
Thank you for trying to help me get it running.  Time to throw in the towel here.  Deleted yours, original (#34), & jkUtils, reinstalled all 3 again, put in API keys, city.  Same as before. Just not meant to be!

TypeError: Cannot read property 'Value' of null
Line 7313, Column 20

Thanks for ideas Petera, but I have never had a working version of this so no restore will help.

Have you tried restoring your SD card to a last know working version. From reading your endeavours here it sounded like you were giving it a good hammering taking chunks of code out to make it work. Maybe following soxfan instructions with a last known stable setup you may have success. If itís worked on one setup thereís no reason why it canít work on yours.
Title: Re: Updated Weather Program and Widget
Post by: mike on December 29, 2020, 03:03:50 PM
Just a thought, but when you get to a point where things are working ok, you could use rpi-clone to create a backup card that you can step back to if you break things.  I personally opt for both a backup sd and writing down every command that I've decided is correct into a script of sorts.  When you get to a point where it's too broken, you then have 2 options to get back up and running.  If you are just flailing by throwing commands against the wall without writing down what you've done, you'll never get what you want because even if you succeed this time, the next thing you touch will break your card.

I do keep a good working SD card image backup, so no issue there.

You have a great scheme by writing down each change as you go!  I do the same.  I have bookshelves full of my notebooks with detail by detail notes going back to 1975 of every business phone call, every customer visit to solve tech problems, complete as you say, down to the minute, of exactly every line of code I changed as I went along.  I can unroll every change I made with a customer on site for 45 years, line by line.  It has served me well.  I have been called in many times to solve 'unsolvable' problems others tried to fix for weeks and months and solved every one of them - with this method.

This method, added to my other 2 beliefs (1) "I am from MO. - SHOW ME" - If I did not witness it myself I do not take my customer's word of what is going on, and 2) I am a great believer in what you did last broke it;  so I tend to go overboard asking my customer whom I am trying to help solve a difficult technical issue, when did it last WORK?  Tell me what you did between then and NOW.