Announcement

Collapse
No announcement yet.

Dark Sky API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Dark Sky API

    Are there any plugs ins using the Dark Sky API? (https://darksky.net/dev/)

    Jeff - Could it be added to WeatherXML?

    Cheers
    Scott

    #2
    If you don't get any luck then it would appear to be fairly easy to get going with just a script, one of the JSON scripts knocking around could probably be modified fairly easily.

    Comment


      #3
      Originally posted by mrhappy View Post
      If you don't get any luck then it would appear to be fairly easy to get going with just a script, one of the JSON scripts knocking around could probably be modified fairly easily.
      I'm going to have a crack at that this afternoon - I'm going to look at Jon00's scraper app first, faiiling that I'll knock up a script.

      Comment


        #4
        This is a start if you get stuck...unfortunately I have a number of other plugins on the go at the minute so I wouldn't be up for making it into a plugin myself. This will get the basic 'currently' data from the API and put it in the log, anything more complex would need the JSON structures expanding.

        Code:
        Imports System.Web.Script.Serialization
        
        Dim secret_key As String = "af4f2bb899888d0db"
        Dim json As New JavaScriptSerializer
        Dim LT as string = "DarkSky Script"
        Dim LatLong As String = "" 'leave blank to use HS lat/long data
        
        Sub Main(ByVal Parms As Object)
        
            Try
                If LatLong = "" then LatLong = Convert.ToDecimal(hs.getinisetting("Settings","gLatitude","37.8267")) & "," & Convert.ToDecimal(hs.getinisetting("Settings","gLongitude","-122.4233") * -1)
                Dim DataRaw As String = hs.GetURL("https://api.darksky.net/", "forecast/" & secret_key & "/" & LatLong, true, 80)
                Dim DSData As rdata = json.Deserialize(Of rdata)(DataRaw)
        
                hs.writelog(LT, "Current Summary: " & DSData.currently.summary)
                hs.writelog(LT, "Current Temperature: " & DSData.currently.temperature)
                hs.writelog(LT, "Current Humidity: " & DSData.currently.humidity)
                hs.writelog(LT, "Current Visibility: " & DSData.currently.visibility)
        		
            Catch ex As Exception
                hs.writelog(LT, "Exception: " & ex.message.tostring)
            End Try
        
        End Sub
        
        Public Class rdata
            Public Property latitude As double
            Public Property longitude As double
        
        	Public Property currently As currentdata
        End Class
        
        Public Class currentdata
        	Public Property time As String
            Public Property summary As String
            Public Property icon As String
            Public Property nearestStormDistance As integer
            Public Property nearestStormBearing As integer
            Public Property precipIntensity As integer
            Public Property precipProbability As integer
            Public Property temperature As decimal
            Public Property apparentTemperature As decimal
            Public Property dewPoint As decimal
            Public Property humidity As decimal
            Public Property windSpeed As decimal
            Public Property windBearing As decimal
            Public Property visibility As decimal
            Public Property cloudCover As decimal
            Public Property pressure As decimal
            Public Property ozone As decimal
        End Class
        You just need to change the API key to your own.

        Comment


          #5
          Was just wondering if anyone has done anything to expand on this? I'd definitely be interested in a full weather plugin that uses the Dark Sky API...

          Comment


            #6
            Originally posted by teladog01 View Post
            Was just wondering if anyone has done anything to expand on this? I'd definitely be interested in a full weather plugin that uses the Dark Sky API...
            Not me personally weather plugins ain't been really my thing (I can never be bothered to find the icons) I can't see a need for a plugin myself because it could be done all from a script just would need to write to a device rather than the log.

            Comment


              #7
              Originally posted by teladog01 View Post
              Was just wondering if anyone has done anything to expand on this? I'd definitely be interested in a full weather plugin that uses the Dark Sky API...
              I created a plug-in a while ago to support the Dark Sky API. I never released it because the Dark Sky does not allow free use of their API. The only way I could have released it is to set an expire timeframe after activation (e.g. 5 years). I decided not to release it because there was no way for me to prevent abuse of the Dark Sky API using my API key.

              Regards,
              Ultrajones
              Plug-ins: UltraMon, UltraM1G, UltraCID, Ultra1Wire, UltraLog, UltraWeatherBug, UltraPioneerAVR, UltraGCIR

              Comment


                #8
                Originally posted by mrhappy View Post
                This is a start if you get stuck...unfortunately I have a number of other plugins on the go at the minute so I wouldn't be up for making it into a plugin myself. This will get the basic 'currently' data from the API and put it in the log, anything more complex would need the JSON structures expanding.
                Just wanted to say thanks to mrhappy for posting the Dark Sky starter script. I've expanded upon it and made changes to suit my needs and it seems to be working great.

                Thanks!

                Comment


                  #9
                  Originally posted by teladog01 View Post
                  I've expanded upon it and made changes to suit my needs and it seems to be working great.
                  I'd like to see how you ended up deserializing the forecasted dark sky data in vb.net and assigning variables to the data.

                  I've been working on this and haven't got it working right yet.

                  Thanks!

                  Comment


                    #10
                    Originally posted by frankc View Post
                    I'd like to see how you ended up deserializing the forecasted dark sky data in vb.net and assigning variables to the data.

                    I've been working on this and haven't got it working right yet.

                    Thanks!
                    Here's my script. It's made to be able to fetch data for multiple locations by specifying some parameters when the script is run. The parameters are pretty well commented in the script, but I'll admit I haven't tested it with more than a single location, so use at your own risk.

                    The script does not automatically create any devices, so you will need to manually create the six devices per location as seen in the screenshot below. These are the only six devices I'm really interested in for my use, so that is the only ones implemented. But the framework is there to add many more devices that correspond to the data returned by the Dark Sky API.

                    You will need to edit the "secretKey" constant at top of the script, and there are four other constants right below it that you can edit as you see fit to suit your HS3 environment.

                    Many thanks to @mrhappy for posting the example earlier in this thread, which my script is heavily based upon.
                    Attached Files
                    Last edited by teladog01; November 2, 2017, 09:57 PM.

                    Comment


                      #11
                      Here's some screenshots of the device configs...
                      Attached Files

                      Comment


                        #12
                        more screenshots...
                        Attached Files

                        Comment


                          #13
                          Originally posted by teladog01 View Post
                          Here's my script.
                          Nice!

                          Great looking icons too.

                          I'll go ahead and create the six devices and it'll be a done deal.

                          I'm also working on forecasted data. Not sure what I'll do with it yet. Maybe have to get that into HSTouch stuff.

                          Thank you!

                          Frank

                          Comment


                            #14
                            Data Refresh

                            I seem to have this working now!

                            What do you do about refreshing the weather data on the screen?

                            Comment


                              #15
                              Originally posted by frankc View Post
                              I seem to have this working now!
                              Awesome! Glad it's working for you. I've borrowed many scripts from this forum so it feels good to be on the other side and give one back

                              What do you do about refreshing the weather data on the screen?
                              I just run the script periodically with a simple event with a recurring trigger set for every five minutes. That works out to 288 calls per day which is well under the 1000 free calls per day offered by the Dark Sky API.

                              Comment

                              Working...
                              X