Skip to content

Instantly share code, notes, and snippets.

@vidvisionify
Created February 2, 2019 05:59
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vidvisionify/ed9352066a9a9d0016cdd30d7489a300 to your computer and use it in GitHub Desktop.
Save vidvisionify/ed9352066a9a9d0016cdd30d7489a300 to your computer and use it in GitHub Desktop.
Home Assistant package to download the last Ring video and better last motion sensors
# This package assumes the name of your camera is 'Front Door'. You may need to change some things if it's not.
downloader:
download_dir: www/ring
python_script:
# Put this, un-commented, in a folder named 'python_scripts' at the root of your home assistant config.
# Also create a folder named 'ring' in 'www'
# # ==== ring_download.py START ====
# # obtain ring doorbell camera object
# # replace the camera.front_door by your camera entity
# ring_cam = hass.states.get('camera.front_door')
# subdir_name = 'ring_{}'.format(ring_cam.attributes.get('friendly_name'))
# # get video URL
# data = {
# 'url': ring_cam.attributes.get('video_url'),
# 'subdir': subdir_name,
# 'filename': ring_cam.attributes.get('friendly_name')
# }
# # call downloader component to save the video
# hass.services.call('downloader', 'download_file', data)
# # ==== ring_download.py END ====
automation:
- id: ring_video_download
alias: Ring Video Download
hide_entity: true
trigger:
platform: template
value_template: '{{ is_state_attr(''sensor.ring_front_door_last_motion'',
''recording_status'', ''ready'') }}'
action:
service: downloader.download_file
data_template:
url: '{{ states.camera.front_door.attributes.video_url }}'
filename: '{{now().year}}-{{now().month}}.{{now().day}}-{{now().hour}}.{{now().minute}}.mp4'
overwrite: true
sensor:
# Counting sensors, decided not to use them.
# - platform: history_stats
# name: Front Door Motions Today
# entity_id: binary_sensor.ring_front_door_motion
# state: 'on'
# type: count
# start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
# end: '{{ now() }}'
# - platform: history_stats
# name: Front Door Dings Today
# entity_id: binary_sensor.ring_front_door_ding
# state: 'on'
# type: count
# start: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
# end: '{{ now() }}'
- platform: template
sensors:
ring_last_motion:
friendly_name: Last Motion
icon_template: mdi:walk
value_template: >-
{% set today = now().day | int %}
{% set cat_date = ((as_timestamp(states.sensor.ring_front_door_last_motion.attributes.created_at) | timestamp_custom("%d")) | int) %}
{% if today == cat_date %}
{% set day = "Today" %}
{% elif (today - 1) == cat_date %}
{% set day = "Yesterday" %}
{% elif today == 1 and cat_date > 27 %}
{% set day = "Yesterday" %}
{% else %}
{% set day = as_timestamp(states.sensor.ring_front_door_last_motion.attributes.created_at) | timestamp_custom("%A")%}
{% endif %}
{% set time = as_timestamp(states.sensor.ring_front_door_last_motion.attributes.created_at) | timestamp_custom("%l:%M %p")%}
{{[day,time]|join(" ")}}
ring_last_ding:
friendly_name: Last Ding
icon_template: mdi:bell
value_template: >-
{% set today = now().day | int %}
{% set cat_date = ((as_timestamp(states.sensor.ring_front_door_last_ding.attributes.created_at) | timestamp_custom("%d")) | int) %}
{% if today == cat_date %}
{% set day = "Today" %}
{% elif (today - 1) == cat_date %}
{% set day = "Yesterday" %}
{% elif today == 1 and cat_date > 27 %}
{% set day = "Yesterday" %}
{% else %}
{% set day = as_timestamp(states.sensor.ring_front_door_last_ding.attributes.created_at) | timestamp_custom("%A")%}
{% endif %}
{% set time = as_timestamp(states.sensor.ring_front_door_last_ding.attributes.created_at) | timestamp_custom("%l:%M %p")%}
{{[day,time]|join(" ")}}
@Monacoslo
Copy link

Hi. How can I use that in HA?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment