Here is the script I am using to pull data from the new WU API. This only works if you are also sending WU data and they have given you a new key for the new API.
I don't expect that this will work exactly as is for anyone else, but it does give you a starting place. Sorry that it is not commented better.
You will have to create the devices that the script expects.
Here's one example. (Only the first few icons shown)
I don't expect that this will work exactly as is for anyone else, but it does give you a starting place. Sorry that it is not commented better.
Code:
Imports System.Web.Script.Serialization Const Fname As String = "WeatherForecast.vb" ' this file name Const Lcolor As String = "#ffaa56" ' log color for normal Dim json As New JavaScriptSerializer Sub Main(ByVal Parms As Object) Try Dim DataRaw As String = hs.geturl ("https://api.weather.com","/v3/wx/forecast/daily/5day?geocode=your_latitude,your_longitude&units=e&language=en-US&format=json&apiKey=your_key",FALSE ,"80") if left(DataRaw,5) = "ERROR" then hs.WriteLogDetail(Fname,DataRaw, "#FF0000", 2,Fname & ":Main",1) else Dim jData As WU = json.Deserialize(Of WU)(DataRaw) UpdateNlog("w100",0,jData.dayOfWeek(0),0) UpdateNlog("w110",jData.temperatureMin(0),"",0) UpdateNlog("w140",jData.daypart(0).iconCode(1),jData.daypart(0).narrative(1),0) if IsNothing(jData.temperatureMax(0)) then ' WU sends null when the day forcast has already passed 'UpdateNlog("w120",-99,"",1) else UpdateNlog("w120",jData.temperatureMax(0),"",0) end if if IsNothing(jData.daypart(0).iconCode(0)) then ' Use the night icon if the day one is no longer being sent UpdateNlog("w130",jData.daypart(0).iconCode(1),jData.daypart(0).narrative(1),0) UpdateNlog("w105",2,"",0) ' night forecast else UpdateNlog("w130",jData.daypart(0).iconCode(0),jData.daypart(0).narrative(0),0) UpdateNlog("w105",1,"",0) ' day forecast end if UpdateNlog("w101",0,jData.dayOfWeek(1),0) UpdateNlog("w111",jData.temperatureMin(1),"",0) UpdateNlog("w121",jData.temperatureMax(1),"",0) UpdateNlog("w131",jData.daypart(0).iconCode(2),jData.daypart(0).narrative(2),0) UpdateNlog("w141",jData.daypart(0).iconCode(3),jData.daypart(0).narrative(3),0) UpdateNlog("w102",0,jData.dayOfWeek(2),0) UpdateNlog("w112",jData.temperatureMin(2),"",0) UpdateNlog("w122",jData.temperatureMax(2),"",0) UpdateNlog("w132",jData.daypart(0).iconCode(4),jData.daypart(0).narrative(4),0) UpdateNlog("w142",jData.daypart(0).iconCode(5),jData.daypart(0).narrative(5),0) UpdateNlog("w103",0,jData.dayOfWeek(3),0) UpdateNlog("w113",jData.temperatureMin(3),"",0) UpdateNlog("w123",jData.temperatureMax(3),"",0) UpdateNlog("w133",jData.daypart(0).iconCode(6),jData.daypart(0).narrative(6),0) UpdateNlog("w143",jData.daypart(0).iconCode(7),jData.daypart(0).narrative(7),0) UpdateNlog("w104",0,jData.dayOfWeek(4),0) UpdateNlog("w114",jData.temperatureMin(4),"",0) UpdateNlog("w124",jData.temperatureMax(4),"",0) UpdateNlog("w134",jData.daypart(0).iconCode(8),jData.daypart(0).narrative(8),0) UpdateNlog("w144",jData.daypart(0).iconCode(9),jData.daypart(0).narrative(9),0) end if Catch Ex As Exception hs.WriteLogDetail(Fname,Ex.Message, "#FF0000", 2,Fname & ":Main",1) End Try End Sub Public Class Daypart Public Property cloudCover As Integer?() Public Property dayOrNight As String() Public Property daypartName As String() Public Property iconCode As Integer?() Public Property iconCodeExtend As Integer?() Public Property narrative As String() Public Property precipChance As Integer?() Public Property precipType As String() Public Property qpf As Double?() Public Property qpfSnow As Double?() Public Property qualifierCode As Object() Public Property qualifierPhrase As Object() Public Property relativeHumidity As Integer?() Public Property snowRange As String() Public Property temperature As Integer?() Public Property temperatureHeatIndex As Integer?() Public Property temperatureWindChill As Integer?() Public Property thunderCategory As String() Public Property thunderIndex As Integer?() Public Property uvDescription As String() Public Property uvIndex As Integer?() Public Property windDirection As Integer?() Public Property windDirectionCardinal As String() Public Property windPhrase As String() Public Property windSpeed As Integer?() Public Property wxPhraseLong As String() Public Property wxPhraseShort As String() End Class Public Class WU Public Property dayOfWeek As String() Public Property expirationTimeUtc As Integer() Public Property moonPhase As String() Public Property moonPhaseCode As String() Public Property moonPhaseDay As Integer?() Public Property moonriseTimeLocal As Object() Public Property moonriseTimeUtc As Integer?() Public Property moonsetTimeLocal As Object() Public Property moonsetTimeUtc As Integer?() Public Property narrative As String() Public Property qpf As Double?() Public Property qpfSnow As Double?() Public Property sunriseTimeLocal As DateTime() Public Property sunriseTimeUtc As Integer?() Public Property sunsetTimeLocal As DateTime() Public Property sunsetTimeUtc As Integer?() Public Property temperatureMax As Integer?() Public Property temperatureMin As Integer?() Public Property validTimeLocal As DateTime() Public Property validTimeUtc As Integer?() Public Property daypart As Daypart() End Class Sub UpdateNlog (HDcode As String, Dvalue As Double, Dstr as String, Always as Integer) ' this routine updates a device and logs it if ' it changed and if logging is turned on for the device or if always is set Try dim Dref = hs.GetDeviceRef(HDcode) ' get the reference to the device based on the house/device code dim dv = hs.GetDeviceByRef(Dref) ' get device settings dim Du = hs.GetDeviceByRef(Dref) ' get device data dim Dstring = hs.DeviceVSP_GetStatus(Dref, Dvalue, 1) ' get the string hs.SetDeviceValueByRef (Dref,Dvalue,TRUE) ' update the device value if Dstr > "" then hs.SetDeviceString (Dref,Dstr,true) ' update the device string if provided Dstring = Dstr ' for the log end if if (dv.MISC_Check(hs, Enums.dvMISC.NO_LOG) = 0) or (Always = 1) then ' should it be logged? hs.WriteLogDetail(Fname,Du.Location(hs) & " " & Du.name(hs) & " set to: " & Dstring, Lcolor, 9,Fname,1) end if Catch Ex As Exception hs.WriteLogDetail(Fname,Ex.Message, "#FF0000", 1,Fname & ":UpdateNlog",9) End Try end sub
Here's one example. (Only the first few icons shown)
Comment