Idea for FOSCAM camera binding

Hello together,

i’m interested in developing a binding for FOSCAM H.264 IP cameras to control the alert detection status.

Currently, it is possible to switch this status via HTTP commands.
The API is available here: (see first ZIP-File, FC IP Camera CGI User Manual.pdf)

A better way for controlling this status will be a binding and some actions to doing this with simple items like Switch Camera_Motion_Detect [ON|OFF] and Number Camera_Motion_Sensity [0-5] and so on.

My question: Is there something in the project pipeline or is there any interested to do this together?
I’m new in binding programming, but this is a good start for me and i really need it :smile:


1 Like

I’m interested in participating. I currently control my Foscam camera using a pure Python library that I access from JSR223 Jython rules. I currently can display the camera name and model name, control motion detection and IR enable/disable (and manual/auto mode), display the last user login name and time and can take and display snapshots from openHAB UI.

Can these cameras report motion using a callback URL or similar like the previous generation Foscam cameras? I read through the API manual some months ago and never found such a feature. An example of old vs. new interfaces is here: Security Camera Recommendations

I don’t think the newer API supports it. I had seen a reference to this functionality in another post and I looked in the API and in the web app and didn’t see any support for it.

That’s too bad that they appeared to have removed the feature with their later cameras.

It would be great if any binding written for Foscam cameras could auto-detect (or at least attempt to auto-detect) the camera’s firmware version, so one binding could work across the greatest range of their cameras, so, for the most part, a binding under the name org.openhab.binding.foscam would be able to address the widest range of Foscam cameras possible. Excluding older models would be a missed opportunity, IMHO. And writing a binding would have to be an improvement over existing methods like using the HTTP binding, I would hope.

On a related subject, does anyone know of a straightforward way to see the image or video stream at a URL that is the state of a String item in openHAB 1.x (as opposed to being hardwired into a sitemap)? If not, is such possible in OH2/ESH? If not, I think this might be a good feature to add to some UI component(s). When I added Nest Cam support to the Nest binding, I came up empty on how to achieve that.

Another option could be to write a motion binding. This is very easy to setup and works well with all sorts of different IP/USB cameras. There is a nice simple REST API for enabling/disabling motion detection and it provides a mechanism for calling out to custom scripts and programs on various events.

For example I have 4 cameras (all different types) dotted around the house all being monitoring by one instance of motion on my home server. I can view the camera streams via the motion web server, arm/disarm motion detection via a simple HTTP binding in openHAB, and then call out to a python script which updates another Camera_MotionDetection item in openHAB via the REST API.

I also have another script which posts the motion snapshot to a private Slack channel so I can quickly monitor from my phone when away from home.

I am not sure there is too much to be gained by writing a dedicated binding however, since the only thing it can handle is the arm/disarm logic. Everything else is part of motion itself. It is a great piece of software tho, I would definitely recommend it.


I do exactly the same thing with motion and openhab. I had toyed with the idea of an openhab binding for Foscams, but thought it might be too specific. Plus I can already do everything via other means.

I use the HD low level protocol for Foscam, to get the video and motion triggers (you can get audio also, but it’s a pain). I built the low level protocol into a modified version of motion (plus HD motion tracking for the pan/tilt cameras), and have a python program to trap low level motion triggers. The low level protocol is much faster than using the URL interface (but it’s not published anywhere, so it’s deciphered by trial and error).

Normally you would use rtsp to get the camera image, but it has horrible lag on it, and distorts frequently. The low level protocol pulls the H.264 feed directly from the camera, with little delay, and I decode it using the ffmpeg decoder libraries (libavdecode). You can do this in motion or python, it’s pushing it to try decoding mainstream HD video at 30 fps in python though. substream video or snapshots work OK.

Is your code shared anywhere Nicholas? Sounds very interesting.

My code is kind of a mess, it’s bodged together from numerous projects, so there’s lots of left over stuff in it (and the comments sometimes don’t make sense).

My low level motion detector is here My Dropbox Stuff. This is a self contained openhab motion detection interface for HD foscams (only works on HD Foscams). Uses python 2.7 and has a command line explanation (of sorts).

