Foscam C1 Motion Detection integration

Hi guys,

I have a problem to integrate Motion Detection of my Foscam C1.

My configuration.yaml:

- platform: foscam
  name: foscam1
  ip: 10.0.X.X
  username: #######
  password: ########

It’s Ok with the entitie camera.foscam1 i see my foscam in the dashboard.

My problem is in Motion Detection integration, i use this code in a switches.yaml:

switch:
 platform: command_line
 switches:
 foscam_motion:
 command_on: 'curl -k "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=#######&pwd=#######"'
 command_off: 'curl -k "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=#######&pwd=#######"'
 command_state: 'curl -k --silent "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=#######&pwd=#######" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"'
 value_template: '{{ value == "1" }}'

It’s ok i see a new entitie switch.foscam_motion and this result in dashboard:

switch

When I click on the button, it turns blue, it launches well the request “Turned on switch.foscam_motion.
and he immediately goes back to the initial status. Off.

If I look in the webacces of the Foscam, the motion detection is activated. :face_with_raised_eyebrow:
why does not the switch stay on?

Hass.io Log Details (ERROR):

Command failed: curl -k --silent "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=#######&pwd=########" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"

when I type in a browser:

https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=#######&pwd=########

I have this feedback:

<CGI_Result>
<result>0</result>
<isEnable>0</isEnable>
<linkage>140</linkage>
<snapInterval>3</snapInterval>
<sensitivity>1</sensitivity>
<triggerInterval>10</triggerInterval>
<isMovAlarmEnable>1</isMovAlarmEnable>
<isPirAlarmEnable>1</isPirAlarmEnable>
<schedule0>0</schedule0>
<schedule1>0</schedule1>
<schedule2>0</schedule2>
<schedule3>0</schedule3>
<schedule4>0</schedule4>
<schedule5>0</schedule5>
<schedule6>0</schedule6>
<area0>0</area0>
<area1>0</area1>
<area2>0</area2>
<area3>0</area3>
<area4>0</area4>
<area5>0</area5>
<area6>0</area6>
<area7>0</area7>
<area8>0</area8>
<area9>0</area9>
</CGI_Result>

isEnable=1 if my motion is activate
isEnable=0 if my motion is disable

What’s wrong with command_state ? no keep the statut ON in the dashboard.

Thanks for help :sweat:

1 Like

Did you indent your switch config properly?

switch:
  platform: command_line
  switches:
    foscam_motion:
      command_on: 'curl -k "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=#######&pwd=#######"'
      command_off: 'curl -k "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=#######&pwd=#######"'
      command_state: 'curl -k --silent "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=#######&pwd=#######" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"'
      value_template: '{{ value == "1" }}'

Thanks dude for fast help,

Yes my indent is correct, to test, i copy / paste your code in my yaml, same error:

Command failed: curl -k --silent "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=#######&pwd=########" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"

My motion detection is started on my foscam but the switch not stay ON in dashboard. I think the command_state does not keep or check the Motion status.

Or a pb with: (?<=isEnable>).*?(?=</isEnable>)

Any idéa?

Nobody meets same problem?

Thx

Just for testing could you try this one:

switch:
  platform: command_line
  switches:
    foscam_motion:
      command_on: 'curl -k "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=#######&pwd=#######"'
      command_off: 'curl -k "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=0&usr=#######&pwd=#######"'
      command_state: 'curl -k --silent "https://10.0.X.X:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=#######&pwd=#######" | grep -q "<isEnable>1</isEnable>"'

May be you distribution/linux has a strange version of grep. I removed the “value_template” line intentionally!

3 Likes

Hi Syssi, i tested with your code, and that’s run fine :+1::ok_hand:

Big Thanks!!

Best regards…

Ps: How to mark this topic solved?