Announcement

Collapse
No announcement yet.

What I've been doing with PHLocation and maybe a feature request?

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

    What I've been doing with PHLocation and maybe a feature request?

    ImperiHome
    So, some back story. I work 2 hours away (1 way), but I only have to go in the office every other week. On the days that I go, My wife likes to check my progress on my way back. PHLocation mixed with Backitude and Imperihome does this swimmingly. I started with a simple tile that showed her the minutes from home. This way she could plan dinner, or know how much longer till she is done dealing with the kids alone...LOL.

    That worked great and she loved it, but I wanted to go a step further, so I started playing around with it. Instead of a single tile in Imperihome, I went to a whole page. PHLocation provides a map, so I decided to use this. Because I don't know how to access things from the /html folder from outside my house (I know I can do port forwarding, but I Don't want to expose that), I decided to upload them via FTP to my personal Server. I also upload a file which contains the "link" that PHLocations puts in the "Street Address" device. I use scripting on my server to generate a page where the image is a link and I call that from Imperihome.

    In case anyone wants the script I'm using to do this, here it is:
    Code:
    Imports System.Text.RegularExpressions 
    
    Sub Main(ByVal Parms As String)
    	Dim ParmArray() As String = Parms.tostring.split(",")
    	Dim userDeviceID As Integer = CInt(ParmArray(0))
    	Dim addressDeviceID As Integer = CInt(ParmArray(1))
    	Dim localFileLocation As String = "C:\Program Files (x86)\HomeSeer HS3\html\PHLocation\Maps\"
    	Dim remoteFileLocation As String = "ftp://[removed]/HA/PHLocation/Maps/"
    	Dim AddressFile As String = localFileLocation & CStr(userDeviceID) & ".cfm"
    
    	If System.IO.File.Exists( localFileLocation & CStr(userDeviceID) & ".cfm" ) = True Then
    		Dim objWriter As New System.IO.StreamWriter( localFileLocation & CStr(userDeviceID) & ".cfm" , false)
    		objWriter.WriteLine( hs.DeviceString( addressDeviceID ) )
    		objWriter.Close()
    	End If
    
    	' upload location file
    	Dim miRequest As Net.FtpWebRequest = Net.WebRequest.Create( remoteFileLocation & CStr(userDeviceID) & ".cfm" )
    	miRequest.Credentials = New Net.NetworkCredential("[removed]", "[removed]")
    	miRequest.Method = Net.WebRequestMethods.Ftp.UploadFile
    
    	Dim bFile() As Byte = System.IO.File.ReadAllBytes(localFileLocation & CStr(userDeviceID) & ".cfm")
    	Dim miStream As System.IO.Stream = miRequest.GetRequestStream()
    	miStream.Write(bFile, 0, bFile.Length)
    	miStream.Close()
    	miStream.Dispose()
    
    	' upload map image
    	Dim miRequest2 As Net.FtpWebRequest = Net.WebRequest.Create( remoteFileLocation & CStr(userDeviceID) & ".png" )
    	miRequest2.Credentials = New Net.NetworkCredential("[removed]", "[removed]")
    	miRequest2.Method = Net.WebRequestMethods.Ftp.UploadFile
    
    	Dim bFile2() As Byte = System.IO.File.ReadAllBytes(localFileLocation & CStr(userDeviceID) & ".png")
    	Dim miStream2 As System.IO.Stream = miRequest2.GetRequestStream()
    	miStream2.Write(bFile2, 0, bFile2.Length)
    	miStream2.Close()
    	miStream2.Dispose()
    	
    end sub
    Note that it accepts 2 parameters. The Device ID of the Root Device for the user and the Device ID for the Street Address Device. I do this because i upload 2 files, one for myself and one for my wife.

    This script runs whenever the street address device changes.

    I also include 4 other values on that page via an ImperiHome sensor combo widget: City, Speed, distance from home, time to home.

    Alexa/Voice Status
    In addition to this, I wanted a way for my wife to check my progress without having to pull out her phone. Enter Jon00's awesome Alexa Helper script (http://board.homeseer.com/showthread.php?t=184504). Now my wife can ask in a couple different ways where I am. I know, it sounds stalky, but most the time I am home, so I don't really care...LOL

    In order to do this though, I needed something to tell me where I am in a nice text format. So I wrote another script that runs the same time that the FTP one above does. This script checks a couple of different values and "builds" a string and sets that as the devices string. This one is a bit more customized and not so easy for someone else to use, but here it is anyways:

    Code:
    Imports System.Text.RegularExpressions 
    
    Sub Main(ByVal Parms As String)
    	Dim ParmArray() As String = Parms.tostring.split(",")
    	Dim LocationString As String = ""
    	If ParmArray(0) = "Frank" Then
    		If hs.DeviceValue(667) = 1 Then
    			hs.SetDeviceString( 1982 , "" , false )
    			hs.SetDeviceValueByRef( 1982 , 1 , true )
    '			LocationString = "Frank is at Home"
    		ElseIf hs.DeviceValue( 1972 ) = 1 Then
    			hs.SetDeviceString( 1982 , "" , false )
    			hs.SetDeviceValue( 1982 , 2 , true )
    '			LocationString = "Frank is at the Office"
    		Else
    			' Frank was at the office since being at home, he is currently moving faster than 5 mph, and he is approaching home
    			If hs.DeviceLastChangeRef( 1972 ) > hs.DeviceLastChangeRef(667) And hs.DeviceValue( 658 ) > 5 And hs.DeviceValue(668 ) = 1 Then
    				LocationString = "Frank is currently in " + hs.DeviceString( 651 ) + " and is about " + CStr( hs.DeviceValue( 672 )) + " Minutes from home."
    			' If moving
    			ElseIf hs.DeviceValue( 658 ) > 5 Then
    				Dim LocationNoHTML As String = Regex.Replace(hs.DeviceString(650), "<.*?>", "")
    				Dim LocationArray() As String = LocationNoHTML.split( {","} , StringSplitOptions.RemoveEmptyEntries )
    				LocationString = "Frank is Driving " + hs.DeviceString(660) + "down " + Regex.Replace(LocationArray(0), "^[\d-]* ", "") + " at " + CStr( hs.DeviceValue( 658 ) ) + " miles per hour"
    			Else 
    				Dim LocationNoHTML As String = Regex.Replace(hs.DeviceString(650), "<.*?>", "")
    				Dim LocationArray() As String = LocationNoHTML.split( {","} , StringSplitOptions.RemoveEmptyEntries )
    				LocationString = "Frank is currently At " + LocationArray( 0 ) + " " + LocationArray( 1 ) + " " + LocationArray( 2 ) + ". "
    			End If
    			hs.SetDeviceString( 1982 , LocationString , false )
    			hs.SetDeviceValueByRef( 1982 , 0 , true )
    		End If
    	Else
    		If hs.DeviceValue(704) = 1 Then
    			hs.SetDeviceString( 1983 , "" , false )
    			hs.SetDeviceValueByRef( 1983 , 1 , true )
    			LocationString = "Sara is at Home"
    		Else
    			' If moving
    			If hs.DeviceValue( 700 ) > 5 Then
    				Dim LocationNoHTML As String = Regex.Replace(hs.DeviceString(692), "<.*?>", "")
    				Dim LocationArray() As String = LocationNoHTML.split( {","} , StringSplitOptions.RemoveEmptyEntries )
    				LocationString = "Sara is Driving " + hs.DeviceString(702) + "down " + Regex.Replace(LocationArray(0), "^[\d-]* ", "") + " at " + CStr( hs.DeviceValue( 700 ) ) + " miles per hour"
    			Else 
    				Dim LocationNoHTML As String = Regex.Replace(hs.DeviceString(692), "<.*?>", "")
    				Dim LocationArray() As String = LocationNoHTML.split( {","} , StringSplitOptions.RemoveEmptyEntries )
    				LocationString = "Sara is currently At " + LocationArray( 0 ) + " " + LocationArray( 1 ) + " " + LocationArray( 2 ) + ". "
    			End If
    			hs.SetDeviceString( 1983 , LocationString , false )
    			hs.SetDeviceValueByRef( 1983 , 0 , true )
    		End If
    	End If
    end sub
    Notice it takes 1 param, the person's name.

    So, in my "virtual" devices I have set up 3 values:
    0 is "not at any known locations"
    1 is "At home"
    2 is "At the office" (sara doesn't work right now so doesn't have an office).

    I have their values set accordingly on the status graphics tab.

    You'll also notice that for "0", I build a string and add it. Have a couple of different scenarios. I'll do mine since there are more:

    1. Frank is Home - I just set the device value to 1
    2. Frank is at work - I just set the device value to 2
    3. Frank is at neither - This is where it gets fun!
    3.a I am moving and I have been at work since I've been home. I must be driving home: "Frank is currently in [City] and is about [Time from home] Minutes from home."
    3.b. I'm not home, but I'm moving: "Frank is driving [Course] down [Street] at [speed] miles per hour"
    3.c Any other situation: "Frank is at [Address]"

    My wife's are simpler, but follow some of the same rules. I may add in some other things like how long I've been at a place.

    To do all this all my wife has to do is ask the Echo: "Alexa, ask The House where Frank is" (or My Husband, or Daddy, or Dad, or Bubba (what my kids call me) and Jon00s script just sends back the devices string for that virtual device.

    This is the config for my jon00s helper for getting this information:
    Code:
    [Trigger1]
    
    AlexaText=frank he's||where frank||frank yes||where husband||where dad||husband is||dad is||where daddy||daddy is||where bubba||bubba is||franke's
    Mode=1
    AlexaResponse=[devicetext 1982]
    RunEvent=
    Runscript=
    Speak=
    SPClient=
    SpeakDevice=
    CAPI=
    Json=
    DeviceValue=
    SetDeviceValue=
    SetCapiValue=
    Delay=
    * note that the AlexaText values are odd. I used the logs to determine what her and I were saying. For some reason it doesn't like Frank (and will come back as Franke sometimes). Luckily the helper script lets you do logical ORs so if it misses one I can add it in there. It also seems to miss "where" a lot when asked "Alexa Ask the House where frank is". It will just return "frank is" about half the time. Very frustrating.

    Possible feature requests:
    • MY new virtual device is kinda of specialized, but would it be possible to have a device like this automatically created and populated with your known places? 0 could always be "at no known locations for this user" and there could be a scripting hook that when it's 0 (zero) you can run that script (to set the device string). The plugin could then add values for known places as you create them.

      The plugin could even be smart and have some of the strings I have above automatically done like "So and So is drving down [street] and heading towards [known place]".
    • A way to grab all the known places and/or users/devices from scripting so I can just loop through them and check the values (would simply my script and make it easier to decide where they are as I add users)

    I know, it's a lot. I'm just throwing stuff out there. It's completely possible to do all/most this via scripting (Which is awesome by itself!).

    Future additions:
    • I think I'm going to change my "webpage" that has the map to include my virtual device text as well. Imperihome doesn't do a good job at wrapping text.
    • At some point I will be adding a status screen in the house (I keep dreaming for a reasonably priced, well sized e-ink display to be released). When I do, I will use some of the stuff here to populate that.
    • When my kids get phones, I will be adding this stuff for them. It's not that I don't trust them, but it will be nice to know where they are. I have a feeling when I do that, I will be adding lots of known locations to account for friend's houses and stuff like that ("Where is Winnie?": "Winnie is a Babara's house").


    Things I want to do but can't yet (not the fault of this plugin!). Ok, mostly the fault of ImperiHome.
    • I wish Imerihome would not make me put that stupid generic sensor icon on the combo sensor widget
    • I wish that Imperihome would allow me to open links in tiles outside that tile (so that when you click the map, it opens either google maps in a browser or the app)
    • I wish that I could make sensors in Imperihome "clickable" to go to another page. This way I could make the icon on the main menu more meaning full, but still have a way to get "more information"
    • I wish I could convince my wife to take her phone with her everytime she leaves the house (even if she leaves it in the car)..LOL
    • I hope one day I can do all of the Alexa stuff on Google Home (which I haven't bought yet!)


    Images
    here are some Images (I wanted to put them inline, but I really can't on this forum very well). My map is blurred because I don't want my location (Besides my city) out there
    Attached Files
    Last edited by sirmeili; November 10, 2016, 05:38 PM. Reason: Fixed some issues in the code that adjusts the virtual device status string

    #2
    Thank you for the detailed update on your project and especially acknowledging how you have integrated several plugin to produce the outcome.

    So what I thought was missing in the summary was do you get the meals on time... just joking

    Well done.

    Comment


      #3
      Originally posted by brientim View Post
      Thank you for the detailed update on your project and especially acknowledging how you have integrated several plugin to produce the outcome.

      So what I thought was missing in the summary was do you get the meals on time... just joking

      Well done.
      To be honest, she never waits for me to eat and I don't expect her too. I would rather eat cold food and get the kids to bed on time....lol

      Sent from my XT1585 using Tapatalk

      Comment


        #4
        So, I didn't really like that it only said the address. So I looked up how to use either an address or GPS coordinates to look up the business at a location. so i found I could call Google Places API and return a list of places with in X meters (I used 100, but I may want to tweak it). It's not foolproof and I know I still have some tweaking to do, but my hope is that I will be able to do something like:

        "Frank is a Publix Super Market"

        without me having to have a ton of known places set up in PHLocation.

        I need to test some more (by driving around) and see how it works. I would like to at some point track how long it's been since I've been moving and only use the location name then. I think I can do this by checking how long the speed device has been since it updated.

        Finally, I did code it so that it defaults to the address. If it can't find a place near by it will just give the address (needed for residential). it also sometimes returns the "city" as it's own location. I know I can filter it out, but it doesn't come through each time. I think it has to do with how close to the city limits you are. Right now it is sorted by Prominence, so that should work (I hope) most of the time

        I've also thought about updating a device with this information so that I can trigger other things in the system. For instance:

        When Frank's Location has been "Publix Supermarket" for 2 minutes And Frank's City is "Sebring" Notify Sara via pushover "Frank is at Publix, you should message him if you need something."

        Sorry, for the ramblings...Just getting into scripting for HS and trying lots of new things. At some point I would like to make a plugin (perhaps one that will handle these things)...which makes me wonder, can you have a plugin that has dependencies on other plugins?

        Eitherway, none of this would be possible without this awesome plugin

        Edit: And I know I could create a known place for Publix, but it creates a lot of devices and I'm thinking I could just have a list of stores that I could search the location name for and send her a notification if I'm there.
        Last edited by sirmeili; November 15, 2016, 10:30 PM.

        Comment


          #5
          So, it worked I went to the grocery store last night. I also as able to:
          • add in the "only use this if speed has been 0 for more than 2 minutes
          • Exclude "locality" and "political" places (like a "city")


          Obviously I will be monitoring it to see how it works. At least it will give a general idea. I picked some GPS coordinates of places we visit in town and plugged them into a test script and so far it picks the place I actually thought it should be.
          Attached Files

          Comment


            #6
            So, I kept getting collisions while trying to upload the maps, so I set out to find a solution. After using google's apis to get the business name, I realized I could use the same methods for getting my map into ImperiHome.

            So I wrote a web service on my web server (offsite) to store and retrieve the locations. I'm just writing out to an INI file and reading from that when I call the getMap service. The great thing about it is I can put multiple markers so instead of 1 person on a map, I can have 2 and we can see our relation to each other. I also added the ability to send it what the Marker Labels should be (F for Frank and S for Sara) and then the color of the markers. I'm sure there is more I can do with the API, but so far this is good enough. I'm a bit worried about the quota, but I"ll have to see if I go over it. We don't normally stand there and look at the app.

            I normally don't like depending on web services, but since most of this depends on us having internet anyways, I don't mind. I mean, if I'm not at home and I don't have internet, there is no way for Homeseer to know my location anyways.

            Comment


              #7
              Originally posted by sirmeili View Post
              So, it worked I went to the grocery store last night. I also as able to:
              • add in the "only use this if speed has been 0 for more than 2 minutes
              • Exclude "locality" and "political" places (like a "city")


              ...
              So I went to Taco Bell tonight (Wife wanted some tacos), and I noticed something. It updated the location while i was driving up the drive-through so my speed was 1 mph, however, since I didn't move much further, i don't think it updated my location again (understandable). I checked Backitude and it said my last update included a speed of 0, so I think the plugin just ignored all updates because the location didn't change enough.

              @Sooty (Paul), would it be possible to still change the speed device even if the location hasn't changed much? Or am I crazy and it already does?

              The hardest part about debugging this stuff is that I'm not at my computer when I'm testing it, so I have to depend on logs and what comes through ImperiHome.

              Comment


                #8
                Nicely documented.

                I have not been able to get the map to display - still working on it, albeit slowly.

                Michael
                Last edited by Rvtravlr; December 6, 2016, 11:53 PM.
                Michael

                Comment


                  #9
                  Frank, I just stumbled across this thread. First, thank you! I have been slowly working to do something similar (minus imperihome as I don't use it) and you basically just handed it to me on a silver platter.

                  Can you expand a little bit on how you are using the google API? I messed with Bing a while back to get traffic data, but found it wasn't really reliable.

                  Thank you again for taking the time to build the scripts, it will be a nice addition.
                  Last edited by waynehead99; December 7, 2016, 03:24 PM.

                  Comment


                    #10
                    Originally posted by waynehead99 View Post
                    Frank, I just stumbled across this thread. First, thank you! I have been slowly working to do something similar (minus imperihome as I don't use it) and you basically just handed it to me on a silver platter.

                    Can you expand a little bit on how you are using the google API? I messed with Bing a while back to get traffic data, but found it wasn't really reliable.

                    Thank you again for taking the time to build the scripts, it will be a nice addition.
                    I have updated my scripts as I've been testing. I'll post the "new" ones tomorrow. I'll also try and find some time to get some instructions up for using the google API. For the "Place data" (name of business) Its free for so many requests, but if you give them a CC, you get up to 150k request for free as well (and they don't do overage charges...they just fail after 150k unless you tell it not to).

                    The maps I'm not to sure about the limits, but if you aren't going to be "displaying" the map or accessing it remotely, then you can just use the ones PHLocation provides. I know I haven't hit the limit myself though, but we don't normally check all that often in Imperihome. It's there just in case.

                    Comment


                      #11
                      @sirmeili firstly thanxs for sharing your script(s) and idea's with how to use PHLocation.. you opened my eyes to more than entry/exiting fences!

                      Question to you I noticed that you have a map (albeit blurred) being displayed in IH can you share what you did to be able to display it. I see two map with Pins that I assume create a static map? Any help/guidance would be greatly appreciated thanxs in advance. Mike
                      Computer: CUK Intel NUC7i7BNH
                      Op System: Windows10 Pro - Work Station
                      HS Version: HS4 Pro Edition 4.2.19.0

                      Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                      Comment


                        #12
                        Frank, it been a little while since our last conversation.. where are you in reference to your Imperihome solution and are you using PHL2 per chance or something else? Mike
                        Computer: CUK Intel NUC7i7BNH
                        Op System: Windows10 Pro - Work Station
                        HS Version: HS4 Pro Edition 4.2.19.0

                        Plug-Ins: AK Weather 4.0.5.25,APCUPSD 3.3.2.3,BLBackup 2.0.63.0,BLEditor 2.0.11.0,BLGData 3.0.55.0,BLOccupied 2.0.28.0,BLShutdown 1.0.6.0,Blue-Iris 3.1.3.33206,Device History 3.2.0.2,EasyTrigger 3.0.0.76,Harmony Hub 4.0.14.0,iRobot 5.22.41.1,JowiHue 4.0.8.7,Nest 3.0.0.34,NetCam Plugin 1.0.0.5,PHLocation2 3.0.0.64,Pushover 4.0.10.0,Random 3.0.0.2,Restart 1.0.0.7,Ring 1.0.0.9,SDJ-Health 3.1.1.3,Sonos 3.1.0.59,Sonos4 4.0.1.12,UltraCID3 3.0.6681.34300,UltraMon3 3.0.6554.33094,UltraNetCam3 3.0.6413.20219,Unifi 4.0.32.0,Zigbee 4.0.11.0,Z-Wave 4.0.3.0, and Jon00 scripts.

                        Comment

                        Working...
                        X