Page 1 of 1

External Control example

Posted: Tue Oct 20, 2015 2:12 pm
by Richard Naninck
On top of Scotts Tip about the Amazon Echo the other day I would like to add the following.

To be able to send data to HouseBot, use the External Control device just like the Echo example in the Tips and Tricks section. Set it to ASCII = NO and assign a port.

I downloaded Mongoose webserver and assigned a port to it different than the standard 80. Opened this port in my router and now any application able to send url (http://myip:myport/index.vbs?here_comes_my_data) like IOS Geofancy or IOS Home Remote or IOS iControl can be used to control HouseBot.
A simple and nice example would be with Geofancy: I set a point on my house's location with a radius of 50 meters. When leaving the radius, an url gets sent to Mongoose which index.vbs parses and inputs the data using external control to HouseBot. I can have HouseBot check if the garagedoor is closed and if not, notify myself that I forgot to close the door.
Below the code for Mongoose config file and the code for index.vbs
Copy C:\Windows\System32\cscript.exe to Mongoose document root

Have fun!

cgi_interpreter cscript.exe
cgi_pattern **.cgi$|**.vbs$|**.php$|**.pl$
document_root C:\Program Files\Webserver
listening_port 80

Code: Select all

Option Explicit

Dim objShell
Dim objHB
Dim strValue
Dim intLength
Dim ReceivedData
Dim arrData
Dim arrLabel
Dim nit

Set objShell = CreateObject("WScript.Shell") 
Set objHB    = CreateObject("HBControlMod.HBControl")
Call objHB.Connect(4721, "192.168.0.3", "")

For Each strValue In objShell.Environment("Process") 

	If strValue = "REQUEST_METHOD=POST" Then
		intLength    = objShell.ExpandEnvironmentStrings("%CONTENT_LENGTH%") 
		ReceivedData = Replace(WScript.StdIn.Read(intLength), "?", "")
		Exit For
	End If
	
	If InStr(strValue, "QUERY_STRING") Then
		arrData = Split(Replace(Replace(strValue, "QUERY_STRING=", ""), "%20", " "), "&")
		
		For nit = 0 To UBound(arrData)
			arrLabel = Split(arrData(nit), "=")
			
			Select Case arrLabel(0)
				Case "cmd": ReceivedData = arrLabel(1)
				Case "id" : ReceivedData = ReceivedData & "^" & arrLabel(1)
			End Select
		Next
		
		Exit For
	End If 
Next 

Call objHB.SetPropertyValue("myDevice", "myProperty", ReceivedData)

Set objHB    = Nothing
Set objShell = Nothing

Re: External Control example

Posted: Thu Nov 05, 2015 12:38 pm
by Steve Horn
Richard, I've been following the Echo thread and have an Echo on the way. (I've threatened to get one anyway, but Scott's post put me over the edge.) Anyway, any particular reason you went with Mongoose web server instead of Windows built-in? Just curious... And I'm getting fired up to play with the Echo and HB.

Re: External Control example

Posted: Thu Nov 05, 2015 1:19 pm
by ScottBot
Steve,

FYI: with the next HouseBot release (coming soon...), the external control device will allow HTTP control. This would allow the Echo Bridge software to connect directly to HouseBot without needing a webserver with HB_Control.cgi setup.

Not sure if that will be the best setup for your system or not, but it will be an option.

Re: External Control example

Posted: Thu Nov 05, 2015 1:34 pm
by Steve Horn
Good to know - will be looking for it! If I understand this, I'll still need the jar step to create the echo bridge function.

Echo is to be delivered tomorrow, giving me time to play with its basic and not so basic functionality.

Re: External Control example

Posted: Thu Nov 05, 2015 1:43 pm
by Richard Naninck
Steve Horn wrote:Richard, I've been following the Echo thread and have an Echo on the way. (I've threatened to get one anyway, but Scott's post put me over the edge.) Anyway, any particular reason you went with Mongoose web server instead of Windows built-in? Just curious... And I'm getting fired up to play with the Echo and HB.
Well uhhh, simply because I didn't know such a Windows Service existed native.
I am trying to get it to work right now but without succes so far. Mongoose is very easy to setup but did cost me 5$ to get the pro version to have cgi enabled after one weeks use.

Re: External Control example

Posted: Thu Nov 05, 2015 2:14 pm
by Steve Horn
After your post a did a quick read-up on Mongoose. Yes, even to me, seemed easy to set up and go with. I say, use whatever works. Never mind Windows web server.

Re: External Control example

Posted: Mon Nov 16, 2015 5:14 pm
by Steve Horn
Richard, I got looking into the idea of geofencing as a result of your posting. Geofancy does not currently support Android devices (although I did find a public domain version that is supposedly Android). However, I did find two that are: Autolocation, which looks to be far more functional than what is needed here, and EgiGeoZone, http://www.egigeozone.de/default.html which looks to be similar to Geofancy. However, its doc is all in German. With the help of Google Translate it may work out though. (Fortunately the app itself is presented in English.)
So far, I've thought of two applications: 1) Turn on garage lights when I'm within x of the house and driving, and 2) Turn on the alarm system (if I've forgotten to) when I've left the fence perimeter. I'm sure there are more.

Re: External Control example

Posted: Tue Nov 17, 2015 3:33 am
by Richard Naninck
Would you arm the alarm or just push a notification that you forgot to arm? What if somebody is still home?
Geofences work but are still not flawless so it should be an aid versus a reliability.
Nice to have more people thinking about this because it is a nice new addition to HA

Re: External Control example

Posted: Tue Nov 17, 2015 7:49 am
by Steve Horn
Good thoughts on this. I haven't worked out the details - haven't even got it functional yet. Need to set up DDNS among other things. But I was able to do a test run on external control in preparation for HB/Echo integration. It will be interesting to hear what others do with geofencing.

Re: External Control example

Posted: Thu Nov 19, 2015 4:27 am
by Richard Naninck
Since yesterday I stopped using Mongoose since HB_External control can now use http requests directly. Not sure if it has been released yet but it works great. Links must be something like this:

http://yourip:port/SPV?D=my%20device&P=my%20property&V=my%20value

Re: External Control example

Posted: Thu Nov 19, 2015 7:11 am
by Steve Horn
I downloaded the new release and tested the external control HTTP option as part my HB/Echo integration. Works fine. Still dealing with another issue on that Echo work though.

Re: External Control example

Posted: Thu Nov 19, 2015 8:45 am
by ScottBot
Richard Naninck wrote:Since yesterday I stopped using Mongoose since HB_External control can now use http requests directly. Not sure if it has been released yet but it works great. Links must be something like this:

http://yourip:port/SPV?D=my%20device&P=my%20property&V=my%20value
It's in the latest 3.31 release. The released version also displays the help (and examples) if you enter something wrong or nothing at all.

Re: External Control example

Posted: Tue Dec 08, 2015 8:36 am
by jacco van der Ven

Re: External Control example

Posted: Tue Dec 08, 2015 10:09 am
by Richard Naninck
Yep.
iControl Web, Home Remote, Geofancy but also the Siti HomekitBridge running on a Raspberry Pi can output URL that can be inputted in HouseBot.