The purpose of this post is to illustrate an interesting capability of the Fibaro HC2 in managing some very specific devices that are not originally made to be manage by the HC2 ! An IP camera like the Foscam FI8910W presented in my previous post (Improving home security with video monitoring) is a good example for the usage of “virtual device”. The objective is to activate the camera motion detector and the automatic send email function through a script and make available the building blocks for an alarm system.
Here are the constraints when using the HC2 with version 1.046:
– Using the graphical script builder, there is NO specific IP camera command for motion detector & email. The only available command is take a picture !
– Virtual device is therefore a good solution to communicate/send orders to the IP camera through “virtual buttons”.
Let’s consider our IP camera “foscam2” located in the kitchen. The “V-foscam2” is the virtual device associated to this camera. This V-foscam2 has 3 buttons or functionalities:
(i) Arm the motion detector (armer)
(ii) Activate the automatic send email function of the camera (mail)
(iii) Disarm the motion detector (disarmer)
The first & second button will be used to activate the alarm mode.
The V-foscam2 characteristics (general parameters tab) are:
– Controled device: Other device (autre peripherique)
– Location: Kitchen (cuisine)
– IP address of the camera
– Port: TCP port of the camera
In the advanced parameters tab, the script for each button is defined. Basically, the communication with the Foscam will be done through an HTTP query that integrates a CGI command. It may sounds very technical (and it is!) but just follow this tutorial and it will work like a charm!
Arm/disarm the camera motion detector
The key CGI command is “set_alarm.cgi” with a list of parameters:
– motion_armed=1 (1=Arm, 0=Disarm)
– mail=1 (1=Arm, 0=Disarm)
– user=camera-login (this is the camera login with no quotation mark)
– pwd=camera-pass (and the camera password with no quotation mark)
The full script for the button “Arm the motion detector” is:
GET /set_alarm.cgi?motion_armed=1&user=admin&pwd=1234 HTTP/1.10x0D0x0A0x0D0x0A
The “HTTP/1.10x0D0x0A0x0D0x0A” is a string to indicate that you are sending an HTTP query. Don’t ask why or how, this is all I know but most important is that it works nice !
For more information on CGI commands, have a look at this IP Camera CGI manual.
Virtual device management
We have defined a virtual device v-foscam2 with 3 buttons (arm, activate email and disarm). The iPhone HC2 client has some limitation: the current version can NOT manage virtual devices. A turn around solution is to use some script and then launch the scripts from the iPhone. The virtual buttons will be called within a regular script.
Here is the script to arm the camera:
(i) If the camera is not already armed (use of a local variable/parameter: 1=armed), 0=disarmed)
a. Arm the camera using the virtual button “V-foscam2 armer”
b. Activate the email using “V-foscam2 mail”
c. Set the local variable “#foscam2 armer” to 1, meaning the camera is armed.
More details in a new post (part 2) coming next week !