Page 1 of 1

Device "clouds" based on wunderground api

Posted: Wednesday 15 August 2018 13:18
by Lebo2d9
Hi,

I want to created a device that is based on the value weather
Below you can find the reponse of the api an d i want a device that is update with the weather value "geheel bewolkt"

Code: Select all

{
  "response": {
  "version":"0.1",
  "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
  "features": {
  "conditions": 1
  }
	}
  ,	"current_observation": {
		"image": {
		"url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
		"title":"Weather Underground",
		"link":"http://www.wunderground.com"
		},
		"display_location": {
		"full":"Weerde, Belgium",
		"city":"Weerde",
		"state":"VLG",
		"state_name":"Belgium",
		"country":"BX",
		"country_iso3166":"BE",
		"zip":"00000",
		"magic":"85",
		"wmo":"06448",
		"latitude":"50.970974",
		"longitude":"4.465515",
		"elevation":"9.1"
		},
		"observation_location": {
		"full":"Kleine Brogel, ",
		"city":"Kleine Brogel",
		"state":"",
		"country":"BE",
		"country_iso3166":"BE",
		"latitude":"50.97",
		"longitude":"4.47",
		"elevation":"26 ft"
		},
		"estimated": {
		},
		"station_id":"IZEMST12",
		"observation_time":"Last Updated on augustus 15, 1:14 PM CEST",
		"observation_time_rfc822":"Wed, 15 Aug 2018 13:14:18 +0200",
		"observation_epoch":"1534331658",
		"local_time_rfc822":"Wed, 15 Aug 2018 13:14:35 +0200",
		"local_epoch":"1534331675",
		"local_tz_short":"CEST",
		"local_tz_long":"Europe/Brussels",
		"local_tz_offset":"+0200",
		"weather":"Geheel bewolkt",
		"temperature_string":"68.4 F (20.2 C)",
		"temp_f":68.4,
		"temp_c":20.2,
		"relative_humidity":"74%",
		"wind_string":"Calm",
		"wind_dir":"WZW",
		"wind_degrees":244,
		"wind_mph":0,
		"wind_gust_mph":0,
		"wind_kph":0,
		"wind_gust_kph":0,
		"pressure_mb":"1020",
		"pressure_in":"30.12",
		"pressure_trend":"0",
		"dewpoint_string":"60 F (15 C)",
		"dewpoint_f":60,
		"dewpoint_c":15,
		"heat_index_string":"NA",
		"heat_index_f":"NA",
		"heat_index_c":"NA",
		"windchill_string":"NA",
		"windchill_f":"NA",
		"windchill_c":"NA",
		"feelslike_string":"68.4 F (20.2 C)",
		"feelslike_f":"68.4",
		"feelslike_c":"20.2",
		"visibility_mi":"6.2",
		"visibility_km":"10.0",
		"solarradiation":"247",
		"UV":"3.0","precip_1hr_string":"0.00 in ( 0 mm)",
		"precip_1hr_in":"0.00",
		"precip_1hr_metric":" 0",
		"precip_today_string":"0.00 in (0 mm)",
		"precip_today_in":"0.00",
		"precip_today_metric":"0",
		"icon":"cloudy",
		"icon_url":"http://icons.wxug.com/i/c/k/cloudy.gif",
		"forecast_url":"http://www.wunderground.com/global/stations/06448.html",
		"history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IZEMST12",
		"ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=50.970974,4.465515",
		"nowcast":""
	}
}

Can somenhelp with this?

Kind regards

Re: Device "clouds" based on wunderground api

Posted: Wednesday 15 August 2018 13:44
by waaren
Lebo2d9 wrote: Wednesday 15 August 2018 13:18 ...
I want to created a device that is based on the value weather
Can someone help with this?
...
What is the URL you use to get this ?
Do you want the string "geheel bewolkt" in a text device ?

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 18:01
by Lebo2d9
Hi Waaren,

The URL I use is http://api.wunderground.com/api/myapike ... MST12.json

and Yes i want the result of the weather string in a text device.

Kind regrds

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 18:28
by SweetPants
The Baro device already contains this information derived from the "icon"

"icon":"cloudy" -> "weather":"Geheel bewolkt"
"icon":"partlycloudy" -> "weather":"Partly Cloudy"

So this text device would be redundant

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 20:02
by Lebo2d9
This is the code I already have in dzVents

Code: Select all