This is derived from some code I found on github ages ago, and is hacked out of a monster facial recognition system I have for my Porch Foscam (which almost works - if it didn’t keep picking up shadows on the driveway as me, or car wheels as my daughter…). You can glean the low level protocol principals from it though.

I’ll zip up my motion code for you to look at as well (in the same place). You have to compile libcurl in with motion, so the Makefile is hacked to include it, as I use curl to control the pan and tilt for motion tracking. You need to include FFMPEG as well, as I use the libraries for decoding the raw H.264 feed from the camera. I added some new options to the .conf file for low level foscam protocol (because there aren’t enough already).

In python I use a small hook into libavdecoder to decode raw H.264 frames (not in the motion detector code example), which is how you get video and snapshots etc.

Let me know if you get it working, or find it useful.


1 Like

Thanks mate - I will try and have a look at some stage - I just spent some time last night bodging together a simple PHP script for pulling out a snapshot frame from the Motion MJPEG streams of my various cameras, so I can show in my openHAB sitemap. A couple of my cameras don’t have a builtin snapshot API so I wanted to build a generic method. This may well help with this task as well. Cheers.

There is a low level protocol for SD Foscams as well, it’s published though, so it’s easier to deal with.

The python H.264 decoder I use is from here pyh264decode.

Good Luck!

Hello together,

thank you all for your really quick response.

First of all i would like difference between the Foscam motion detection and the application solution like Motion or Zoneminder (Thank you, Ben Jones for this good idea!).

The advantage of the foscam feature itself is, that WiFi-Cams don’t need to send the stream all the time to a server which detects the changes in the picture.
if you count the bandwith, it’s a lot of data and much electro smog only for this traffic. I really don’t like that for this use case.

If the cameras are wired using ethernet - it’s fine for me, but i cannot have ethernet wires in every outside corner :slight_smile:

so i think a motion binding is a good idea, where we can keep focus for the future, but to be honest: I haven’t motion installed.

Back to foscam:
Currently, unfortunetly I’ve also no feature in my new firmware to call an URL when a motion is detected.

Maybe we can reach this using another way:
When motion is detected, we just store a few pictures to the FTP-Server and detect this picture upload using the Linux Inotify functions.


Every change on the file system will be anounced there and then you don’t need to poll the harddisk all the time - i think it’s a good alternative for the feature lack in the new foscams.

The other topic is, which features are needed:
Of course for me it’s the status of motion detection, but we can also add some features like pan & tilt, snapImage and so on.

There will be some differences in Firmware-Version and models, but we can solve it like watou’s proposal with a binding name below org.orpenhab.binding.foscam.XYZ
I’m also interested in a good way to Transfer an image, video or audio in a proper way to openhab without using WGET and other tools.

Great ideas right here in less than 24 hours :slight_smile:
Thank you guys!


very intressted, if you need testers :wink: count me in , i have a bunch of them

kindest regards

Excuse me, i’m an OpenHAB newbie…

is it possible to embed rtsp video in openHAB ??? How i can do this ?
my dvr has not http direct access to stream… just rtsp…


Not without something like the Foscam binding that is being discussed.

The way that I am doing it is to use the excellent Linux software “motion” which does support direct RTSP interface (I was using it on my HD Foscams, until I switched to the low level protocol). You need the latest version of “motion” the earlier ones did not support RTSP, and you need FFMPEG as well (motion uses FFMPEG libraries to decode the H.264 video stream).

Once you have motion working (it’s not as hard as it looks!), you can enable it’s MJPEG server, and your RTSP video is converted into MJPEG which can be viewed in a web page.

This is the only way to view live video in a web page. There is no other way without an “app” - like flash, or UTube - or an openhab binding. Most web browsers can view video files (mp4 for example), but that’s not the same thing as viewing live video.

