Cameras and Motion

Hi @aimc just wondering if you got anything working in regards to detecting motion and then a large video stream appearing over the top of everything for x amount of seconds?

I’d like to do something like this for the ring.com video doorbell. Basically in the way the ring.com currently works on its own app where you rather than when you detect motion, you press the doorbell and then a live view of the camera pops up over everything for say 10 seconds.

Im not the best in this field but im thinking binary sensor as the trigger to then display the camera, or even set it up as to display a certain dashboard which will have the camera stream setup in it.

I havent done much with my cameras recently, but I want to get to that eventually after the rewrite and version 3 is out.

Sounds good… i look forward to it.

@aimc

Not trying to be too pushy but… :slight_smile:

Any way you (or anybody else) could help me out with this?

Can you tell us the model number. Also can you share the configuration of how you goten to work?

All my camera’s are Foscam R2 units.

What part of my configuration do you need exactly? I’m not sure to which post of mine you replied, but I shared my motion binary_sensor on the 8th of October if you scroll up.

Finally got my older model Foscam camera working with the command line.

Here is what worked:

'curl -k --silent "http://192.168.1.XX:XXXX/get_status.cgi?user=yyyy&pwd=zzzz" | grep -oP "(?<=alarm_status=).*?(?=;)"'

This worked for me with my Escam Pearl QF100:

The motion on/off switch:

    switch:
      - platform: command_line
      switches:
        hallen_motion_switch:
          command_on: 'curl -k "http://IP:PORT/set_alarm.cgi?loginuse=user&loginpas=pass&motion_armed=1&motion_sensitivity=6&presetsit=0&mail=0&ftp_enable=0&schedule_enable=1&schedule_sun_0=-1&schedule_sun_1=-1&schedule_sun_2=-1&schedule_mon_0=-1&schedule_mon_1=-1&schedule_mon_2=-1&schedule_tue_0=-1&schedule_tue_1=-1&schedule_tue_2=-1&schedule_wed_0=-1&schedule_wed_1=-1&schedule_wed_2=-1&schedule_thu_0=-1&schedule_thu_1=-1&schedule_thu_2=-1&schedule_fri_0=-1&schedule_fri_1=-1&schedule_fri_2=-1&schedule_sat_0=-1&schedule_sat_1=-1&schedule_sat_2=-1"'
          command_off: 'curl -k "http://IP:PORT/set_alarm.cgi?loginuse=user&loginpas=pass&motion_armed=0"'
          command_state: 'curl -k --silent "http://IP:PORT/get_params.cgi?loginuse=user&loginpas=pass" | grep -oP "alarm_motion_armed=\K[0-9]+"'
          value_template: '{{ value == "1" }}'

And the motion sensor:

binary_sensor:
  - platform: command_line
    name: "Hallen motion"
    command: 'curl -k --silent "http://IP:PORT/get_status.cgi?loginuse=user&loginpas=pass" | grep -oP "alarm_status=\K[0-9]+"'
    value_template: >-
      {%- if value == "1" -%}
        motion
      {%- else -%}
        none
      {%- endif -%}
    payload_on: motion
    payload_off: none
    device_class: motion
    scan_interval: 5

I thought I would play with this before I invest in additional motion sensors. The camera I am testing on is a Foscam FI9821P and running in Hassio. I keep getting a grep error… something simple I am sure.

When I run:

curl -k --silent "http://192.168.X.X:XXXX/cgi-bin/CGIProxy.fcgi?cmd
    =getDevState&usr=XXXX&pwd=XXXX"

I get:

<CGI_Result>
    <result>0</result>
    <IOAlarm>0</IOAlarm>
    <motionDetectAlarm>0</motionDetectAlarm>
    <soundAlarm>0</soundAlarm>
    <record>0</record>
    <sdState>0</sdState>
    <sdFreeSpace>0k</sdFreeSpace>
    <sdTotalSpace>0k</sdTotalSpace>
    <ntpState>1</ntpState>
    <ddnsState>0</ddnsState>
    <url>http%3A%2F%2Fip8662.myfoscam.org%3A18808</url>
    <upnpState>0</upnpState>
    <isWifiConnected>1</isWifiConnected>
    <wifiConnectedAP>JAHA</wifiConnectedAP>
    <infraLedState>1</infraLedState>
