Cameras and Motion

If I had to do it again ( currently using foscam ) I would absolutely look at Blink! Wireless, BAT Powered, built in temp sensor, and HASS integration

Might even go this route regardless, can’t beat the price!

1 Like

These actually look really good. I’d want to wait until they had the outdoor cam on the list though so I can see what the price is. Could totally see using these indoors though.

A few folks have used the indoor ones outdoors, as long as they don’t get wet it says on the blink site, they are good to go! :slight_smile:

1 Like

@shep

These look promising. Do they have a battery life indicator in their API? I’d like to be proactive about replacing batteries, rather than realize “oh dang, HASS reports the camera as off, now I need to order batteries.” Battery life would be a big concern for me… and are probably the reason why I’d stay away from this vs something that is POE.

1 Like

According to the linked post, there is a separate battery level sensor for each camera

If you are happy with a DIY solution we have a thread on use of raspberry pi camera for motion detection etc Door bell with pi camera and motion detection

1 Like

Annnd this is what I’ve been looking for. Now to write an AppDaemon app for this :slight_smile:

1 Like

Hey any chance you can post your code? I have the R2 and can’t get it to work.

Here’s what I use (per R2 camera):

Switches:

- platform: command_line
  switches:
    camera_bedroom_infrared:
      command_on: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=openInfraLed&usr=YOURUSER&pwd=YOURPASSWORD"'
      command_off: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=closeInfraLed&usr=YOURUSER&pwd=YOURPASSWORD"'
      command_state: 'curl -k --silent "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=YOURUSER&pwd=YOURPASSWORD" | grep -oP "(?<=infraLedState>).*?(?=</infraLedState>)"'
      value_template: '{{ value == "1" }}'
    camera_bedroom_motion:
      command_on: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig1&isEnable=1&linkage=12&snapInterval=1&triggerInterval=10&schedule0=281474976710655&schedule1=281474976710655&schedule2=281474976710655&schedule3=281474976710655&schedule4=281474976710655&schedule5=281474976710655&schedule6=281474976710655&width1=10000&height1=10000&sensitivity1=2&valid1=1&usr=YOURUSER&pwd=YOURPASSWORD"'
      command_off: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig1&isEnable=0&usr=YOURUSER&pwd=YOURPASSWORD"'
      command_state: 'curl -k --silent "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=getMotionDetectConfig1&usr=YOURUSER&pwd=YOURPASSWORD" | grep -oP "(?<=isEnable>).*?(?=</isEnable>)"'
      value_template: '{{ value == "1" }}'

Sensors:

- platform: command_line
  name: "camera bedroom motion"
  command: 'curl -k --silent "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=YOURUSER&pwd=YOURPASSWORD" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"'
  value_template: >-
    {%- if value == "0" -%}
      Disabled
    {%- elif value == "1" -%}
      None
    {%- elif value == "2" -%}
      Detected
    {%- endif -%}
  scan_interval: 5

Shell_commands:

camera_bedroom_preset_off: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=Off&usr=YOURUSER&pwd=YOURPASSWORD"'
camera_bedroom_preset_room: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=ptzGotoPresetPoint&name=Room&usr=YOURUSER&pwd=YOURPASSWORD"'
camera_bedroom_zoom_out: 'curl -k "https://192.168.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=zoomOut&usr=YOURUSER&pwd=YOURPASSWORD"'

Scripts (only so I can show the shell_commands in the UI):

camera_bedroom_preset_off:
  sequence:
    service: shell_command.camera_bedroom_preset_off
camera_bedroom_preset_room:
  sequence:
    service: shell_command.camera_bedroom_preset_room
8 Likes

@fanaticDavid can you share your motion detection curl command i cant seem to get mine to work I keep getting:

curl -k "https://192.168.2.165/cgi-bin/CGIProxy.fcgi?cmd=setMotionDetectConfig&isEnable=1&usr=USER&pwd=PASSWORD"

<CGI_Result>
    <result>-3</result>
</CGI_Result>

all the other foscam ones work like a charm, but this on which is an R2 V3 does not

I found this at the end. Thanks this solved my issue!!!

how you do this?

Using a command_line sensor with a curl command. I shared the code in my previous post in this thread, a couple of posts up from this one.

I did recently switch from a regular command line sensor to a binary command line sensor. That sensor looks like this:

- platform: command_line
  name: "camera bedroom motion"
  command: 'curl -k --silent "https://xxx.xxx.xxx.xx:443/cgi-bin/CGIProxy.fcgi?cmd=getDevState&usr=YOURUSER&pwd=YOURPASSWORD" | grep -oP "(?<=motionDetectAlarm>).*?(?=</motionDetectAlarm>)"'
  value_template: >-
    {%- if value == "2" -%}
      motion
    {%- else -%}
      none
    {%- endif -%}
  payload_on: motion
  payload_off: none
  device_class: motion
  scan_interval: 5

device_class: motion makes it so the off state shows as clear in the UI, and on as detected. Bare in mind the actual state of the binary sensor is still off or on. And don’t forget to replace xxx.xxx.xxx.xx with the ip address of your Foscam camera, as well as YOURUSER and YOURPASSWORD with your correct credentials.

hello, I am new at this and I have a foscam too, could you tell me how can I integrate it to the home assistant thx

Awesome info!! Worked like a charm.
Just one comment in case anyone faces a similar issue:
the getDevState seems to require credentials for an Administrator role. Using an Operator won’t be enough.

1 Like

@ fanaticDavid thank you very much for sharing the curl commands. There’re other projects but the simplicity and practicality of your approach is best. All I wanted was to be able to use the motion sensor and this worked fine on my Foscam C1. I couldn’t get the switches to work but I guess this is due to camera differences. Thank you again.

1 Like

@Maxlandr

What exactly are you trying to do?

@fanaticDavid

Thanks for this!

I had my cameras sending motion detected through Blue Iris on my PC. For some reason my garage camera had a really long delay from the time motion was detected (and Blue Iris started recording) till BI sent the motion detected signal to HA. It was a delay of anywhere from 15 to 30 seconds!

The rest of my cameras (4 others) were pretty much immediate. As soon as BI started recording based on motion it sent the signal to HA. I’m not sure why that camera is so delayed. As far as I can see the config for all of them are exactly the same.

This allows me to get an almost instant response from the camera to HA (based on the polling interval…) and then turn my lights on. And if I have any issues with my Blue Iris/PC I will still have access to the camera motion status.

The Dahua Starlight 5231 IP cam is one of the best bang for the buck POE IP cameras on the market. See extensive review and discussion here: https://ipcamtalk.com/threads/dahua-starlight-varifocal-turret-ipc-hdw5231r-z.14683/

Camera-based motion detection is pretty inaccurate and ends in lots of false positives. New cameras from Hikvision and Dahua and other manufacturers include smarter motion detection with virtual tripwires, zone intrusion, etc. that is significantly more accurate.

User cor35vet on ipcamtalk wrote a small python script to monitor Dahua IVS events. See here: https://ipcamtalk.com/threads/trigger-blue-iris-with-ivs.17303/#post-1631964. I modified it to send MQTT messages so I could incorporate my cameras into HomeAssistant. See here: https://github.com/johnnyletrois/dahua-watch/blob/master/watch.py. It would be awesome if someone smarter than me would make a native component for HomeAssistant.

I use the following binary sensors to monitor the MQTT topics:

binary_sensor:
- platform: mqtt
  state_topic: "home-assistant/cameras/0/IVS"
  name: "Garage Tripwire"
- platform: mqtt
  state_topic: "home-assistant/cameras/1/IVS"
  name: "NWhouse Tripwire"
- platform: mqtt
 state_topic: "home-assistant/cameras/2/IVS"
 name: "SWhouse Tripwire"

One of my automations using the above sensors is to play a dog barking on my patio speakers and turn my office light on if the garage sensor is tripped:

- alias: Garage cam tripwire
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.garage_tripwire
    to: 'on'
  condition:
    condition: and
    conditions:
      condition: time
      after: '22:30:00'
      before: '06:00:00'
  action:
    - service: notify.ios_john_iphone_app
      data:
         message: "Garage tripwire activated"
        data:
          attachment:
            url: !secret ip_cam_garage_image_login_url
            content-type: jpeg
            hide-thumbnail: false

    - service: light.turn_on
      data:
        entity_id: light.office_ceiling_level
        brightness: 255

    - service: script.dog_bark

    - delay: '00:00:{{ (range(30, 55)|random|int) }}'

    - service: light.turn_off
      entity_id: light.office_ceiling_level
1 Like

So far I’m not seeing any false positives from my Foscam cameras. Or even the one REALLY cheap Tenvis camera that I bought several years ago.

And at double the price of my Foscams I’m not seeing the advantage of that camera for my uses.

I just want to see the live image of the camera in the visu of home assistant, I add it in the configuration. Yaml as the example that comes in the page components (foscam) but in the visu of HA it says error loading image so I don’t know what is wrong thanks for your help