Apple is promoting a way of converting live video into “chunks” of small files that are then fed to a regular web browser (an HTML5 browser like Chrome or Safari). I do this with the HD RTSP feed using FFMPEG, as I get sound etc, but it’s delayed by 20 seconds or so (ie the “chunks” are 5s or so each), I don’t watch this feed, this is what I record. So when motion detects a motion trigger, the file it starts recording is the delayed HD feed (with sound) - so you don’t miss the event that triggers the recording!

The Foscam “plugin” for your browser that allows you to view the video in IE is an “app” like flash that uses the low level protocol to display the video. It’s not using RTSP, and it’s not using your browser to display the images (any more than flash is). That’s why you don’t get anywhere near as good results using anything other than their plugin.

I posted a low level protocol version of motion earlier, and a python low level interface that uses the cameras motion detection to trigger events in openhab (camera send low level protocol code 111 on motion detection. There is a code for audio detection also).

The python script will work as is in Windows, Linux etc (just download and go - it has a command line interface). You can even get video out of it, but it’s pushing python’s limits to get HD video. I have a python script that does facial recognition (not very well).

The motion program you have to compile from the source that I posted.

I noticed in the API that you can send a request to the camera if the ALARM state has been tripped, could that be used to know when movement has been detected if you keep checking the state and then clearing the alarm after OPENHAB has read the alarm state?

What do you all think of the Foscam FI9853EP ?
If you do make a binding, will it work with it as it is a 720p h.264 model?
Also does it work with the HTTP commands as some cameras are listed but this one is not? Thanks for the link in the first post.

Sorry for all the questions about this as I am about to purchase 5 of these as I want a camera that is outdoor rated with night vision to go under the eves of our house and to be white in a dome setup. I have cat6 run to the areas of the house already so do not need wireless. If you know of a better foscam model that is still available please let me know.

I am also very interested in a native FOSCAM binding to support my newer-gen cameras. It’s a shame the latest API dropped the HTTP GET trigger support, so rather than constantly poll the camera with the following OpenHAB item:

Number Security_Office_PTZ_Motion “Motion [(%d)]” (GF_Office, Security) { http="<[http://IPADDRESS:PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD:4000:REGEX(.?(.?).*)]" }

It may work better to use an external occupancy sensor to handle motion detection, rather than push everything through another service like motion or ZoneMinder which processes each frame.


currently i’ve no time to create a bindung for this, but i’ll create a collection of items and rules to create the most important functions like deactivating and activating the motion detection.

Furthermore, i’ve created a bash-script which detects a motion and send it to openHAB. This is done by inotify-tools.
Inotify “subscribes” a record folder, and when the camera is storing a video or image, i invokes another bash-script which is doing a curl http request to openHAB’s rest service.

I would be glad to, if there’s anyone, who can assist me to set up a new binding.

I’ve also completed a short bash script, which can extract a snapshot for example every minute, and save it to the harddisk and could also upload it to an ftp server. This can also placed into the sitemap, of course.

This collection of items, rules and bash scripts is my current solution and works properly. Of course it’s not as clean as a nice binding :smile:



Hi, First time poster and long time lurker.

I was having issues with the new foscam cameras. I wanted to be able to use the video widget in the openhab ui without plugins etc. I was originally told that the H.264 cameras cannot be show live in the UI. Not true. My solution was to turn one of the streams to mjpeg and then the video widget works great. I don’t know if its a good as the HD stream but it does work flawlessly in the UI without any plugins. Maker sure the firmware is up to date and you use the mjpeg option in your sitemap item.

http://ip address:port/cgi-bin/CGIProxy.fcgi?cmd=setSubStreamFormat&format=1&usr=xxxx&pwd=xxxxx

will set the substream to mjpeg.

I have 5 foscam FI9853EP HD POE cameras that i can view in the openhab ui. Works from the internet too.
Also works in HABDroid as well.

Anyone have a good way to display the streams in the UI?? Or at least have the user pick what camera to see in the UI? Side by side? Right now I have a switch that only shows the steam when “on” using the visibility on a frame. It works great unless 2 people are logged in to openhab.


1 Like

In the very latest version I believe there is an experimental html5 viewer that works on ff and chrome. Maybe we can explore that