</CGI_Result>

But when I try to add the grep described in other posts:

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

I get:

grep: unrecognized option: P
BusyBox v1.26.2 (2017-05-23 16:46:32 GMT) multi-call binary.

Usage: grep [-HhnlLoqvsriwFE] [-m N] [-A/B/C N] PATTERN/-e PATTERN.../-f FILE [FILE]...

Search for PATTERN in FILEs (or stdin)

        -H      Add 'filename:' prefix
        -h      Do not add 'filename:' prefix
        -n      Add 'line_no:' prefix
        -l      Show only names of files that match
        -L      Show only names of files that don't match
        -c      Show only count of matching lines
        -o      Show only the matching part of line
        -q      Quiet. Return 0 if PATTERN is found, 1 otherwise
        -v      Select non-matching lines
        -s      Suppress open and read errors
        -r      Recurse
        -i      Ignore case
        -w      Match whole words only
        -x      Match whole lines only
        -F      PATTERN is a literal (not regexp)
        -E      PATTERN is an extended regexp
        -m N    Match up to N times per file
        -A N    Print N lines of trailing context
        -B N    Print N lines of leading context
        -C N    Same as '-A N -B N'
        -e PTRN Pattern to match
        -f FILE Read pattern from file

I’m using this for the motion sensor on my hassio box. It seems to be more reliable to me than curl.

binary_sensor:
  - platform: rest
    name: "Foscam Motion Sensor"
    resource: http://CAMERAIP:PORT/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=USERNAME&pwd=PASSWORD
    device_class: motion
    scan_interval: 5
    value_template: >-
      {%- if "<motionDetectAlarm>2</motionDetectAlarm>" in value -%}
        {{ true }}
      {%- else -%}
        {{ false }}
      {%- endif -%}
7 Likes

This worked, I think. I have the sensor now but I am away from home and cannot force motion.

Thank you, I will play with this!

I don’t suppose you have ever done the same for Amcrest cameras? I saw the component but I have all my cameras ported through Zoneminder so I do not want to use the Amcrest component just to get motion.

The Foscam worked like a charm btw!

Unfortunately no. I don’t have any Amcrest cameras.

Hi,
Can someone explain to me how grep -oP "(?<=isEnable>).*?(?=</isEnable>)"' and value_template: '{{ value == "1" }}'" work?

I need to get the state of a PIR Sensor in a Hikvision camera who’s output looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<PIRAlarm version="1.0" xmlns="http://www.hikvision.com/ver10/XMLSchema">
<enabled>true</enabled>
<name>PIR Alarm</name>
</PIRAlarm>

The status is “true” or “false” on the 3rd line of the output

You’ll probably have to change this to grep -oP "(?<=enabled>).*?(?=</enabled>)"

There is no need to template the value of the command when the value is true or false already, so just leave this bit out.

Nop, still not working.
The state line looks now like this:

 command_state: 'curl -X GET http://user:pass@IP/ISAPI/WLAlarm/PIR | grep -oP "(?<=enabled>).*?(?=</enabled>)"' 

and the HA switch state is frozen on “OFF” state

Anyone else noticed that the Blink motion sensing isn’t working? :frowning:

Continuing the discussion from Cameras and Motion:

Hi, everybody. This is my first post, although I usually read this forum.
I’ve had the same problem and I’ve just found how I might to solve the problem.
In the recent versions, the command “grep -oP” don’t work. You must change this command to this other:

command_state: 'curl -k --silent "http://myip:88/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig&usr=myusuer&pwd=mypass" | grep -E -o "<isEnable>(.*)</isEnable>" | sed -e "s,.*<isEnable>\([^<]*\)</isEnable>.*,\1,g"`'
value_template: '{{ value == "1" }}'`

I get my switch work well. And I hope that It will be useful for you.

:blush:

Which “recent versions” are you referring to?

I found a similar problem on this topic

And I supposed that the problem that I had was the same.
When you execute the command “grep -oP” directly in the terminal SSH don`t work.