使用旧 Foscam FI8909W 摄像头进行Home Assistant运动检测等

也许您还有一台旧的 foscam 相机放在周围并收集灰尘? 您实际上不必破坏您的银行帐户来购买那些花哨的“安全摄像头”,以享受移动检测和家庭助理的更高级功能。 在本文中,我将向您展示如何重新使用这些旧相机进行运动检测和更高级的Home Assistant任务,让您的生活更轻松!

1. Foscam FI8909W基本介绍

Foscam FI8909W

大约 10 年前,我购买了 2 台 Foscam FI8909W,当时 RTSP 安全摄像头还非常罕见。 这些 Foscam 无线摄像机具有 640X480 分辨率和通过 Web GUI 提供的基本功能。 不幸的是,它的固件几年前就停止了更新,因此对Home Assistant的支持非常有限。 人们通过Home Assistant中的通用相机或 MJPEG 相机将它们集成在一起。

为了确保摄像头访问的安全,我强烈建议通过 Web GUI 设置用户名/密码,并在“警报服务设置”下启用“运动检测”。 其他设置可以根据自己的喜好进行配置。 foscam alarm setting

Foscam FI8909W 的有用 CGI 命令

与Home Assistant集成时,这些命令将非常有用

检索当前相机状态

http://192.168.x.x/get_status.cgi?user=admin&pwd=123456

Output:

 1var id='000DC5DBFB8E';
 2var sys_ver='11.40.2.46';
 3var app_ver='2.4.91.17';
 4var alias='FrontCam';
 5var now=1664303995;
 6var tz=28800;
 7var alarm_status=0;
 8var ddns_status=0;
 9var ddns_host='';
10var oray_type=0;
11var upnp_status=5;
12var p2p_status=0;
13var p2p_local_port=23321;
14var msn_status=0;
15var wifi_status=1;

获取当前视频流

http://192.168.x.x/videostream.cgi?user=admin&pwd=123456

这将输出一个实时的 MJPEG 流

2. 准备集成Home Assistant运动检测

首先,我们需要创建一个命令行binary sensor。

1- platform: command_line
2  name: "Front Camera Motion"
3  device_class: motion
4  command: 'curl -k --silent "http://192.168.x.x/get_status.cgi?user=admin&pwd=123456" | grep alarm | cut -b 18'
5  payload_on: "1"
6  payload_off: "0"
7  scan_interval: 3

将上述内容添加到您的 configuration.yaml 将创建一个来自相机的运动传感器。 该运动传感器利用 foscam 提供的内置警报服务。 这种方法容易发生光线变化,因此不是 100% 准确的。

对于高级使用,建议对本地处理的 AI 检测对象使用 Frigate,以减少误报。 在 Frigate 中添加相机后,会自动生成一些运动传感器。

3. Foscam motion sensor应用

现在无论有没有 Frigate,我们都将旧的 Foscam 摄像头变成了支持运动检测的安全摄像头。 当在目标区域检测到运动时,我们可以创建自动化来触发各种动作。

我在我的门廊里放了一个 foscam 摄像头,还有两个 wifi 智能灯泡。 我最喜欢的自动化之一是在检测到运动时将我的前门廊灯亮到 100% 亮度,并在清除运动后将灯变暗到 15% 亮度以节省能源。 请注意,添加了“sun.below_horizon”条件以在白天不触发自动化。

自动化 YAML 如下:

 1alias: Bright up porch light on motion
 2trigger:
 3  - platform: state
 4    entity_id:
 5      - binary_sensor.front_camera_motion
 6    to: "on"
 7condition:
 8  - condition: state
 9    entity_id: sun.sun
10    state: below_horizon
11action:
12  - service: light.turn_on
13    data:
14      brightness_pct: 100
15    target:
16      entity_id:
17        - light.smart_lighting_tunable_white_and_color
18        - light.smart_lighting_tunable_white_and_color_2
19mode: single
20
 1alias: Darken porch light when no motion
 2trigger:
 3  - platform: state
 4    entity_id:
 5      - binary_sensor.front_camera_motion
 6    to: "off"
 7    for:
 8      hours: 0
 9      minutes: 1
10      seconds: 0
11condition:
12  - condition: state
13    entity_id: sun.sun
14    state: below_horizon
15action:
16  - service: light.turn_on
17    data:
18      brightness_pct: 15
19    target:
20      entity_id:
21        - light.smart_lighting_tunable_white_and_color_2
22        - light.smart_lighting_tunable_white_and_color
23mode: single
24
comments powered by Disqus

翻译: