I just bought a Foscam cam and added to HA using Foscam Integrations. I can control PTZ but there’s no evidence of the switch and sensor to activate-deactivate motion or sound detection.
I’ve found older post (this and this) and tried to make a collage but without full success. Instead of necroposting I preferred open a new one to collect all the info.
Till now I accomplished to have a motion switch using this code:
I tried to use same logic for the motion sensor but it stays always on none or disabled (never change to detected even if I receive notification via Foscam App:
sensor:
- platform: command_line
command: curl -k --silent "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=Foscam1&pwd=xxxxxxxx"
name: "Foscam 1 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
Just to add all the info this is what I see when using the following link in a web browser:
I added the specific sensor to the history stats and I see now the change state.
Sorry…
For the record I made to have also sound and switch for audio. Below the code for future users:
sensor:
- platform: command_line
command: curl -k --silent "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=Foscam1&pwd=xxxxxxx"
name: "Foscam 1 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
- platform: command_line
command: curl -k --silent "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=Foscam1&pwd=xxxxxx"
name: "Foscam 1 Sound"
value_template: >
{% set status = value | regex_findall_index('Alarm>(\d+)</sound') %}
{% if status == "0" %}
Disabled
{%- elif status == "1" -%}
None
{%- elif status == "2" -%}
Detected
{% else %}
Not Determined
{%- endif -%}
scan_interval: 3
switch:
- platform: command_line
switches:
foscam1_motion:
friendly_name : "Foscam 1 Motion"
# command_on: 'curl -k "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxxxxxx&cmd=setMotionDetectConfig&isEnable=1&linkage=15&snapInterval=1&sensitivity=1&triggerInterval=0&schedule0=281474976710655&schedule1=281474976710655&schedule2=281474976710655&schedule3=281474976710655&schedule4=281474976710655&schedule5=281474976710655&schedule6=281474976710655&area0=1023&area1=1023&area2=1023&area3=1023&area4=1023&area5=783&area6=527&area7=775&area8=771&area9=768"'
command_on: 'curl -k "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxxxx&cmd=setMotionDetectConfig&isEnable=1"'
command_off: 'curl -k "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxx&cmd=setMotionDetectConfig&isEnable=0"'
command_state: 'curl -k --silent "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxxxx&cmd=getMotionDetectConfig" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"'
value_template: '{{ value == "1" }}'
- platform: command_line
switches:
foscam1_sound:
friendly_name : "Foscam 1 Sound"
command_on: 'curl -k "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxxxxxxxx&cmd=setAudioAlarmConfig&isEnable=1"'
command_off: 'curl -k "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxxxxxxx&cmd=setAudioAlarmConfig&isEnable=0"'
command_state: 'curl -k --silent "http://192.168.2.114:88/cgi-bin/CGIProxy.fcgi?usr=Foscam1&pwd=xxxxxx&cmd=getAudioAlarmConfig" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"'
value_template: '{{ value == "1" }}'
I take advantage of your kindness to ask you support for the other point.
I’m trying to add a switch to load 2 different preset 1) AtHome 2) AtWatch. At this moment I have command for on and off but how can I see the current preset (if any)?
value_template: >
{% set status = value | regex_findall_index('enable>(\d+)</enable') %}
{% if status == "0" %}
Disabled
{%- elif status == "1" -%}
Enabled
{% else %}
Not Determined
{%- endif -%}
or if that doesn’t work it should if you replace the above with:
value_template: >
{% set status = value | regex_findall_index('enable>(\d+)</enable') %}
{% set values = {'0':'Disabled', '1':'Enabled'} %}
{{ values[status] if status in values.keys() else 'Not Determined'}}