roleoroleo / yi-hack_ha_integration

Home Assistant custom integration for Yi cameras: yi-hack-MStar, yi-hack-Allwinner, yi-hack-Allwinner-v2, yi-hack-v5 and sonoff-hack

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] How save to a file "motion detection snapshot".

franciscot opened this issue · comments

Hi,

When the camera detects motion, the camera sends a picture via mqtt to HA. I can see the image in HA in the entity: camera.yi_hack_motion_detection_cam

How can I save this HA image to a file? I would like to be able to save it to disk temporarily to send it (for example with telegram service).

I can use to "take snapshot" but it is slow and duplicates the work.

Thanks a lot.

commented

I think you should use an automation trigger:
https://www.home-assistant.io/docs/automation/trigger/#mqtt-trigger
without going through the entity.

I made a "dirty" solution for HA:

My automation:

alias: motion snapshot to telegram
description: ""
trigger:
  - platform: mqtt
    topic: yicam/motion_detection_image
    encoding: ""
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: shell_command.motion_file
    data: {}
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
  - service: telegram_bot.send_photo
    data:
      file: /tmp/snapshot.jpg
      authentication: digest

And I added a shell command in configuration.yaml:

#My shell command
shell_command:
  motion_file: curl http://192.168.1.168:8123{{ state_attr('camera.yi_camera_motion_detection_image', 'entity_picture') }} --output /tmp/snapshot.jpg

I don't like but it's working.

Thanks for your great integration.