Foscam Questions

I’m considering buying Foscam outdoor cameras and am trying to determine if there is a way to detect motion on the cameras and have the feed be recorded to the PC (Windows) running Hass. Is this even possible?

This is possible using the out-of-the-box functionality of the camera. Why do you want to go through HASS to do this?

I’d like to use the motion triggers to start automations (i.e. turn on lights, play audio).

I use the motion sensor of my Foscam to trigger ftp-uploads to the same Pi3 I’m running HA on.

I think there should be a way to use the folder sensor (https://home-assistant.io/components/sensor.folder/) to recognize if new files have been uplaoded to trigger some actions from it.

Just a guess, haven’t tried anything yet.

I use the following to pull the motion detected signal from my camera:

- platform: command_line
  name: "Livingroom Camera Motion"
  command: 'curl -k --silent "http://192.168.1.xx:xxxx/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxx&pwd=xxxxxxxx" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"'
  value_template: >-
    {%- if value == "0" -%}
      Disabled
    {%- elif value == "1" -%}
      None
    {%- elif value == "2" -%}
      Detected
    {%- endif -%}
  scan_interval: 3 
  friendly_name: 'Livingroom'

you may have to adjust the cgi command based by your camera requirements tho.

and of course you need to enable motion detection in your camera interface.

and for the video feed just follow the docs for the Foscam component.

- platform: foscam
    ip: 192.168.1.xx
    username: !secret cam_user
    password: !secret cam_pw
    port: xxxx
    name: Dining Room

in the foscam cams you can setup where to save the feeds. (almost everything is possible there)
i use my own FTP server, but you can use other ways too.

it is possible to detect motion. the cam uses it to start saving video or take pics.
with CGI commands you can check if motion detection is active.

the problem with using a cams motion detection to set up automations:

  1. you need to send a CGI command very regularly over your network, but still you only will get it with the speed that you have set, for example every 10 secs checking will make that your automation can start 10 secs after you have checked the last time.
  2. the cam will be kept busy all the time and it will also be busy saving video and pics. at some points its just to busy to answer to your cgi commands. making the sensor even more unreliable.

i dont think that its just something from foscam, but in general. motion sensors from cams are for the cam, and dont send a signal as soon as motion is detected.

i know there are some that send alarm to an app, but i dont know of any that are integrated in HA (but then again i didnt look anymore because i use foscam for over a year now)

I’ve tried your piece of code (the command) with the correct information and it returns an “unknown” answer. Yet, I can see that it’s obviously 1 when I type the URL into a browser. Any ideas?

What happens if you type the entire command using a terminal?

Stupid question, but how would I do this, as I am on Windows?

well…I’m not really sure what the equivalent command line would be in windows. Which is strange because I’ve been a windows user for A LOT longer than I have been a Linux user.

I’ve never needed to learn how to extract any data that was returned from a command.

I’ll have to do some research.

But…that’s what you are basically doing by the command above. you are asking for the status of the data in the camera, then parsing out the returned data with the grep command to pick out one data point from the table using the search terms you provided.

if you figure it out before i do be sure to let me know.

After some research, I’ve discovered Curl and Grep libraries you can use with Windows and they work perfectly.

great!

so what is the output of that command using those libraries?

Turns out that installing those libraries fixed the problem all together!

awesome! even better! :grinning:

Hi, I was hoping you could help me out on this, I’ve been trying to get this to work in Hassio, but am having no luck. When I use this command in Hassio SSH, I get the following error “grep: unrecognized option: P”. When I remove the P option from grep (and also the --silent from curl, so I can see the response), I get 100% , Received 525, blah blah blah, which I assume means the command went through and it received data back from the camera. But then when I added it into my config, I get the following error:
2019-07-22 20:28:24 ERROR (SyncWorker_10) [homeassistant.components.command_line.sensor] Command failed: curl -k “http://192.168.0.xx:89/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxxx&pwd=xxxxxxxx” | grep -o “(?<=motionDetectAlarm>).*?(?=)”

This is where I am stuck and looking for assistance. Thanks

Make sure you finish off the command. It looks like you forgot the last string.

curl -k --silent "http://192.168.1.xx:xxxx/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxx&pwd=xxxxxxxx" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)

You can also look at this website to see as to why the -oP is highly important.

Thanks for the feedback. I did use the complete command as you shown, just with the grep -o and dropped the “P” option as mentioned. Typing the command directly in HASSIO terminal command line actually fails with that option. But I did manage to get this to work without it. Thanks again for your response.