OpenWeatherMap-Alerts-Weather-Driver

something seems off
the android app shows clear sky yet hubitat shows light rain at condition text
debugging and looking at json response it shows current condition clear sky and light rain for tomorrow forecast
it looks like the driver is pulling the wrong data for my city

the built-in hubitat driver seems to be showing the weather correctly but that's just too basic.

not my app or anything but a devout user of it - check your settings in both your hub long lat and the device itself - there is an 'override hub location' - mine is switched off - my hub long lat are doing the job. you may be getting a discrepancy there.

thanks but it doesn't do the trick, I tried with override and made sure my hub's coordinates are right and still showing light rain when is clear sky while the built-in driver for weather shows the weather correctly but is too basic for my needs...

What is the driver set for in this setting? I'm guessing you have it off and it is showing you the forecast, not the current condition.
image

2 Likes

oh, how on earth did I miss that, I was pretty sure the default condition text would have been current day.
That did the trick, thanks a lot

2 Likes

what is difference between Pop1 vs Pop2, trying to figure out which to use.

PoP1= percent of precipitation Tomorrow
PoP2=percent of precipitation day after tomorrow
percentPrecip= percent of precipitation today

1 Like

This is OWM's forecast so it is 'Probability of Precipitation' ... which is expressed as a percentage.

2 Likes

I have a bit unusual problem. I live so far north that right now we don´t have any sunrise or sunset and it is the same in winter (only then no sun).
So the driver runs into a problem when it should fetch the sunrise (and I assume sunset) at line 327.
Is there a fix for this?

Here is the location I use.

Never thought of that possibility. Can you try the code below and let me know if that resolves the error? I have no easy way to test it.

Replace lines 324 &325 with the code below:

    if(!todaysSunrise || todaysSunrise == null) {
        if(!todaysSunset || todaysSunset == null) {
            Date tsunrise= Date.clearTime()
        } else {
            Date tsunrise= todaysSunset
        }
    } else {
        Date tsunrise = todaysSunrise
    }
    if(!todaysSunset || todaysSunset == null) {
        Date tsunset= tsunrise
    } else {
        Date tsunset= todaysSunset
    }

Not many do think of Polar Night and Polar Day unless you live here :wink:

I assume it was the 2 marked lines you meant to replace (see photo), I also tried lines 324 and 325 without success.

The error I get in the logs are when I change 325 and 326 is:

I guess you could test it by overriding the location in the driver and put 70.6626, 23.6829 which is my position. But of course I will test any changes you suggest :slight_smile:

Try this

from the original code, change lines 325 & 326 and again for lines 1604 & 1605 (be careful as lines will change when you make the first change. The lines you are replacing are the same in both places. You will change this:

    Date tsunrise= todaysSunrise
    Date tsunset= todaysSunset

to this:

    Date tsunrise, tsunset
    tsunrise = (!todaysSunrise || todaysSunrise == null) ? Date.parse("yyyy-MM-dd hh:mm:ss", new Date().format('yyyy-MM-dd', TimeZone.getDefault()) + " 00:00:00") : todaysSunrisex ;log.debug "made it to line 329. tsunrise: " + tsunrise
    tsunset = ((!todaysSunset || todaysSunset == null) && (new Date() >= Date.parse("yyyy-MM-dd", new Date().format('yyyy', TimeZone.getDefault()) + '-03-21')) && (new Date() < Date.parse("yyyy-MM-dd", new Date().format('yyyy', TimeZone.getDefault()) + '-09-21'))) ? Date.parse("yyyy-MM-dd hh:mm:ss", new Date().format('yyyy-MM-dd', TimeZone.getDefault()) + " 23:59:59") : Date.parse("yyyy-MM-dd hh:mm:ss", new Date().format('yyyy-MM-dd', TimeZone.getDefault()) + " 00:00:01")
    if(!(!todaysSunset || todaysSunset == null)) {
        tsunset = todaysSunset
    } 

The intent here to use default values when sunrise or sunset = null. If that happens and it is between March 21 and September 21st then it will set Sunrise at 00:00:00 and Sunset at 23:59:59. If it is between September 21st and March 21st it will set Sunrise at 00:00:00 and Sunset at 00:00:01. I know that will give you one second of night that you don't have in the summer and one second of day that you don't have in winter ..... but that is the best I could think to do. It should eliminate the errors.

Please try the code and let me know if it works and you have no errors. If so, I'll push it into production. Thanks.

Made it to line 329 (tsunset = todaysSunset) before it stopped, see log:

Sorry about that. It didn't stop. That was just a debug log to help me figure out what was going on in the code, that I failed to remove. No error there.

Other than that log entry ... is everything else as you would expect? If it is I'll push that out to production.

(I did add one additional piece of code to accommodate the masses of people using this driver :smile: that have similar (but opposite) situation in the southern pole regions.)

I have been working on a HubiThings driver using the SmartThings API for its data set. After watching this thread, this was something that is working for Utqiagvik, AK with Weather Channel data. Just posting if it might help you (or if you see fault).

Boolean is_day = false
if(weatherMap?.sunriseTimeLocal && weatherMap?.sunsetTimeLocal) {        
    String timeZoneId = device.currentValue("timeZoneId").toString()
    BigDecimal latitude = device.currentValue("latitude").toBigDecimal()
    TimeZone tz = TimeZone.getTimeZone(timeZoneId) // figure out the local timezone of the Hub. Might be different than Hubitat hub.
    
    Date sunriseTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", weatherMap.sunriseTimeLocal.value, TimeZone.getTimeZone("UTC"))
    Date sunsetTime = Date.parse("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", weatherMap.sunsetTimeLocal.value, TimeZone.getTimeZone("UTC"))
    
    if(sunriseTime == sunsetTime) {            
        Date midnightSun = Date.parse("yyyy-MM-dd", (latitude>0 ? (new Date().format('yyyy', tz) + '-03-21') : (new Date().format('yyyy', tz) + '-09-21')), tz)
        Date polarNight  = Date.parse("yyyy-MM-dd", (latitude<0 ? (new Date().format('yyyy', tz) + '-03-21') : (new Date().format('yyyy', tz) + '-09-21')), tz)           
        is_day = ((new Date()).after(midnightSun) && (new Date()).before(polarNight))
        logDebug "midnightSun: $midnightSun, polarNight: $polarNight, is_day: $is_day"
    }
    else {
        is_day = ((new Date()).after(sunriseTime) && (new Date()).before(sunsetTime))
    }
    sendEvent(name: "localSunrise", value: sunriseTime.format('h:mm a', tz).toString())
    sendEvent(name: "localSunset", value: sunsetTime.format('h:mm a', tz).toString())               
}
4 Likes

Thanks! The code I have written (but not pushed to production, yet) does similar things. This driver uses the hub's reported sunrise and sunset time, which may be null in these instances (as opposed to "sunriseTime == sunsetTime"). The code I am proposing accommodates those null values.

2 Likes

[UPDATED V0.6.5 05/30/2023]

  • Changes to prevent errors and better reporting in situations where there is no sunrise or sunset.

If using HPM do an Update or a repair. Otherwise open the driver code and re-import the code. Thanks.

1 Like

Thank you Matthew, it works perfectly now!

2 Likes

[UPDATED V0.6.6 06/03/2023]

If using HPM do an Update or a Repair. Otherwise open the driver code and re-import the code. Thanks.

4 Likes