motionEye

motionEye 集成允许您将您的 motionEye 服务器集成到 Home Assistant。motionEye 是一个开源的网络前端,供运动守护进程使用,用于集中管理 和可视化多种类型的摄像头。

配置

要将 motionEye integration 添加到您的 Home Assistant 实例中,请使用此 My 按钮:

手动配置步骤

如果上述 My 按钮不起作用,您也可以手动执行以下步骤:

url

motionEye 服务器的 URL 本身 – 不是 它提供的摄像头流的 URL。

admin_username

motionEye 管理帐户的用户名,用于更改摄像头设置。

admin_password

motionEye 管理帐户的密码。

surveillance_username

motionEye 监控用户的用户名,用于验证视频流。

surveillance_password

motionEye 监控帐户的密码。

选项

motionEye 的选项可以通过用户界面设置,具体步骤如下:

  • 浏览到您的 Home Assistant 实例。
  • 转到 设置 > 设备与服务
  • 如果配置了多个 motionEye 实例,请选择您想配置的实例。
  • 选择集成,然后选择 配置
配置 motionEye Webhook 以将事件报告给 Home Assistant

是否应配置 motionEye Webhook 以回调到 Home Assistant。如果此选项被禁用,将不会生成运动检测或文件存储事件,除非手动配置 Webhook。

覆盖未识别的 Webhook

是否覆盖已经配置但未被识别为属于此集成的 Webhook(如果 Webhook 的查询字符串中包含 src=hass-motioneye,则认为它们属于此集成)。

流 URL 模板

一个 jinja2 模板,用于覆盖标准 MJPEG 流 URL(例如,用于反向代理)。请参见下面的 Camera MJPEG Streams。该选项仅显示给启用了 高级模式 的用户。

使用方法

实体

平台 描述
camera 显示 motionEye 视频流的 MJPEG 摄像头。
switch 开关实体,用于启用/禁用运动检测、文本叠加、视频流、静态图像捕获、电影捕获和上传。
sensor 一个“动作传感器”,显示此设备配置的 动作 的数量。可用动作的名称可以在传感器实体的 actions 属性中查看。

注意:

  • 如果视频流开关被关闭,摄像头实体和对该摄像头操作的动作将变得不可用。其余的集成将继续运行。
  • 因为摄像头被添加或移除到 motionEye,设备/实体将自动添加或移除到 Home Assistant。

摄像头 MJPEG 流

为了使 MJPEG 流功能正常,它们需要在 <motioneyehost>:<streaming port> 上可访问,即 Home Assistant 将直接连接到配置在 motionEye UI 中的流端口(在主机上配置的“视频流”下)。

示例:

  • 如果此集成配置为在 http://motioneye:8765 与 motionEye 通信,并且 摄像头配置为在端口 8081 上流,则 Home Assistant 需要能够 与 motioneye 端口 8081 通信。
流 URL 模板

对于高级用例,可以通过 流 URL 模板 选项更改此行为。设置后,此字符串将覆盖默认的流地址,该地址源于上面描述的默认行为。此选项支持 jinja2 模板,并包含来自 motionEye 的 camera 字典变量 (示例) 可用于模板。请注意,模板中不提供任何 Home Assistant 状态,仅提供来自 motionEye 的摄像头字典。

当 motionEye 位于自定义配置的反向代理后面时,这非常有用, 和/或当流端口在其他情况下无法访问 Home Assistant(例如防火墙规则)。

流 URL 模板示例

以下是此选项可能设置的有用示例。

在流 URL 中使用摄像头名称

http://motioneye/video/{{ name }}

在流 URL 中使用摄像头名称,先将其转换为小写

http://motioneye/video/{{ name|lower }}

在流 URL 中使用摄像头 ID

http://motioneye/video/{{ id }}

事件

收到运动或文件存储回调时,将触发事件,可用于 自动化等。

事件中的数据

  • 事件数据包括此 motionEye 摄像头设备的 Home Assistant device_id 和 Home Assistant 设备 name
  • 事件数据还包括与该事件类型相对应的尽可能多的 运动转换说明符
  • 任何手动添加到 motionEye webhook 的 &key=value 对(在 motionEye UI 中)将自动传播到事件数据。如果您手动调整 Webhook,删除 src=hass-motioneye 参数,否则 Webhook 将被覆盖。
  • 对于文件存储事件,集成将自动添加 media_content_id(可用于在 Home Assistant 媒体播放器中播放媒体的标识符)和 file_url(媒体的原始 URL)。请参见下面的 示例自动化,以说明如何使用它。
  • 如果存储的媒体是图像,则 file_type 将小于 8,否则为电影/视频。有关更多详细信息,请参阅 运动源

示例运动检测事件

{
    "event_type": "motioneye.motion_detected",
    "data": {
        "device_id": "662aa1c77657dbc4af836abcdf80000a",
        "name": "办公室",
        "camera_id": "2",
        "changed_pixels": "99354",
        "despeckle_labels": "55",
        "event": "02",
        "fps": "24",
        "frame_number": "10",
        "height": "1080",
        "host": "6aa7a495490c",
        "motion_center_x": "314",
        "motion_center_y": "565",
        "motion_height": "730",
        "motion_version": "4.2.2",
        "motion_width": "252",
        "noise_level": "12",
        "threshold": "20736",
        "width": "1920"
    },
    "origin": "LOCAL",
    "time_fired": "2021-04-11T04:25:41.106964+00:00",
    "context": {
        "id": "0320bb897aa3656dbb02affddce322f2",
        "parent_id": null,
        "user_id": null
    }
}

示例文件存储事件

{
    "event_type": "motioneye.file_stored",
    "data": {
        "device_id": "662aa1c77657dbc4af836abcdf80000a",
        "name": "办公室",
        "camera_id": "2",
        "event": "03",
        "file_path": "/var/lib/motioneye/Camera2/2021-04-10/21-27-53.mp4",
        "file_type": "8",
        "media_content_id": "media-source://motioneye/74565ad414754616000674c87bdc876c#662aa1c77657dbc4af836abcdf80000a#movies#/2021-04-10/21-27-53.mp4",
        "file_url": "https://cctv/movie/2/playback/2021-04-10/21-27-53.mp4?_username=admin&_signature=bc4565fe414754616000674c87bdcacbd",
        "fps": "25",
        "frame_number": "21",
        "height": "1080",
        "host": "6aa7a495490c",
        "motion_version": "4.2.2",
        "noise_level": "12",
        "threshold": "20736",
        "width": "1920"
    },
    "origin": "LOCAL",
    "time_fired": "2021-04-11T04:27:54.528671+00:00",
    "context": {
        "id": "0358cac9457e3e3a2039da8c998e4c25",
        "parent_id": null,
        "user_id": null
    }
}

动作

所有动作接受 entity_iddevice_id

motioneye.snapshot

触发摄像头快照(例如,将图像保存到磁盘)。

参数:

参数 描述
entity_id device_id 用于触发快照的实体 ID 或设备 ID。

注意:这是对 motioneye.action 调用 的一个薄包装。

motioneye.action

触发 motionEye 动作(请参见 motionEye 动作按钮)。

参数:

参数 描述
entity_id device_id 用于触发该动作的实体 ID 或设备 ID。
action 一个字符串,表示要触发的 motionEye 动作。可以是 snapshotlockunlocklight_onlight_offalarm_onalarm_offuprightdownleftzoom_inzoom_outpreset1preset9record_startrecord_stop

注意record_startrecord_stop 动作在 motionEye 自身中仅部分实现,因此在此时未按预期功能运行 (相关代码)。

motioneye.set_text_overlay

设置摄像头的文本叠加。

参数:

参数 描述
entity_id device_id 用于设置文本叠加的实体 ID 或设备 ID。
left_text right_text 之一为 timestampcamera-namecustom-textdisabled,用于在左侧或右侧显示时间戳、摄像头名称、自定义文本或什么都不显示。
custom_left_text custom_right_text 自定义文本,如果选择了 custom-text 值,则显示在左侧或右侧。

