Camera Wyze RTSP - Snapshot/Record - Saving a local file - hassio - Proxmox VM - Having Fun with Hassio

I will be updating this “Guide” (if you can call it that) as I go. So please, bare with me.

I have discovered that instead of running motion_eye in it’s own container, chewing up valuable resources and having entirely too many front end options for my needs, I discovered the camera.snapshot and camera.record functions.

Off I went on an adventure. I went from having the camera on a generic integration, working as good as I expected, but I was wrong.

It turns out you need to use, or rather should use with your cameras (where possible) the ffmpeg integration instead of the generic ip camera integration. (it seems that the generic ip camera eats up a lot more resources then needed, causing issues, among other smaller, less important issues with this automation)

#Cameras     
  - platform: ffmpeg
    name: basementcam
    input: !secret basementfeed (rtsp feeds work here if you use the rtsp://username:[email protected]/live I just use secrets for everything I can)

The generic integration seems to throw errors, and requires the localization of the still image, which I wanted for the automation. So, once I implemented ffmpeg correctly, I discovered a brand new set of issues.

Permissions.

It seems like proxmox, or hassio, or both don’t seem to like to create files from scripts or automations locally. It’s likely something to do with how it handles the local/web addresses, locally.

I wound up with the following solution for that little 90 minute detour into madness.

(I run proxmox, so I opened the console in pve, and the direct console to the vm, while the vm was running)

I ran the following command(s) under guidance (below the whitelist), and after doing so, the automation worked as expected, prior to which I was getting constant no access to path responses from the log, even after the recommended:

  whitelist_external_dirs: "/config/tmp/"

this is my permissions fix? am I not going to like the outcome of this? I don’t know much linux but I’m pretty sure this should be fine within that container, within that bash shell.

root

login

docker exec -it homeassistant /bin/bash

sudo chmod a+rw * 

Below are my automations, and scripts. I use input_boolean to switch on and off the snapshotting, for high traffic times, or when I want, like all my 70 automations, there is always a way to disable it without too much fuss. input_boolean is great for switching on and off automations on the fly, when used with conditionals in your automations.

##Automations##

- id:
  alias: back door opens take snapshot
  description: ''
  trigger:
  - entity_id: binary_sensor.door_back
    for: '1'
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.home_automations
    state: 'on'
  - condition: state
    entity_id: input_boolean.snapshot_automation_switch
    state: 'on'
  action:
  - data: {}
    service: script.back_snapshot
- id:
  alias: When front door opens, take snapshot
  description: ''
  trigger:
  - entity_id: binary_sensor.door_front
    for: '1'
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.home_automations
    state: 'on'
  - condition: state
    entity_id: input_boolean.snapshot_automation_switch
    state: 'on'
  action:
  - data: {}
    service: script.front_snapshot
- id:
  alias: when garage door opens, take snapshot
  description: ''
  trigger:
  - entity_id: switch.garage_door
    for: '3'
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: binary_sensor.door_carport
    for: '1'
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - condition: state
    entity_id: input_boolean.home_automations
    state: 'on'
  - condition: state
    entity_id: input_boolean.snapshot_automation_switch
    state: 'on'
  action:
  - data: {}
    service: script.garage_snapshot


##Scripts##

back_snapshot:
  alias: back snapshot
  sequence:
  - data:
      duration: 5
      entity_id: camera.backcam
      filename: tmp/videos/back_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4
    service: camera.record
  - data:
      entity_id: camera.backcam
      filename: tmp/images/back_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
    service: camera.snapshot
  - timeout: '5'
    wait_template: ''
  - service: shell_command.copy_latest_photo
  - timeout: '1'
    wait_template: ''
  - service: shell_command.copy_latest_video
  - timeout: '5'
    wait_template: ''
  - data:
      message: Snapshot taken from Kitchen Door
      data:
        clickAction: "https://CustomHASSIOURL:8123/local/latest/latest_door_video.mp4"
    service: notify.notify
garage_snapshot:
  alias: garage snapshot
  sequence:
  - data:
      duration: 20
      entity_id: camera.garagecam
      filename: tmp/videos/garage_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4
    service: camera.record
  - data:
      entity_id: camera.garagecam
      filename: tmp/images/garage_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
    service: camera.snapshot
  - timeout: '5'
    wait_template: ''
  - service: shell_command.copy_latest_photo
  - timeout: '1'
    wait_template: ''
  - service: shell_command.copy_latest_video
  - timeout: '5'
    wait_template: ''
  - data:
      message: Snapshot taken from Kitchen Door
      data:
        clickAction: "https://CustomHASSIOURL:8123/local/latest/latest_door_video.mp4"
    service: notify.notify    
front_snapshot:
  alias: front snapshot
  sequence:
  - data:
      duration: 5
      entity_id: camera.frontcam
      filename: tmp/videos/front_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4
    service: camera.record
  - data_template:
      entity_id: camera.frontcam
      filename: tmp/images/front_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
    service: camera.snapshot
  - data:
      duration: 10
      entity_id: camera.kitchencam
      filename: tmp/videos/kitchen_{{ now().strftime("%Y%m%d-%H%M%S") }}.mp4
    service: camera.record
  - data:
      entity_id: camera.kitchencam
      filename: tmp/images/kitchen_{{ now().strftime("%Y%m%d-%H%M%S") }}.jpg
    service: camera.snapshot
  - timeout: '5'
    wait_template: ''
  -  service: shell_command.copy_latest_photo
  - timeout: '1'
    wait_template: ''
  - service: shell_command.copy_latest_video
  - timeout: '5'
    wait_template: ''
  - data:
      message: Snapshot taken from Kitchen Door
      data:
        clickAction:  "https://CustomHASSIOURL:8123/local/latest/latest_door_video.mp4"
    service: notify.notify

#Shell Scripts

shell_command:
  copy_latest_video: 'cp $(ls -t1 /config/tmp/videos/*.mp4|head -n1) /config/www/latest/latest_door_video.mp4'
  copy_latest_photo: 'cp $(ls -t1 /config/tmp/images/*.jpg|head -n1) /config/www/latest/latest_door_photo.jpg'

Scrub me if it’s needed, but I think I got everything. Thanks for reading!

5 Likes

I would just like to use that exact file (either moving it, renaming it to a temp name, displaying it, or just displaying that file) in the notify.notify. should be possible, that’s my next little adventure.

I have now implemented notify.notify as displaying both a dynamic message and photo of that instant. Will update the guide after testing. This seems to be a pretty special use case, but I personally love it. It has so much potential for future proofing my home. The cameras already record, locally. But I want a solution that will both allow me local notifications, as well as personal cloud storage. The next thing is to sync those snapshots and recordings to google drive, and have them available over https. Small steps.

Hi and thanks for the instructions. I feel like I am close. I get the mpf4 file which works but the jpg file is not showing an image. It does have a file size indicating that its not just empty but doesnt display. Any thoughts?

thanks

actually I renamed the jpg to have a .mp4 extension and its a video not a snapshot?

All good I managed to get it working. I needed to change the Docker Wyze Bridge snapshot mode to RTSP and used the snapshot url that is mentioned in their documentation