return {
	active = true,

	on = {
		timer = {
			--'at 23:58'
			'every 5 minutes'
		}
	},
	execute = function(domoticz)
        local Date = domoticz.time.year..domoticz.time.month..domoticz.time.day

	    json = (loadfile "/home/pi/domoticz/scripts/lua/JSON.lua")() 
        local key = "code"
        local location = "pws:IZEMST12" --plaatsnaam of personal weather station invoeren
	    local file=assert(io.popen('curl http://api.wunderground.com/api/'..key..'/conditions/q/'..location..'.json')) 
	    local raw = file:read('*all')
	    file:close()
	    local deviceinfo = json:decode(raw)
        domoticz.log('raw:'..raw)
end
}
And this is the log i have

Code: Select all

2018-08-16 19:55:00.189 Status: dzVents: Info: ------ Start internal script: dzVentstestWU:, trigger: every 5 minutes
2018-08-16 19:55:00.662 Status: dzVents: Info: raw:
2018-08-16 19:55:00.662 {
2018-08-16 19:55:00.662 "response": {
2018-08-16 19:55:00.662 "version":"0.1",
2018-08-16 19:55:00.662 "termsofService":"http://www.wunderground.com/weather/api/d/terms.html",
2018-08-16 19:55:00.662 "features": {
2018-08-16 19:55:00.662 "conditions": 1
2018-08-16 19:55:00.662 }
2018-08-16 19:55:00.662 }
2018-08-16 19:55:00.662 ,	"current_observation": {
2018-08-16 19:55:00.662 "image": {
2018-08-16 19:55:00.662 "url":"http://icons.wxug.com/graphics/wu2/logo_130x80.png",
2018-08-16 19:55:00.662 "title":"Weather Underground",
2018-08-16 19:55:00.662 "link":"http://www.wunderground.com"
2018-08-16 19:55:00.662 },
2018-08-16 19:55:00.662 "display_location": {
2018-08-16 19:55:00.662 "full":"Weerde, Belgium",
2018-08-16 19:55:00.662 "city":"Weerde",
2018-08-16 19:55:00.662 "state":"VLG",
2018-08-16 19:55:00.662 "state_name":"Belgium",
2018-08-16 19:55:00.662 "country":"BX",
2018-08-16 19:55:00.662 "country_iso3166":"BE",
2018-08-16 19:55:00.662 "zip":"00000",
2018-08-16 19:55:00.662 "magic":"85",
2018-08-16 19:55:00.662 "wmo":"06448",
2018-08-16 19:55:00.662 "latitude":"50.970974",
2018-08-16 19:55:00.662 "longitude":"4.465515",
2018-08-16 19:55:00.662 "elevation":"9.1"
2018-08-16 19:55:00.662 },
2018-08-16 19:55:00.662 "observation_location": {
2018-08-16 19:55:00.662 "full":"Kleine Brogel, ",
2018-08-16 19:55:00.662 "city":"Kleine Brogel",
2018-08-16 19:55:00.662 "state":"",
2018-08-16 19:55:00.662 "country":"BE",
2018-08-16 19:55:00.662 "country_iso3166":"BE",
2018-08-16 19:55:00.662 "latitude":"50.97",
2018-08-16 19:55:00.662 "longitude":"4.47",
2018-08-16 19:55:00.662 "elevation":"26 ft"
2018-08-16 19:55:00.662 },
2018-08-16 19:55:00.662 "estimated": {
2018-08-16 19:55:00.662 },
2018-08-16 19:55:00.662 "station_id":"IZEMST12",
2018-08-16 19:55:00.662 "observation_time":"Last Updated on August 16, 7:54 PM CEST",
2018-08-16 19:55:00.662 "observation_time_rfc822":"Thu, 16 Aug 2018 19:54:57 +0200",
2018-08-16 19:55:00.662 "observation_epoch":"1534442097",
2018-08-16 19:55:00.662 "local_time_rfc822":"Thu, 16 Aug 2018 19:55:00 +0200",
2018-08-16 19:55:00.662 "local_epoch":"1534442100",
2018-08-16 19:55:00.662 "local_tz_short":"CEST",
2018-08-16 19:55:00.662 "local_tz_long":"Europe/Brussels",
2018-08-16 19:55:00.662 "local_tz_offset":"+0200",
2018-08-16 19:55:00.662 "weather":"Partly Cloudy",
2018-08-16 19:55:00.662 "temperature_string":"76.8 F (24.9 C)",
2018-08-16 19:55:00.662 "temp_f":76.8,
2018-08-16 19:55:00.662 "temp_c":24.9,
2018-08-16 19:55:00.662 "relative_humidity":"64%",
2018-08-16 19:55:00.662 "wind_string":"Calm",
2018-08-16 19:55:00.662 "wind_dir":"NNW",
2018-08-16 19:55:00.662 "wind_degrees":330,
2018-08-16 19:55:00.662 "wind_mph":0,
2018-08-16 19:55:00.662 "wind_gust_mph":0,
2018-08-16 19:55:00.662 "wind_kph":0,
2018-08-16 19:55:00.662 "wind_gust_kph":0,
2018-08-16 19:55:00.662 "pressure_mb":"1014",
2018-08-16 19:55:00.662 "pressure_in":"29.95",
2018-08-16 19:55:00.662 "pressure_trend":"0",
2018-08-16 19:55:00.662 "dewpoint_string":"64 F (18 C)",
2018-08-16 19:55:00.662 "dewpoint_f":64,
2018-08-16 19:55:00.662 "dewpoint_c":18,
2018-08-16 19:55:00.662 "heat_index_string":"NA",
2018-08-16 19:55:00.662 "heat_index_f":"NA",
2018-08-16 19:55:00.662 "heat_index_c":"NA",
2018-08-16 19:55:00.662 "windchill_string":"NA",
2018-08-16 19:55:00.662 "windchill_f":"NA",
2018-08-16 19:55:00.662 "windchill_c":"NA",
2018-08-16 19:55:00.662 "feelslike_string":"76.8 F (26 C)",
2018-08-16 19:55:00.662 "feelslike_f":"76.8",
2018-08-16 19:55:00.662 "feelslike_c":"26",
2018-08-16 19:55:00.662 "visibility_mi":"6.2",
2018-08-16 19:55:00.662 "visibility_km":"10.0",
2018-08-16 19:55:00.662 "solarradiation":"79",
2018-08-16 19:55:00.662 "UV":"1.0","precip_1hr_string":"0.00 in ( 0 mm)",
2018-08-16 19:55:00.662 "precip_1hr_in":"0.00",
2018-08-16 19:55:00.662 "precip_1hr_metric":" 0",
2018-08-16 19:55:00.662 "precip_today_string":"0.00 in (0 mm)",
2018-08-16 19:55:00.662 "precip_today_in":"0.00",
2018-08-16 19:55:00.662 "precip_today_metric":"0",
2018-08-16 19:55:00.662 "icon":"partlycloudy",
2018-08-16 19:55:00.662 "icon_url":"http://icons.wxug.com/i/c/k/partlycloudy.gif",
2018-08-16 19:55:00.662 "forecast_url":"http://www.wunderground.com/global/stations/06448.html",
2018-08-16 19:55:00.662 "history_url":"http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IZEMST12",
2018-08-16 19:55:00.662 "ob_url":"http://www.wunderground.com/cgi-bin/findweather/getForecast?query=50.970974,4.465515",
2018-08-16 19:55:00.662 "nowcast":""
2018-08-16 19:55:00.662 }
2018-08-16 19:55:00.662 }
2018-08-16 19:55:00.662
2018-08-16 19:55:00.662 Status: dzVents: Info: ------ Finished dzVentstestWU
Now i need only the code to filter the weather info out of the list

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 20:14
by SweetPants
Please read the Wiki https://www.domoticz.com/wiki/DzVents:_ ... _scripting, you have to convert the JSON string using fromJSON(json) to LUA table first to be able to read the individual elements of the JSON string

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 20:39
by waaren
Lebo2d9 wrote: Thursday 16 August 2018 20:02 This is the code I already have in dzVents


