Is it possible to trigger an action if motion is detected on my IP Camera? I am connected to a Foscam C1 camera via the Generic IP Camera component (I wasn’t able to get HASS to connect to it using the Foscam component).
For example:
automation:
alias: Motion Detector
trigger:
platform: state
entity_id: camera.my_camera
from: idle
to: motion_detected
condition: use_trigger_values
action:
# Do some action...
With my foscam I can check here: http://camURLorIP:88/cgi-bin/CGIProxy.fcgi?usr=USERNAME&pwd=PASSWORD&cmd=getDevState
then I get the following response: <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>URL</url>
<upnpState>1</upnpState>
<isWifiConnected>1</isWifiConnected>
<wifiConnectedAP>WIFI</wifiConnectedAP>
<infraLedState>0</infraLedState>
</CGI_Result>
motionDetectAlarm is what you are looking for, but I think it might be easier to just watch a folder for the camera write a new picture to it. Then act on that instead of constantly polling “are you alarming now?”
Then I add other option to the URL to set the motion detection area: &area0=48&area1=48&area2=48&area3=48&area4=48
Then I set the schedule to be 24/7 so it doesn’t shut off automatically: schedule0=281474976710655&schedule1=281474976710655&schedule2=281474976710655&schedule3=281474976710655&schedule4=281474976710655&schedule5=281474976710655&schedule6=281474976710655
Then I set the snap interval, sensitivity, trigger interval: &snapInterval=3&&sensitivity=1&triggerInterval=5
Whole thing looks like this: http://camURL:88/cgi-bin/CGIProxy.fcgi?usr=USERNAME&pwd=PASSWORD&cmd=setMotionDetectConfig&isEnable=1&linkage=14&snapInterval=3&&sensitivity=1&triggerInterval=5&schedule0=281474976710655&schedule1=281474976710655&schedule2=281474976710655&schedule3=281474976710655&schedule4=281474976710655&schedule5=281474976710655&schedule6=281474976710655&area0=48&area1=48&area2=48&area3=48&area4=48
I took a different approach as I wanted to record video as well (haven’t figured out how to do that through HASS yet) and have an old Android phone that I leave plugged in and running that serves as my monitor running tinyCam. When motion is detected it emails me a screenshot and records video and using Tasker I have it trigger some automations in HASS.
I finally was able to get a binary sensor created to reflect in-camera motion detection of my FDT camera. FDT cameras are very similar to Foscam, but they don’t have a corresponding cgi command that I could use to trigger automations in Home Assistant (at least that I could find). Here are the steps in case anyone else could use them. Basically, the binary sensor is “on” when motion was detected within the past 60 seconds.
Temporarily install the “FDT View” app on your phone.
Connect to the camera on the app and under settings -> alert, select push notifications.
Add this to configuration.yaml changing CAMERAIP to your ip address:
Also, my motion trigger was too sensitive, and I couldn’t properly set the sensitivity from the webpage configuration so I used the following command. Play with the “s=xx” option to find the right sensitivity for you (0-100):