Bug - Smartthings SmartWeather Station

Hi,
There’s a bug in the SmartWeather Sation device handler:

The wrong estimated lux is returned, it works if the code is modified so the case statements don’t use arrays. See below…

Niall
Hub v2 / Firmware 000.024.00020

Current Code:
private estimateLux(obs, sunriseDate, sunsetDate) {
def lux = 0
if (obs.dayOrNight == ‘N’) {
lux = 10
}
else {
//day
switch(obs.iconCode) {
case ‘04’:
lux = 200
break
case [‘05’, ‘06’, ‘07’, ‘08’, ‘09’, ‘10’,
‘11’, ‘12’, ‘13’,‘14’, ‘15’,‘17’,‘18’,‘19’,‘20’,
‘21’,‘22’,‘23’,‘24’,‘25’,‘26’]:
lux = 1000
break
case [‘27’, ‘28’]:
lux = 2500
break
case [‘29’, ‘30’]:
lux = 7500
break
default:
//sunny, clear
lux = 10000
}

    //adjust for dusk/dawn
    def now = new Date().time
    def afterSunrise = now - sunriseDate.time
    def beforeSunset = sunsetDate.time - now
    def oneHour = 1000 * 60 * 60

    if(afterSunrise < oneHour) {
        //dawn
        lux = (long)(lux * (afterSunrise/oneHour))
    } else if (beforeSunset < oneHour) {
        //dusk
        lux = (long)(lux * (beforeSunset/oneHour))
    }
}
lux

}

Fixed Code
private estimateLux(obs, sunriseDate, sunsetDate) {
def lux = 0
if (obs.dayOrNight == ‘N’) {
lux = 10
}
else {
//day
switch(obs.iconCode) {
case ‘04’:
lux = 200
break
case ‘05’:
case ‘06’:
case ‘07’:
case ‘08’:
case ‘09’:
case ‘10’:
case ‘11’:
case ‘12’:
case ‘13’:
case ‘14’:
case ‘15’:
case ‘16’:
case ‘17’:
case ‘18’:
case ‘19’:
case ‘20’:
case ‘21’:
case ‘22’:
case ‘23’:
case ‘24’:
case ‘25’:
case ‘26’:
lux = 1000
break
case ‘27’:
case ‘28’:
lux = 2500
break
case ‘29’:
case ‘30’:
lux = 7500
break
default:
//sunny, clear
lux = 10000
}

    //adjust for dusk/dawn
    def now = new Date().time
    def afterSunrise = now - sunriseDate.time
    def beforeSunset = sunsetDate.time - now
    def oneHour = 1000 * 60 * 60

    if(afterSunrise < oneHour) {
        //dawn
        lux = (long)(lux * (afterSunrise/oneHour))
    } else if (beforeSunset < oneHour) {
        //dusk
        lux = (long)(lux * (beforeSunset/oneHour))
    }
}
return lux

}

1 Like

Your best bet would be to file an Issue or Pull request to the GitHub.

3 Likes

I’ve now filed an issue #4098

Thanks!

1 Like

A fix for this is being commited:

3 Likes

It’s been patched here:

This is regarding the Smartweather station tile. I have a PWS and have started using this because I am trying to get as much as possible into the new app while I migrate to a V3 hub. It looks like wind speed is not displayed though when I look at the log is is collecting the information. Also the illuminance is not displaying in the tile. I am using my PWS ID and not the zip code. Any ideas?

Let me know if this discussion should be moved to another string.

Thanks,

© 2019 SmartThings, Inc. All Rights Reserved. Terms of Use | Privacy Policy

SmartThings; SmartApps®; Physical Graph; Hello, Home; and Hello, Smart Home are all trademarks of the SmartThings, Inc.