Now i need only the code to filter the weather info out of the list
The recent versions of dzVents are much more sophisticated to handle URL's and returns.
Maybe the script example below gets you going.

Code: Select all

-- getWeather.lua

return {
    on =        {     timer           =   { "every hour" },
                        httpResponses   =   {  "Wunderground_response" } },                         
              
    logging =   {       level   =   domoticz.LOG_DEBUG,                                   
                        marker  =   "getWeather" },                                           

    execute = function(dz, triggerItem)
    
        local function getWundergroundData()
            local url   = "http://api.wunderground.com/api/myapikey/conditions/q/pws:IZEMST12.json"
            dz.openURL({    url         = url,
                            method      = "GET",
                            callback    = "Wunderground_response"
                       })
        end
   
        local function handleResponse()
            local rt = triggerItem.json                        -- rt is just a reference to the data no actual copy is done
            if triggerItem.json ~= nil then
                dz.log(rt,dz.LOG_DEBUG)
                -- handle the response and fill your text device here 
            end
        end            
        
        if triggerItem.isHTTPResponse then
           if triggerItem.ok and triggerItem.isJSON then 
               handleResponse()
           else
               dz.log("Problem with response from wunderground",dz.LOG_DEBUG)  
           end
        else
            getWundergroundData()
        end 
    end
}

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 21:50
by Lebo2d9
Hi Waaren,

