Foscam C1 Motion Sensor Set Up

Hello,

I’m struggling to get any motion sensor information from my Foscam C1. I have it set up to high sensitivity and ensured that no zones are blocked on the camera software.

My configs are as follows;

switch:
platform: command_line
switches:
foscamsit_motion:
command_on: ‘curl -k “http://192.168.1.157:48958/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=xxxx&pwd=xxxx”’
command_off: ‘curl -k “http://192.168.1.157:48958/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=xxxx&pwd=xxxxx”’
command_state: ‘curl -k --silent “http://192.168.1.157:48958/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=xxxx&pwd=xxxxx” | grep -q “1”’

binary_sensor:

When I paste the http details in the browser I get the following;

<CGI_Result>
0
0
1
0
0
0
0k
0k
0
0

0
0

0
</CGI_Result>

Can anybody advise where I maybe going wrong please?

Thanks in advance

Hassio doesn’t have the ability to use the standard “grep” command.

Instead you need to use the “regex_findall_index” filter.

Here is an example of a sensor with the correct command I use to poll my Foscam camera’s for motion detected:

- platform: command_line  
  command: curl -k --silent "http://192.168.1.52:8002/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxxx&pwd=yyyyyyyyyy"
  name: "Garage Camera Motion"
  value_template: >
    {% set status = value | regex_findall_index('Alarm>(\d+)</motion') %}
    {% if status == "0" %}
      Disabled
    {%- elif status == "1" -%}
      None
    {%- elif status == "2" -%}
      Detected
    {% else %}
      Not Determined
    {%- endif -%}
  scan_interval: 3

then I use the results of that sensor in my automations.

Thank you for coming back to me.

I have tried you code above to no avail.

When I browse with the http element I get;

image

Is there any other settings I need to amend or can check?

Check the home-assistant.log file located in your config directory for any errors.

How do you have hassio installed?

Hello,

I have it installed on a tinkerboard, stright in, no special setup like docker, etc.

Looked at log;

Only bit I think may refer to the camera sensor is possibly this;

File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 546, in get
return self.request(‘GET’, url, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 533, in request
resp = self.send(prep, **send_kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/sessions.py”, line 646, in send
r = adapter.send(request, **kwargs)
File “/usr/local/lib/python3.7/site-packages/requests/adapters.py”, line 498, in send
raise ConnectionError(err, request=request)
requests.exceptions.ConnectionError: (‘Connection aborted.’, OSError("(104, ‘ECONNRESET’)"))

can you SSH into the hassio container itself and try to run the command from there? maybe it’s a permission error from running the command from the container itself.

I have ssh’d in and this is the output (as per browser)

image

Never any motion triggered??

OK, so are you saying that the sensor itself is working but the camera motion sensor itself never actually gets triggered (<motionDetectAlarm> never goes to 2)?

Or that the camera motion detection itself gets triggered but the sensor never shows the state as “Detected”?

And I’m not sure which code you are using for the sensor because the code I gave you will never result in the state of “Off”. Only “Disabled”, “None”, “Detected” or “Not Determined”.

Yes, I thought that was weird.

My configuration.yaml is;

binary_sensor:

  • platform: ring
  • platform: command_line
    name: “Foscam Motion Detection”
    command: curl -k --silent “http://192.168.1.157:xxxxx/cgi-bin/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxxx&pwd=xxxxxxxx”
    value_template: >-
    {% set status = value | regex_findall_index(‘Alarm>(\d+)</motion’) %}
    {% if status == “0” %}
    Disabled
    {%- elif status == “1” -%}
    None
    {%- elif status == “2” -%}
    Detected
    {% else %}
    Not Determined
    {%- endif -%}
    scan_interval: 3

I also have a switch configured;

switches:
foscamsit_motion:
command_on: ‘curl -k “http://192.168.1.157:xxxxx/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=xxxxx&pwd=xxxxxxx”’
command_off: ‘curl -k “http://192.168.1.157:xxxxxx/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=xxxxx&pwd=xxxxxxx”’
command_state: 'curl -k --silent “http://192.168.1.157:xxxxx/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=xxxxx&pwd=xxxxxxx” | grep -q “1”

I have also loaded logger;

2019-09-21 13:28:41 DEBUG (SyncWorker_7) [homeassistant.components.command_line.sensor] Running command: curl -k --silent “http://192.168.1.157:xxxxx/cgi-bin/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=xxxxx&pwd=xxxxxxx”

2019-09-21 13:28:45 DEBUG (MainThread) [homeassistant.components.ssdp] Scanning

You need to change the type of sensor from being a “binary_sensor:” to being just a “sensor:”

ok - is this what you’d expect?

image

No.

the “None” part looks correct but for some reason the way you have it written it’s also adding the “scan_interval: 3” portion which isn’t correct.

try posting your sensor config and make sure you format it correctly just as you have it in your config code.

Looking better now, but STILL doesn’t detect motion. It never goes to 2?

image

that’s a camera configuration or hardware problem.

at least the other part is working now. :wink:

What is the result of the following command (with your details added):

curl -k --silent "http://192.168.1.53:8003/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=xxxxx&pwd=yyyyyyy"

image

I have got a second one going and the result around the URL is different;

image

Still no motion off this one either though!

that’s the output of a original command.

Run the different command that I posted above.

Oops, Sorry!

image

Those results show that even tho you have the motion detection enabled you don’t have any times scheduled for the motion detection to actually run (all of the <schedule> lines are 0).

you can change that in a couple of ways depending on what you are most comfortable with.

you can go to the camera’s web ui and select the schedule for the motion detection there. I think if I remember correctly that the schedule block needs to be red in order for it to “activated”. That confused me at first too.

Or since you seem OK with the command line and you just want to turn on the schedule for 24/7 then just run the following command with your details:

curl -k "http://192.168.1.53:8003/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&schedule0=281474976710655&schedule1=281474976710655&schedule2=281474976710655&schedule3=281474976710655&schedule4=281474976710655&schedule5=281474976710655&schedule6=281474976710655&usr=xxxxxxx&pwd=yyyyyyyyy"'

once you run that command then re-run the previous “getMotionDetectConfig” command and you should see the new schedules show up and motion detection should (hopefully) work.

Great thanks;

tried the CLI, but it came back with a >quote prompt and didn’t change the schedule.

Have now done option 1 as below;

image

Now awaiting motion to see if works.

Only oddity is that the sensitivity reverted from high back to low?