Announcement

Collapse
No announcement yet.

Parse XML into Virtual Device

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

    #16
    Thanks for this interesting post. I would find this useful as well...
    HS3PRO 3.0.0.500 as a Fire Daemon service, Windows 2016 Server Std Intel Core i5 PC HTPC Slim SFF 4GB, 120GB SSD drive, WLG800, RFXCom, TI103,NetCam, UltraNetcam3, BLBackup, CurrentCost 3P Rain8Net, MCsSprinker, HSTouch, Ademco Security plugin/AD2USB, JowiHue, various Oregon Scientific temp/humidity sensors, Z-Net, Zsmoke, Aeron Labs micro switches, Amazon Echo Dots, WS+, WD+ ... on and on.

    Comment


      #17
      Thanks for posting this, traffic info was one of the things I was struggling with to get talking to HS - Google Maps wanted money and any other solutions I saw seemed require subscriptions. Who knows if Bing will end up going the same way but I imagine they get their data from the same sources as all the others at some point...quite whether I will have the confidence to integrate it into my alarm clock I am not sure!

      Here is a script anyway for anyone that needs it, I would suggest a lat/long for the start/end points.

      Code:
      Sub Main(ByVal Parm As Object)
      
          Dim APIKey As String = "Aj7ijQXjYPtIoVOkVatFzrL-s-_EXoi00xyogGeiiiK-Uom8lRHSeXQhZxxxxxxx"
          Dim StartPoint As String = "52.xxx,-1.xxx"
          Dim EndPoint As String = "52.xxx,-2.xxx"
      
          Try
              Dim XMLData As New XmlDocument
      
              Dim URLString As String = "http://dev.virtualearth.net/REST/v1/Routes/Driving?wp.1=" & StartPoint & "&wp.2=" & EndPoint & "&optimize=timeWithTraffic&routePathOutput=Points&distanceUnit=mi&output=xml&key=" & APIKey
      
              XMLData.Load(URLString)
      
              Dim sNS As String = XMLData.DocumentElement.Attributes("xmlns").Value
              Dim oNsMgr = New XmlNamespaceManager(XMLData.NameTable)
              oNsMgr.AddNamespace("def", sNS)
      
              Dim JourneyDuration As String = XMLData.SelectSingleNode("//def:TravelDurationTraffic", oNsMgr).InnerText
      
              hs.writelog("CommuterScript", "Your Journey Will Take: " & JourneyDuration & " Seconds OR " & math.round(convert.todecimal(JourneyDuration) / 60, 2) & " Minutes")
      
          Catch ex As Exception : hs.writelog("CommuterScript", "Error:  " & ex.Message.ToString)
          End Try
      
      End Sub

      Comment


        #18
        Originally posted by mrhappy View Post
        Thanks for posting this, traffic info was one of the things I was struggling with to get talking to HS - Google Maps wanted money and any other solutions I saw seemed require subscriptions. Who knows if Bing will end up going the same way but I imagine they get their data from the same sources as all the others at some point...quite whether I will have the confidence to integrate it into my alarm clock I am not sure!

        Here is a script anyway for anyone that needs it, I would suggest a lat/long for the start/end points.
        Thanks Adam, you saved me from some coding tonight !

        Cheers
        Al
        HS 3.0.0.548: 1990 Devices 1172 Events
        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

        Comment


          #19
          Originally posted by sparkman View Post
          Thanks Adam, you saved me from some coding tonight !

          Cheers
          Al
          I'm going to get the location field from my Google Calendar download script and attempt to place that in this script because I do occasionally work at different places - I have to be careful though before not HS will be making all my decisions in life!!!

          Comment


            #20
            Here's my version of the script which is modified to pass parameters to it and to use an intermediate waypoint. This way I can use the script for multiple scenarios and "force" the selection of specific routes.

            Code:
            Sub Main(ByVal Parms As Object)
            
            	Dim APIKey As String = "sgsdgfgdsGGHY667nhsfssdfgsd9997547dfgdsfgdfgdsgsdg"
            	Dim Debug as Boolean = False
            	Dim logName = "Bing Traffic"				'set log type for HS log
            
            	Dim ParmArray() as String
            	ParmArray = Parms.tostring.split("|")			'split parameter into an array
            	Dim StartPoint = ParmArray(0)				'Starting Location: lat,long
            	Dim IntPoint = ParmArray(1)				'Intermediate Location: lat,long
            	Dim EndPoint = ParmArray(2)				'End Location: lat,long
            	Dim StartPointDesc = ParmArray(3)			'Starting Location description
            	Dim IntPointDesc = ParmArray(4)			'Intermediate location description
            	Dim EndPointDesc = ParmArray(5)			'End location description
            	Dim targetDev as Double = CDbl(ParmArray(6))	'reference ID of the device for which to update value
            
            	'Example parameters 51.0,-114.0|51.1,-114.1|51.2,-114.2|Home|In Between|Work|4655
            		
            	Try
            		Dim XMLData As New XmlDocument
            
            		Dim URLString As String = "http://dev.virtualearth.net/REST/v1/Routes/Driving?wp.1=" & StartPoint & "&vwp.2=" & IntPoint & "&wp.3=" & EndPoint & "&optimize=timeWithTraffic&routePathOutput=Points&distanceUnit=km&output=xml&key=" & APIKey
            		If Debug Then hs.writelog(logName, "<a target=_new href='" & URLString & "'>Bing URL Link</a>")
            
            		XMLData.Load(URLString)
            
            		Dim sNS As String = XMLData.DocumentElement.Attributes("xmlns").Value
            		Dim oNsMgr = New XmlNamespaceManager(XMLData.NameTable)
            		oNsMgr.AddNamespace("def", sNS)
            
            		Dim JourneyDuration As String = XMLData.SelectSingleNode("//def:TravelDurationTraffic", oNsMgr).InnerText
            		Dim Duration As Double = math.round(convert.todecimal(JourneyDuration) / 60, 1)
            		hs.SetDeviceValueByRef(targetDev, Duration, True)
            		hs.SetDeviceString(targetDev, "Travel time from " & StartPointDesc & " to " & EndPointDesc & " via " & IntPointDesc & " is " & Duration & " minutes.", False)
            		If Debug Then hs.writelog(logName, "Your Journey Will Take: " & JourneyDuration & " Seconds OR " & Duration & " Minutes")
            
            		Catch ex As Exception : hs.writelog(logName, "Error:  " & ex.Message.ToString)
            	End Try
            
            End Sub
            Cheers
            Al
            HS 3.0.0.548: 1990 Devices 1172 Events
            Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

            Comment


              #21
              This little addition may help some also, I have a route planned and when the script runs I look through to see if there is any traffic congestion along the route into work. I'm not worried about minor congestion as it always seems to report that but anything more I do wish to know about.

              I don't do anything over the top but I have a small strip of red LED's hidden from view in my lounge that will light whenever I walk into the lounge first thing in the morning, hopefully that will catch my eye and look at the route details as to why there is congestion.

              Code:
              Dim XMLNList As xmlnodelist
                      Dim isThereCongestion As Boolean = False
              
                      XMLNList = XMLData.SelectNodes("//def:Warning[@warningType='TrafficFlow']", oNsMgr)
              
                      For Each NodeInfo As XMLNode In XMLNList
                          'hs.writelog("CommuterScript", NodeInfo.FirstChild.InnerText)
                          Select Case NodeInfo.FirstChild.InnerText.ToLower
                              Case "moderate congestion", "heavy congestion", "severe congestion" : isThereCongestion = True
                              Case "light congestion" : isThereCongestion = False
                          End Select
                      Next
              
                      If isThereCongestion = True Then hs.setdevicevaluebyref(310, 100, True) Else hs.setdevicevaluebyref(310, 0, True)

              Comment


                #22
                Originally posted by mrhappy View Post
                This little addition may help some also, I have a route planned and when the script runs I look through to see if there is any traffic congestion along the route into work. I'm not worried about minor congestion as it always seems to report that but anything more I do wish to know about.

                I don't do anything over the top but I have a small strip of red LED's hidden from view in my lounge that will light whenever I walk into the lounge first thing in the morning, hopefully that will catch my eye and look at the route details as to why there is congestion.
                Thanks for posting that Adam. Will be useful. We should probably start a new thread for the scripts related to the Bing traffic info or have a mod rename this thread so others can find it easier down the road.

                Cheers
                Al
                HS 3.0.0.548: 1990 Devices 1172 Events
                Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                Comment


                  #23
                  sparkman nice script, thanks. unfortunately I'm having issues with the event that checks if is greater than 30 minutes, do you know what I'm doing wrong? The event is fireing with values of 35 although the value is set to 33.3 , should it trigger when the value is only great that 35?
                  Attached Files

                  Comment


                    #24
                    Originally posted by aldo View Post
                    sparkman nice script, thanks. unfortunately I'm having issues with the event that checks if is greater than 30 minutes, do you know what I'm doing wrong? The event is fireing with values of 35 although the value is set to 33.3 , should it trigger when the value is only great that 35?
                    Thanks, but most of the credit goes to Adam (mrhappy). Your event shows the trigger as greater than 35.5, not 30. Does it trigger when it exceeds 35.5?

                    Cheers
                    Al
                    HS 3.0.0.548: 1990 Devices 1172 Events
                    Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                    Comment


                      #25
                      I personally thank Adam as well in private for the script. In regards to the event, since the device value is currently at 33.3 it should not trigger the event if is set to be great than 35.5, Am I missing something basic?

                      Comment


                        #26
                        Originally posted by aldo View Post
                        In regards to the event, since the device value is currently at 33.3 it should not trigger the event if is set to be great than 35.5, Am I missing something basic?
                        It'll only trigger if it's set to a value greater than 35.5.

                        Cheers
                        Al
                        HS 3.0.0.548: 1990 Devices 1172 Events
                        Z-Wave 3.0.1.262: 126 Nodes on one Z-Net

                        Comment

                        Working...
                        X