Thx for the code but now i get

Code: Select all

2018-08-16 21:48:01.401 Status: dzVents: Debug: getWeather: {["current_observation"]={["relative_humidity"]="72%", ["visibility_mi"]="6.2", ["temp_c"]=21, ["history_url"]="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IZEMST12", ["local_tz_short"]="CEST", ["precip_1hr_in"]="0.00", ["temperature_string"]="69.8 F (21.0 C)", ["dewpoint_string"]="60 F (16 C)", ["pressure_mb"]="1014", ["dewpoint_c"]=16, ["wind_kph"]=1.1, ["precip_1hr_string"]="0.00 in ( 0 mm)", ["wind_string"]="Calm", ["observation_time_rfc822"]="Thu, 16 Aug 2018 21:32:51 +0200", ["heat_index_string"]="NA", ["nowcast"]="", ["ob_url"]="http://www.wunderground.com/cgi-bin/findweather/getForecast?query=50.970974,4.465515", ["local_time_rfc822"]="Thu, 16 Aug 2018 21:33:00 +0200", ["precip_today_in"]="0.00", ["windchill_string"]="NA", ["windchill_f"]="NA", ["precip_today_string"]="0.00 in (0 mm)", ["image"]={["link"]="http://www.wunderground.com", ["url"]="http://icons.wxug.com/graphics/wu2/logo_130x80.png", ["title"]="Weather Underground"}, ["forecast_url"]="http://www.wunderground.com/global/stations/06448.html", ["icon_url"]="http://icons.wxug.com/i/c/k/nt_clear.gif", ["feelslike_string"]="69.8 F (21.0 C)", ["pressure_trend"]="0", ["icon"]="clear", ["precip_today_metric"]="0", ["wind_mph"]=0.67, ["dewpoint_f"]=60, ["precip_1hr_metric"]=" 0", ["weather"]="Clear", ["local_epoch"]="1534447980", ["UV"]="0.0", ["solarradiation"]="0", ["visibility_km"]="10.0", ["heat_index_c"]="NA", ["feelslike_c"]="21.0", ["estimated"]={}, ["wind_gust_mph"]="2.5", ["wind_dir"]="NNE", ["wind_degrees"]=14, ["windchill_c"]="NA", ["feelslike_f"]="69.8", ["heat_index_f"]="NA", ["observation_time"]="Last Updated on August 16, 9:32 PM CEST", ["local_tz_long"]="Europe/Brussels", ["station_id"]="IZEMST12", ["wind_gust_kph"]="4.0", ["pressure_in"]="29.95", ["observation_epoch"]="1534447971", ["observation_location"]={["country"]="BE", ["elevation"]="26 ft", ["city"]="Kleine Brogel", ["latitude"]="50.97", ["country_iso3166"]="BE", ["full"]="Kleine Brogel, ", ["state"]="", ["longitude"]="4.47"}, ["local_tz_offset"]="+0200", ["temp_f"]=69.8, ["display_location"]={["magic"]="85", ["city"]="Weerde", ["state_name"]="Belgium", ["state"]="VLG", ["longitude"]="4.465515", ["elevation"]="9.1", ["zip"]="00000", ["latitude"]="50.970974", ["country_iso3166"]="BE", ["wmo"]="06448", ["country"]="BX", ["full"]="Weerde, Belgium"}}, ["response"]={["version"]="0.1", ["termsofService"]="http://www.wunderground.com/weather/api/d/terms.html", ["features"]={["conditions"]=1}}}
2018-08-16 21:48:01.401 Status: dzVents: Info: getWeather: ------ Finished dzVentstestWU
My only problem is how do i get only the weather info

Re: Device "clouds" based on wunderground api

Posted: Thursday 16 August 2018 22:23
by waaren

Lebo2d9 wrote:Hi Waaren,

Thx for the code but now i get

Code: Select all

2018-08-16 21:48:01.401 Status: dzVents: Debug: getWeather: {["current_observation"]={["relative_humidity"]="72%", ["visibility_mi"]="6.2", ["temp_c"]=21, ["history_url"]="http://www.wunderground.com/weatherstation/WXDailyHistory.asp?ID=IZEMST12", ["local_tz_short"]="CEST", ["precip_1hr_in"]="0.00", ["temperature_string"]="69.8 F (21.0 C)", ["dewpoint_string"]="60 F (16 C)", ["pressure_mb"]="1014", ["dewpoint_c"]=16, ["wind_kph"]=1.1, ["precip_1hr_string"]="0.00 in ( 0 mm)", ["wind_string"]="Calm", ["observation_time_rfc822"]="Thu, 16 Aug 2018 21:32:51 +0200", ["heat_index_string"]="NA", ["nowcast"]="", ["ob_url"]="http://www.wunderground.com/cgi-bin/findweather/getForecast?query=50.970974,4.465515", ["local_time_rfc822"]="Thu, 16 Aug 2018 21:33:00 +0200", ["precip_today_in"]="0.00", ["windchill_string"]="NA", ["windchill_f"]="NA", ["precip_today_string"]="0.00 in (0 mm)", ["image"]={["link"]="http://www.wunderground.com", ["url"]="http://icons.wxug.com/graphics/wu2/logo_130x80.png", ["title"]="Weather Underground"}, ["forecast_url"]="http://www.wunderground.com/global/stations/06448.html", ["icon_url"]="http://icons.wxug.com/i/c/k/nt_clear.gif", ["feelslike_string"]="69.8 F (21.0 C)", ["pressure_trend"]="0", ["icon"]="clear", ["precip_today_metric"]="0", ["wind_mph"]=0.67, ["dewpoint_f"]=60, ["precip_1hr_metric"]=" 0", ["weather"]="Clear", ["local_epoch"]="1534447980", ["UV"]="0.0", ["solarradiation"]="0", ["visibility_km"]="10.0", ["heat_index_c"]="NA", ["feelslike_c"]="21.0", ["estimated"]={}, ["wind_gust_mph"]="2.5", ["wind_dir"]="NNE", ["wind_degrees"]=14, ["windchill_c"]="NA", ["feelslike_f"]="69.8", ["heat_index_f"]="NA", ["observation_time"]="Last Updated on August 16, 9:32 PM CEST", ["local_tz_long"]="Europe/Brussels", ["station_id"]="IZEMST12", ["wind_gust_kph"]="4.0", ["pressure_in"]="29.95", ["observation_epoch"]="1534447971", ["observation_location"]={["country"]="BE", ["elevation"]="26 ft", ["city"]="Kleine Brogel", ["latitude"]="50.97", ["country_iso3166"]="BE", ["full"]="Kleine Brogel, ", ["state"]="", ["longitude"]="4.47"}, ["local_tz_offset"]="+0200", ["temp_f"]=69.8, ["display_location"]={["magic"]="85", ["city"]="Weerde", ["state_name"]="Belgium", ["state"]="VLG", ["longitude"]="4.465515", ["elevation"]="9.1", ["zip"]="00000", ["latitude"]="50.970974", ["country_iso3166"]="BE", ["wmo"]="06448", ["country"]="BX", ["full"]="Weerde, Belgium"}}, ["response"]={["version"]="0.1", ["termsofService"]="http://www.wunderground.com/weather/api/d/terms.html", ["features"]={["conditions"]=1}}}
2018-08-16 21:48:01.401 Status: dzVents: Info: getWeather: ------ Finished dzVentstestWU
My only problem is how do i get only the weather info
What do you see if you change dz.log(rt,dz.LOG_DEBUG)
to
dz.log(rt.current_observation.weather,dz.LOG_DEBUG)

?

Verstuurd vanaf mijn ONEPLUS A3003 met Tapatalk


Re: Device "clouds" based on wunderground api

Posted: Friday 17 August 2018 11:59
by Lebo2d9
Hi waaren,

Thx for the last update

now i get what i want

Code: Select all

018-08-17 11:56:01.349 Status: dzVents: Info: Handling httpResponse-events for: "Wunderground_response
2018-08-17 11:56:01.349 Status: dzVents: Info: getWeather: ------ Start internal script: dzVentstestWU: HTTPResponse: "Wunderground_response"
2018-08-17 11:56:01.369 Status: dzVents: Debug: getWeather: Partly Cloudy
2018-08-17 11:56:01.369 Status: dzVents: Info: getWeather: ------ Finished dzVentstestWU

Re: Device "clouds" based on wunderground api

Posted: Monday 24 September 2018 16:30
by roseen
Note that the Weather Underground API will stop working 2018-12-31 as the service is being discontinued.

end-of-service-for-the-weather-underground-api:
https://apicommunity.wunderground.com/w ... ground-api

Re: Device "clouds" based on wunderground api

Posted: Monday 24 September 2018 18:26
by SweetPants
Not 100% true:

For developers who use WU API data for non-commercial purposes, you will have access to a new plan for a personal use, low call volume API. Stay tuned for more details as we build this out.

Let's wait what they come up with