注意

  • 调用此动作会重置 motionEye 摄像头,这将暂停 流/录音/运动检测等。
  • 确保 文本叠加 开关已打开,以实际显示配置的文本叠加。

示例:

action: motioneye.set_text_overlay
data:
  left_text: timestamp
  right_text: custom-text
  custom_right_text: "报警已启动"
target:
  entity_id: camera.office

媒体浏览

保存的 motionEye 媒体(电影和图像)可以在 Home Assistant 的“媒体浏览器”中原生浏览。

手动配置的根目录

尽管此集成允许对每个摄像头单独深入媒体, 但在 motionEye 下面是使用目录结构将媒体项目与每个 单独摄像头关联。因此,如果多个摄像头手动配置为共享相同 的根目录,当查询任何一个“重叠”的摄像头时,motionEye 将返回媒体项目的 组合。使用不同的根目录(在 motionEye 中: 文件存储 -> 根目录)来确保 motionEye(因此此集成)能 正确将媒体与捕获该媒体的摄像头关联。

示例仪表板卡

一个带图标的仪表板卡,可以调用 action 动作来发送动作命令到 motionEye。

- type: picture-glance
  title: "客厅"
  camera_image: camera.living_room
  camera_view: live
  entities:
      - entity: camera.living_room
      - entity: camera.living_room
        icon: "mdi:arrow-left"
        tap_action:
          action: perform-action
          perform_action: motioneye.action
          data:
            action: left
            entity_id: camera.living_room
      - entity: camera.living_room
        icon: "mdi:arrow-right"
        tap_action:
          action: perform-action
          perform_action: motioneye.action
          data:
            action: right
            entity_id: camera.living_room
      - entity: camera.living_room
        icon: "mdi:arrow-up"
        tap_action:
          action: perform-action
          perform_action: motioneye.action
          data:
            action: up
            entity_id: camera.living_room
      - entity: camera.living_room
        icon: "mdi:arrow-down"
        tap_action:
          action: perform-action
          perform_action: motioneye.action
          data:
            action: down
            entity_id: camera.living_room

示例自动化

当报警被激活时设置文本叠加

一个简单的自动化设置文本叠加,以指示报警的激活状态。文本叠加 必须开启,才能使此自动化有效(可通过 switch.<name>_text_overlay 控制)。

- alias: "将摄像头文本叠加设置为已激活"
  triggers:
    - trigger: state
      entity_id: alarm_control_panel.home_alarm
      to: "armed_away"
  actions:
    - action: motioneye.set_text_overlay
      target:
        entity_id: camera.living_room
      data:
        left_text: custom-text
        custom_left_text: "报警已激活"

- alias: "将摄像头文本叠加设置为已解除"
  triggers:
    - trigger: state
      entity_id: alarm_control_panel.home_alarm
      to: "disarmed"
  actions:
    - action: motioneye.set_text_overlay
      target:
        entity_id: camera.living_room
      data:
        left_text: custom-text
        custom_left_text: "报警已解除"

自动播放存储的电影

一个自动化,将存储的电影片段投放到电视上,随着它们到达。

- alias: "播放 motionEye 电影片段"
  triggers:
    - trigger: event
      event_type: motioneye.file_stored
      event_data:
        # 仅播放视频。
        file_type: "8"
  actions:
    - action: media_player.play_media
      target:
        entity_id: media_player.kitchen_tv
      data:
        media_content_id: ""
        media_content_type: video

调试

调试日志

要为集成和底层客户端库启用调试日志,请在您的 configuration.yamlconfiguration.yaml 文件是 Home Assistant 的主要配置文件。它列出了要加载的集成及其特定配置。在某些情况下,需要直接在 configuration.yaml 文件中手动编辑配置。大多数集成可以在 UI 中配置。 [Learn more] 中启用以下内容,然后重新启动:

logger:
  default: warning
  logs:
    motioneye_client: debug
    homeassistant.components.motioneye: debug