Apixu.com worldwide weather data with outside lux. No PWS or server setup

UPDATED 4.0: added WU mappings and some forecast data for next day.

UPDATED 3.5: added temperature, pressure and humidity capabilities.

UPDATED 3.0: updated with code contribution from @jebbett to use some cool weather icons.

UPDATED 2.5: added image icon directly for weather condition for use on dashboard.

UPDATED 2: more granular lux calculation based on time of day and weather condition code.

UPDATED: from weather underground to apixu weather aboveground.

here is the new weather driver for those of us without a pws but have use for weather data in one or more locations.

  1. you will need your own api key from apixu.com.
  2. apixu updates their data every hour ... at least that seems to be the case for the free version ... so the polling frequency is defaulted to 30 minutes in settings.
  3. since a key reason for doing this was supporting illuminance data for those of us with no external lux sensor the illuminance data is calculated and published every 5 minutes independent of the polling interval.
  4. the seconds indicator for the local_time attribute blinks at ~2 second interval. works well when using this to display time on the dashboard for non-local locations.
  5. there is an attribute called illuminated which is the illuminance value properly formatted for display on dashboard.

here is the clock seconds indicator blinking every ~2 seconds:

apixu-clock

here are the attributes that are published and usable on the dashboard:

if you need any of the apixu returned attributes thats not published today ... just ping me and i will update the driver.

here is a dashboard i use with some of the attributes:

and here is the code:

need a way to do notifications based on attributes from this driver? try WATO:

if you would like to donate to support this work ... donate here.

i use this driver with rooms manager and rooms occupancy to turn on and off lights etc when the outside lux is at a certain values. if you havent tried rooms manager do consider giving it a try. it will change how you automate your house. more details here:

11 Likes

@bangali Can i not use my pws station? as I cannot find my API key? need to proof read better. Sorry

i dont have access to a personal PWS station so not sure. sorry didnt get the second part.

Got it working pretty easily. Had to apply to get the WU api key but its free anyways.

When I get time I’ll have to look into the non working attributes. They are probably easy fixes if anything. Just parsing the api responses hopefully.

1 Like

looks good. is there a driver already available for weather underground data?

unfortunately the free api key does not return some of the data hence the non working attributes.

i was going to use get sunrise and sunset data from the hub but that api does not seem to work in drivers. so sunrise/sunset/illuminance and forecast is not available on this.

i have posted on the hubitat support forum to see if the sunrise/sunset api can work in drivers. if it does some of the missing attributes could be filed in that way.

thanks for the link. does the WU driver work standalone or does it need the app to work?

ok. would you please consider adding an attribute with City, State? that seems to be one thing i use thats missing. and solar radiation is that a good approximation for lux? at my location there is no value for solar radiation however the light is still fairly bright outside.

thanks.

here is the city and state as was defined in the other driver "${obs.display_location.city}, ${obs.display_location.state}"

maybe make this configurable so there is no confusion between solar radiation and illuminance.

no worries ... get some sleep. :slight_smile:

thanks. that works.

since solar radiation is not always reported and its not typically the same as illuminance ... you could add a setting to have the user confirm if they want the value of solar radiation from the weather station published as illuminance. if user sets that flag as true via settings then publish the solar radiation as illuminance otherwise publish solar radiation as solar radiation and dont publish as illuminance.

since the illuminance capability is supported in the device and not all weather stations support returning solar radiation having an option not to publish solar radiation as illumination will prevent false triggers.

i was going to use this in the driver i had posted. this returns local sunrise and sunset in ISO 8601 format if you want to calculate illuminance based on this, current time and condition.

// attribution: sunrise and sunset data and api courtesy https://sunrise-sunset.org/
private getSunriseAndSunset()	{
    def params = [
        uri: "https://api.sunrise-sunset.org/json?lat=${location.latitude}&lng=${location.longitude}&date=today&formatted=0"
    ]
    
    def sunRiseAndSet = [:]
    
    try {
        httpGet(params)		{ resp ->
            sunRiseAndSet = [sunrise: resp.data.results.sunrise, sunset: resp.data.results.sunset]
        }
    } catch (e) {
        log.error "http call failed for sunrise and sunset api: $e"
    }

    // returns map with sunrise and sunset in ISO8601 format example: [sunrise:2018-05-01T13:11:41+00:00, sunset:2018-05-02T02:58:41+00:00]
    return sunRiseAndSet
}

the site uses rate limiting so might be worth calling this only when the date changes to a new date.

Just as a heads up for anyone looking into this. currently (5/18/18) you can not get a free API key from WU any more. It looks like as long as you have a key you'll be ok for a while, but no new keys are being given out.

1 Like

fyi i am planning to switch this over to Weather API - OpenWeatherMap using the current weather API.
OR
Current Weather API - API Doc | Apixu.com
OR
Weather Unlocked API - Local Weather Pricing Plans

i was also thinking of trying noaa.gov but their weather api seems unreachable.

got to experiment a little with which one works best.

2 Likes

what endpoints are you trying for NOAA?

i had seen these last time looking for weather API back in 2017 ... the website seems unavailable now ... maybe someone at .gov doesnt like sharing weather data any more.

heres the archive link:

https://web.archive.org/web/20180125084701/www.ncdc.noaa.gov/cdo-web/webservices/v2#dataTypes

going to go with apixu. of the other 2 didnt like how they handle rate limiting on one and their limited international support on the other.

going to just push all of the attributes they support as is with the same name:

{
    "location": {
        "name": "Kolkata",
        "region": "West Bengal",
        "country": "India",
        "lat": 22.57,
        "lon": 88.37,
        "tz_id": "Asia/Kolkata",
        "localtime_epoch": 1526680245,
        "localtime": "2018-05-19 3:20"
    },
    "current": {
        "last_updated_epoch": 1526679924,
        "last_updated": "2018-05-19 03:15",
        "temp_c": 25.0,
        "temp_f": 77.0,
        "is_day": 0,
        "condition": {
            "text": "Mist",
            "icon": "//cdn.apixu.com/weather/64x64/night/143.png",
            "code": 1030
        },
        "wind_mph": 0.0,
        "wind_kph": 0.0,
        "wind_degree": 0,
        "wind_dir": "N",
        "pressure_mb": 1002.0,
        "pressure_in": 30.1,
        "precip_mm": 1.3,
        "precip_in": 0.05,
        "humidity": 83,
        "cloud": 75,
        "feelslike_c": 27.3,
        "feelslike_f": 81.1,
        "vis_km": 3.2,
        "vis_miles": 1.0
    }
}

will also:

  • change everything to valuetile since this is for hubitat only
  • add an attribute called location in city, state format
  • add a calculated attribute for illumination

havent checked. i am doing this for folks like me that dont own a pws.

Not that I can find

I think that an app can be written to cover both needs ... as long as the data end point is configurable / mappable

Those of us running our own PWS should be able to create a json file for consumption, based on a template, using the naming the driver expects.

The Driver then has a config option - JSON or
If JSON then input the URL for the file
pseudocode:

if selected.jsonfile then
GET json.url/file.json
else
Call API functions

Then the app/driver can support multiple options, even multiple APIs as long as the author wants to go through that nightmare of support churn :slight_smile:

did you just self nominate to write the app? :smile: