############################################################################### # @author : Mahasri Kalavala # @date : 07/16/2017 # @package : Cameras # @description : Cameras and the automations # @Comment : USE AT YOUR RISK!!! I CAN'T GUARANTEE IF IT DOESN'T # WORK IN YOUR ENVIRONMENT! ############################################################################### homeassistant: # # The camera url format in secrets.yaml would look like this: # frontdoor_camera_url: http://username:password@192.168.xxx.xxx/ISAPI/Streaming/channels/101/picture # camera: - platform: generic name: Frontdoor Camera still_image_url: !secret frontdoor_camera_url verify_ssl: false authentication: digest username: !secret camera_username password: !secret camera_password - platform: generic name: Driveway Camera still_image_url: !secret driveway_camera_url verify_ssl: false authentication: digest username: !secret camera_username password: !secret camera_password - platform: generic name: Patio Camera still_image_url: !secret patio_camera_url verify_ssl: false authentication: digest username: !secret camera_username password: !secret camera_password - platform: generic name: Playarea Camera still_image_url: !secret playarea_camera_url verify_ssl: false authentication: digest username: !secret camera_username password: !secret camera_password - platform: generic name: Porch Camera still_image_url: !secret porch_camera_url stream_source: porch_camera_rtsp_url verify_ssl: false authentication: basic username: !secret porch_camera_username password: !secret porch_camera_password # - platform: ffmpeg # input: porch_camera_rtsp_url # name: Porch Camera # - platform: mjpeg # mjpeg_url: !secret garage_camera_url # name: Garage Camera # add amcrest cameras - platform: amcrest - platform: local_file name: Frontdoor Latest Scan file_path: "/config/www/downloads/camera/frontdoor/frontdoor_latest.jpg" - platform: local_file name: Driveway Latest Scan file_path: "/config/www/downloads/camera/driveway/driveway_latest.jpg" - platform: local_file name: Patio Latest Scan file_path: "/config/www/downloads/camera/patio/patio_latest.jpg" - platform: local_file name: Playarea Latest Scan file_path: "/config/www/downloads/camera/playarea/playarea_latest.jpg" - platform: local_file name: Garage Latest Scan file_path: "/config/www/downloads/camera/garage/garage_latest.jpg" - platform: local_file name: 3dPrinter Latest Scan file_path: "/config/www/downloads/camera/3d/3d_latest.jpg" - platform: local_file name: Porch Latest Scan file_path: "/config/www/downloads/camera/porch/porch_latest.jpg" shell_command: reset_camera_stream: !secret camera_stream_restart_docker_url # Amcrest Camera Model IP8M-T2669EW-AI amcrest: - host: !secret amcrest_front_camera_ip username: !secret amcrest_front_camera_username password: !secret amcrest_front_camera_password binary_sensors: - motion_detected - crossline_detected - online switch: - platform: rest resource: !secret camera_stream_docker_url name: Camera Stream body_on: '{"state": "start"}' body_off: '{"state": "stop"}' is_on_template: '{{ value_json is not none and value_json.state == "running" }}' binary_sensor: - platform: hikvision name: Frontdoor Camera ssl: false host: !secret frontdoor_camera_ip username: !secret camera_username password: !secret camera_password - platform: hikvision name: Driveway Camera ssl: false host: !secret driveway_camera_ip username: !secret camera_username password: !secret camera_password - platform: hikvision name: Patio Camera ssl: false host: !secret patio_camera_ip username: !secret camera_username password: !secret camera_password - platform: hikvision name: Playarea Camera ssl: false host: !secret playarea_camera_ip username: !secret camera_username password: !secret camera_password - platform: mqtt state_topic: "myhome/dafang_1/motion" name: "Porch Motion" device_class: motion payload_on: "ON" payload_off: "OFF" value_template: "{{ value }}" # image_processing: # - platform: tensorflow # scan_interval: 10000 # source: # - entity_id: camera.frontdoor_camera # - entity_id: camera.driveway_camera # - entity_id: camera.patio_camera # - entity_id: camera.playarea_camera # - entity_id: camera.garage_camera # - entity_id: camera.3d_printer_camera # - entity_id: camera.porch_camera # file_out: # - "/config/www/downloads/camera/{{- camera_entity.split('.')[1].split('_')[0] -}}/{{ camera_entity.split('.')[1].split('_')[0] }}_latest.jpg" # - "/config/www/downloads/camera/{{- camera_entity.split('.')[1].split('_')[0] -}}/{{ camera_entity.split('.')[1].split('_')[0] }}_{{ now().strftime('%Y%m%d_%H%M%S') }}.jpg" # model: # graph: /config/tensorflow/models/efficientdet_d0_coco17_tpu-32/ image_processing: - platform: doods scan_interval: 10000 url: !secret doods_server_url detector: tensorflow source: - entity_id: camera.frontdoor_camera - entity_id: camera.driveway_camera - entity_id: camera.patio_camera - entity_id: camera.playarea_camera - entity_id: camera.garage - entity_id: camera.3d_printer_camera - entity_id: camera.porch_camera file_out: - "/config/www/downloads/camera/{{- camera_entity.split('.')[1].split('_')[0] -}}/{{ camera_entity.split('.')[1].split('_')[0] }}_latest.jpg" - "/config/www/downloads/camera/{{- camera_entity.split('.')[1].split('_')[0] -}}/{{ camera_entity.split('.')[1].split('_')[0] }}_{{ now().strftime('%Y%m%d_%H%M%S') }}.jpg" labels: - name: person confidence: 75 - name: car confidence: 90 - name: truck confidence: 90 input_label: current_stream: name: Current Stream # frontdoor_camera_text_overlay_url: http://192.168.xxx.xxx/Video/inputs/channels/1/overlays/text/1 rest_command: set_frontdoor_camera_text_left_bottom: url: !secret frontdoor_camera_text_overlay_url username: !secret camera_username password: !secret camera_password method: PUT content_type: "text/xml" payload: >- 1true 45520 {{ message }} set_driveway_camera_text_left_bottom: url: !secret driveway_camera_text_overlay_url username: !secret camera_username password: !secret camera_password method: PUT content_type: "text/xml" payload: >- 1true 45520 {{ message }} set_patio_camera_text_left_bottom: url: !secret patio_camera_text_overlay_url username: !secret camera_username password: !secret camera_password method: PUT content_type: "text/xml" payload: >- 1true 45520 {{ message }} set_playarea_camera_text_left_bottom: url: !secret playarea_camera_text_overlay_url username: !secret camera_username password: !secret camera_password method: PUT content_type: "text/xml" payload: >- 1true 45520 {{ message }} ############################################################################### # _ _ _ # /\ | | | | (_) # / \ _ _| |_ ___ _ __ ___ __ _| |_ _ ___ _ __ ___ # / /\ \| | | | __/ _ \| '_ ` _ \ / _` | __| |/ _ \| '_ \/ __| # / ____ \ |_| | || (_) | | | | | | (_| | |_| | (_) | | | \__ \ # /_/ \_\__,_|\__\___/|_| |_| |_|\__,_|\__|_|\___/|_| |_|___/ # ############################################################################### automation: - alias: Scan Porch Camera On Motion initial_state: true trigger: - platform: state entity_id: binary_sensor.porch_motion from: "off" to: "on" action: - service: camera.snapshot data: entity_id: "camera.porch_camera" filename: "{{ '/config/www/downloads/camera/porch/porch_' ~ (states.binary_sensor.porch_motion.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: image_processing.scan data: entity_id: image_processing.doods_porch_camera # # Scan front door and driveway cameras when motion detected # if the garage doors are open, scan garage cameras as well # - alias: Scan Frontdoor Camera On Motion initial_state: true trigger: - platform: state entity_id: - binary_sensor.motion_sensor_158d00024ee084 to: "on" action: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - service: script.frontdoor_cam # change to front door camera stream on chromecast - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" - service: image_processing.scan data: entity_id: image_processing.doods_frontdoor_camera - service: image_processing.scan data: entity_id: image_processing.doods_driveway_camera - condition: template value_template: >- {% if state_attr('image_processing.doods_frontdoor_camera', 'summary') != None %} {% if state_attr('image_processing.doods_frontdoor_camera', 'summary') |count > 0 %} true {% else %} false {% endif %} {% else %} false {% endif %} - service: script.voice_notify data: message: >- {%- set e_id = "image_processing.doods_frontdoor_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the front yard." }} {%- endif -%} greeting: "no" - service: notify.notify_smtp data: title: 'Front door motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: > {%- set e_id = "image_processing.doods_frontdoor_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the front yard on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected at the front door on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} data: images: - "/config/www/downloads/camera/frontdoor/frontdoor_latest.jpg" - service: script.notify_family data: title: "Front Door Motion" message: > {%- set e_id = "image_processing.doods_frontdoor_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the front yard on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected at the front door on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif %} url: "/config/www/downloads/camera/frontdoor/frontdoor_latest.jpg" notify_options: - telegram - tv - condition: template value_template: > {% if states('binary_sensor.door_window_sensor_158d0004248d5b') == "on" or states('binary_sensor.door_window_sensor_158d0004231f7b') == "on" %} True {% else %} False {% endif %} - service: image_processing.scan data: entity_id: image_processing.doods_garage # # Scan driveway and frontdoor cameras when motion detected # if the garage doors are open, scan garage cameras as well # - alias: Scan Driveway Camera When Motion initial_state: true trigger: - platform: state entity_id: - binary_sensor.motion_sensor_158d00024e57fb to: "on" action: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - service: script.stream2chromecast data: url: !secret driveway_camera_stream_url name: "driveway" - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" - service: image_processing.scan data: entity_id: image_processing.doods_driveway_camera - service: image_processing.scan data: entity_id: image_processing.doods_frontdoor_camera - condition: template value_template: >- {% if state_attr('image_processing.doods_driveway_camera', 'summary') != None %} {% if state_attr('image_processing.doods_driveway_camera', 'summary') |count > 0 %} true {% else %} false {% endif %} {% else %} false {% endif %} - service: script.voice_notify data: message: >- {%- set e_id = "image_processing.doods_driveway_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the driveway" }} {%- endif -%} - service: script.notify_family data: title: "Driveway Motion" message: > {%- set e_id = "image_processing.doods_driveway_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the driveway on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected at the driveway on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} url: "/config/www/downloads/camera/driveway/driveway_latest.jpg" notify_options: - telegram - tv - service: notify.notify_smtp data: title: 'Driveway motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: > {%- set e_id = "image_processing.doods_driveway_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the driveway on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected at the driveway on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} data: images: - "/config/www/downloads/camera/driveway/driveway_latest.jpg" - condition: template value_template: > {% if states('binary_sensor.door_window_sensor_158d0004248d5b') == "on" or states('binary_sensor.door_window_sensor_158d0004231f7b') == "on" %} True {% else %} False {% endif %} - service: image_processing.scan data: entity_id: image_processing.doods_garage # # When motion detected in garage, scan garage camera # If any of the garage doors are open, scan front door, driveway as well! # - alias: Scan Garage Camera When Motion initial_state: true trigger: - platform: state entity_id: - binary_sensor.motion_sensor_158d000272bf48 to: "on" condition: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" action: - service: image_processing.scan data: entity_id: image_processing.doods_garage - condition: template value_template: > {% if states('binary_sensor.door_window_sensor_158d0004248d5b') == "on" or states('binary_sensor.door_window_sensor_158d0004231f7b') == "on" %} True {% else %} False {% endif %} - service: image_processing.scan data: entity_id: image_processing.doods_driveway_camera - service: image_processing.scan data: entity_id: image_processing.doods_frontdoor_camera - condition: template value_template: >- {% if state_attr('image_processing.doods_garage', 'summary') != None %} {% if state_attr('image_processing.doods_garage', 'summary') |count > 0 %} true {% else %} false {% endif %} {% else %} false {% endif %} - service: script.voice_notify data: message: >- {%- set e_id = "image_processing.doods_garage" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the garage." }} {%- endif -%} - service: script.notify_family data: title: "Garage Motion" message: > {%- set e_id = "image_processing.doods_garage" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the garage on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected in the garage on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} url: "/config/www/downloads/camera/garage/garage_latest.jpg" notify_options: - telegram - tv - service: notify.notify_smtp data: title: 'Garage motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: > {%- set e_id = "image_processing.doods_garage" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the garage on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected in the garage on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} data: images: - "/config/www/downloads/camera/garage/garage_latest.jpg" # # When motion detected in the backyard, scan both cameras # - alias: Scan Backyard Camera When Motion initial_state: true trigger: - platform: state entity_id: - binary_sensor.motion_sensor_158d00024e842c to: "on" action: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - service: script.stream2chromecast data: url: !secret playarea_camera_stream_url name: "backyard" - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" - service: image_processing.scan data: entity_id: image_processing.doods_patio_camera - service: image_processing.scan data: entity_id: image_processing.doods_playarea_camera - condition: template value_template: >- {% if state_attr('image_processing.doods_patio_camera', 'summary') != None %} {% if state_attr('image_processing.doods_patio_camera', 'summary') |count > 0 %} true {% else %} false {% endif %} {% else %} false {% endif %} - service: script.voice_notify data: message: >- {%- set e_id = "image_processing.doods_patio_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the backyard." }} {%- endif -%} - service: script.notify_family data: title: "Backyard Motion" message: > {%- set e_id = "image_processing.doods_patio_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the backyard on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected in the backyard on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} url: "/config/www/downloads/camera/patio/patio_latest.jpg" notify_options: - telegram - tv - service: notify.notify_smtp data: title: 'Backyard motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: > {%- set e_id = "image_processing.doods_patio_camera" -%} {%- if state_attr(e_id, 'summary') -%} {%- set count = state_attr(e_id, 'summary') | count -%} {%- for x in state_attr(e_id, 'summary') | list -%} {%- if loop.first %}{% elif loop.last %}, and {% else %}, {% endif -%} {{- state_attr(e_id, 'summary')[x]}} {{ x ~ 's' if state_attr(e_id, 'summary')[x] > 1 else x }} {%- endfor -%} {{ " detected in the backyard on " ~ now().strftime("%d %h %Y, at %I:%M:%S %p") ~ ". Please see the images below." }} {% else %} Motion detected in the backyard on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below. {%- endif -%} data: images: - "/config/www/downloads/camera/patio/patio_latest.jpg" - "/config/www/downloads/camera/playarea/playarea_latest.jpg" # Before you think this code is crazy, here is an explanation. # # I have a xiaomi aqara PIR motion sensor near the front door, and # when it triggers, I capture photo from the camera, save it locally # using last_triggered date and time as filename... then send that # image to my email as an attacment. # # In the action, I have multiple services I am calling, and one service # creates file, and I needed that file name in the second service. # Since passing variables/info between the services within an action, # is not possible, I generate the file name based on the automation's # last_triggered date. Since that info is same across all the services # within the automation, I now can access/use the same file name everywhere! # # I only send iOS notifications when I am home, as my HA is not exposed to # Internet, & I can't see my camera unless I login to my vpn on my device. # That's why you see the condition right above iOS notification service. # # Make sure you add the path to white_list in the configuration.yaml file. # If front door is open, wait for a couple of seconds, before taking pic! # # I could have combined all the 3 automations into one, but if all the motion # sensors are triggered at the same time, the automation would only fire once, # and the code gets ugly big and unmanageable. 3 simple automations is better! ############################################################################### # ______ _ _ # | ____| | | | | # | |__ _ __ ___ _ __ | |_ __| | ___ ___ _ __ # | __| '__/ _ \| '_ \| __/ _` |/ _ \ / _ \| '__| # | | | | | (_) | | | | || (_| | (_) | (_) | | # |_| |_| \___/|_| |_|\__\__,_|\___/ \___/|_| - alias: Notify Frontdoor Camera Snapshots initial_state: true trigger: platform: state entity_id: binary_sensor.motion_sensor_158d00024ee084 to: "on" condition: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" action: - delay: "{{ '00:00:08' if states('binary_sensor.door_window_sensor_158d000424a6d6') == 'on' else '0:0:0' }}" - service: camera.snapshot data: entity_id: "camera.frontdoor_camera" filename: "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: camera.snapshot data: entity_id: "camera.porch_camera" filename: "{{ '/config/www/downloads/camera/porch/porch_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: camera.snapshot data: entity_id: "camera.driveway_camera" filename: "{{ '/config/www/downloads/camera/driveway/driveway_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: camera.snapshot data: entity_id: "camera.garage" filename: "{{ '/config/www/downloads/camera/garage/garage_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: notify.telegram data: title: "Front Door Motion" message: "Motion Detected At Front Door, Check images:" data: photo: - file: "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Front Door" - file: "{{ '/config/www/downloads/camera/driveway/driveway_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Driveway" - file: "{{ '/config/www/downloads/camera/garage/garage_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Garage" - file: "{{ '/config/www/downloads/camera/porch/porch_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: Porch - service: notify.notify_smtp data: title: 'Front door motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: 'Motion detected at the front door on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") -}}. Please see the images below.' data: images: - "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - "{{ '/config/www/downloads/camera/driveway/driveway_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - "{{ '/config/www/downloads/camera/garage/garage_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - "{{ '/config/www/downloads/camera/porch/porch_' ~ (states.binary_sensor.motion_sensor_158d00024ee084.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - condition: template value_template: "{{ states('device_tracker.life360_suresh') == 'home' }}" - service: notify.ios_devices data: message: "Check Front Door camera!" data: push: category: camera entity_id: "camera.frontdoor_camera" attachment: url: "{{ states.camera.frontdoor_camera.attributes.entity_picture }}" content-type: jpg # ############################################################################### # # _____ _ # # | __ \ (_) # # | | | |_ __ ___ _______ ____ _ _ _ # # | | | | '__| \ \ / / _ \ \ /\ / / _` | | | | # # | |__| | | | |\ V / __/\ V V / (_| | |_| | # # |_____/|_| |_| \_/ \___| \_/\_/ \__,_|\__, | # # __/ | # # |___/ - alias: Notify Driveway Camera Snapshots initial_state: true trigger: platform: state entity_id: binary_sensor.motion_sensor_158d00024e57fb to: "on" condition: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" action: - service: camera.snapshot data: entity_id: "camera.frontdoor_camera" filename: "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: camera.snapshot data: entity_id: "camera.driveway_camera" filename: "{{ '/config/www/downloads/camera/driveway/driveway_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: camera.snapshot data: entity_id: "camera.garage" filename: "{{ '/config/www/downloads/camera/garage/garage_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: notify.telegram data: title: "Driveway Motion" message: "Motion Detected At Driveway, Check images:" data: photo: - file: "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Front Door" - file: "{{ '/config/www/downloads/camera/driveway/driveway_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Driveway" - file: "{{ '/config/www/downloads/camera/garage/garage_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Garage" - service: notify.notify_smtp data: title: 'Driveway motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: 'Motion detected at the Driveway on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below.' data: images: - "{{ '/config/www/downloads/camera/driveway/driveway_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - "{{ '/config/www/downloads/camera/frontdoor/frontdoor_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - "{{ '/config/www/downloads/camera/garage/garage_' ~ (states.binary_sensor.motion_sensor_158d00024e57fb.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - condition: template value_template: "{{ states('device_tracker.life360_suresh') == 'home' }}" - service: notify.ios_devices data: message: "Check Driveway camera!" data: push: category: camera entity_id: "camera.driveway_camera" attachment: url: "{{ states.camera.driveway_camera.attributes.entity_picture }}" content-type: jpg # ############################################################################### # # ____ _ _ # # | _ \ | | | | # # | |_) | __ _ ___| | ___ _ __ _ _ __ __| | # # | _ < / _` |/ __| |/ / | | |/ _` | '__/ _` | # # | |_) | (_| | (__| <| |_| | (_| | | | (_| | # # |____/ \__,_|\___|_|\_\\__, |\__,_|_| \__,_| # # __/ | # # |___/ - alias: Notify Backyard Camera Snapshots initial_state: true trigger: platform: state entity_id: binary_sensor.motion_sensor_158d00024e842c to: "on" condition: - condition: template value_template: "{{ states('input_boolean.camera_alerts') == 'on' }}" - condition: template value_template: "{{ states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' }}" action: - condition: template value_template: >- {% if state_attr('image_processing.doods_frontdoor_camera', 'summary') != None %} {% if state_attr('image_processing.doods_frontdoor_camera', 'summary') |count > 0 %} true {% else %} false {% endif %} {% else %} false {% endif %} - service: camera.snapshot data: entity_id: "camera.patio_camera" filename: "{{ '/config/www/downloads/camera/patio/patio_' ~ (states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: camera.snapshot data: entity_id: "camera.playarea_camera" filename: "{{ '/config/www/downloads/camera/playarea/playarea_' ~ (states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - service: notify.telegram data: title: "Backyard Motion" message: "Motion Detected in the Backyard, Check images:" data: photo: - file: "{{ '/config/www/downloads/camera/patio/patio_' ~ (states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Patio" - file: "{{ '/config/www/downloads/camera/playarea/playarea_' ~ (states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" caption: "Playarea" - service: notify.notify_smtp data: title: 'Backyard motion {{ now().strftime("%d %h %Y, %I:%M:%S %p") }}' message: 'Motion detected in the Backyard on {{ now().strftime("%d %h %Y, at %I:%M:%S %p") }}. Please see the images below.' data: images: - "{{ '/config/www/downloads/camera/patio/patio_' ~ (states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - "{{ '/config/www/downloads/camera/playarea/playarea_' ~ (states.binary_sensor.motion_sensor_158d00024e842c.last_updated ~ '').replace('-','_') .replace(' ', '_').replace(':','_').replace('.','_').replace('+','_') ~ '.jpg' }}" - condition: template value_template: "{{ states('device_tracker.life360_suresh') == 'home' }}" - service: notify.ios_devices data: message: "Check Patio camera!" data: push: category: camera entity_id: "camera.patio_camera" attachment: url: "{{ states.camera.patio_camera.attributes.entity_picture }}" content-type: jpg ############################################################################### # _______ _ ____ _ # |__ __| | | / __ \ | | # | | _____ _| |_ | | | |_ _____ _ __| | __ _ _ _ # | |/ _ \ \/ / __| | | | \ \ / / _ \ '__| |/ _` | | | | # | | __/> <| |_ | |__| |\ V / __/ | | | (_| | |_| | # |_|\___/_/\_\\__| \____/ \_/ \___|_| |_|\__,_|\__, | # __/ | # |___/ # # Show latest weather information on camera (refresh every 2 minutes), but only # do it if the last updated is more than 2 minutes; In case some other automation # sets a new text overlay, make sure it stays for at least 2 minutes before # replacing with the weather information # - alias: Show Outdoor Temperature on Camera trigger: - platform: time_pattern minutes: "/2" condition: - condition: template value_template: > {% if state_attr('script.frontdoor_camera_text_overlay', 'last_triggered') != None %} {{ (as_timestamp(now()) - as_timestamp( state_attr('script.frontdoor_camera_text_overlay', 'last_triggered'))) | int > 120 }} {% else %} true {% endif %} action: - service: script.frontdoor_camera_text_overlay data: text: > {{ '* ' if states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' -}} {{- states('sensor.dark_sky_temperature')|int}} °F, Feels like {{- ' ' ~ states('sensor.dark_sky_apparent_temperature') |int -}} - service: script.driveway_camera_text_overlay data: text: > {{ '* ' if states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' -}} {{- states('sensor.dark_sky_temperature')|int}} °F, Feels like {{- ' ' ~ states('sensor.dark_sky_apparent_temperature') |int -}} - service: script.playarea_camera_text_overlay data: text: > {{ '* ' if states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' -}} {{- states('sensor.dark_sky_temperature')|int}} °F, Feels like {{- ' ' ~ states('sensor.dark_sky_apparent_temperature') |int -}} - service: script.patio_camera_text_overlay data: text: > {{ '* ' if states('alarm_control_panel.home') == 'armed_home' or states('alarm_control_panel.home') == 'armed_away' -}} {{- states('sensor.dark_sky_temperature')|int}} °F, Feels like {{- ' ' ~ states('sensor.dark_sky_apparent_temperature') |int -}} ############################################################################### # _____ _ _ # / ____| | | | # | | | |__ _ __ ___ _ __ ___ ___ ___ __ _ ___| |_ # | | | '_ \| '__/ _ \| '_ ` _ \ / _ \/ __/ _` / __| __| # | |____| | | | | | (_) | | | | | | __/ (_| (_| \__ \ |_ # \_____|_| |_|_| \___/|_| |_| |_|\___|\___\__,_|___/\__| # # # Automation to keep Chromecast ON always # When chromecase goes into screen saver mode, the status becomes OFF # This automation will turn it back on if it is OFF for more than 30 seconds - alias: Keep Chromecast On trigger: - platform: state entity_id: media_player.chromecast_monitor to: "off" for: seconds: 30 - platform: state entity_id: media_player.chromecast_monitor to: "idle" for: seconds: 30 action: - service: media_player.turn_on entity_id: media_player.chromecast_monitor - service: media_player.play_media data: entity_id: media_player.chromecast_monitor media_content_id: !secret frontdoor_camera_stream_url media_content_type: video - service: input_label.set_value data: entity_id: input_label.current_stream value: "frontyard" # Motion can be detected anywhere around the house, but the main focus is "Frontyard". # By default, the "frontyard" camera stream is played on Chromecast, but when motion # detected anywhere else, it changes the stream to that corresponding camera. # This automation restores back to "default" (frontyard) after 15 seconds! # - alias: Restore Frontyard Stream trigger: - platform: time_pattern seconds: "/5" condition: - condition: template value_template: "{{ states('input_label.current_stream') != 'frontyard' }}" - condition: template value_template: "{{ (as_timestamp(now()) - as_timestamp(states.input_label.current_stream.last_updated)) | int > 15 }}" action: - service: script.frontdoor_cam # # Every 15 minutes, change stream to alternate view with random cameras # - alias: Reset Stream On Chromecast trigger: - platform: time_pattern minutes: "/15" action: - service_template: "script.{{- ['driveway', 'patio', 'playarea', 'porch'] | random -}}_cam" script: frontdoor_cam: sequence: - service: script.stream2chromecast data: url: !secret frontdoor_camera_stream_url name: "frontyard" driveway_cam: sequence: - service: script.stream2chromecast data: url: !secret driveway_camera_stream_url name: "driveway" patio_cam: sequence: - service: script.stream2chromecast data: url: !secret patio_camera_stream_url name: "patio" playarea_cam: sequence: - service: script.stream2chromecast data: url: !secret playarea_camera_stream_url name: "playarea" porch_cam: sequence: - service: script.stream2chromecast data: url: !secret porch_camera_stream_url name: "porch" reset_camera_stream: alias: Reset Camera Stream sequence: - service: shell_command.reset_camera_stream - service_template: "script.{{- ['frontdoor', 'driveway', 'patio', 'playarea'] | random -}}_cam" ############################################################################### # On-Demand camera stream to chromecast scripts # stream_frontdoor_camera_to_chromecast: sequence: - condition: template value_template: "{{ states('input_boolean.stream_camera2chromecast') == 'on' }}" - service: script.stream2chromecast data: url: !secret frontdoor_camera_stream_url name: "frontyard" stream_driveway_camera_to_chromecast: sequence: - condition: template value_template: "{{ states('input_boolean.stream_camera2chromecast') == 'on' }}" - service: script.stream2chromecast data: url: !secret driveway_camera_stream_url name: "driveway" stream_patio_camera_to_chromecast: sequence: - condition: template value_template: "{{ states('input_boolean.stream_camera2chromecast') == 'on' }}" - service: script.stream2chromecast data: url: !secret patio_camera_stream_url name: "patio" stream_playarea_camera_to_chromecast: sequence: - condition: template value_template: "{{ states('input_boolean.stream_camera2chromecast') == 'on' }}" - service: script.stream2chromecast data: url: !secret playarea_camera_stream_url name: "playarea" stream_porch_camera_to_chromecast: sequence: - condition: template value_template: "{{ states('input_boolean.stream_camera2chromecast') == 'on' }}" - service: script.stream2chromecast data: url: !secret porch_camera_stream_url name: "porch" ############################################################################### # _____ ____ _ # / ____| / __ \ | | # | | __ _ _ __ ___ ___ _ __ __ _ | | | |_ _____ _ __| | __ _ _ _ # | | / _` | '_ ` _ \ / _ \ '__/ _` | | | | \ \ / / _ \ '__| |/ _` | | | | # | |___| (_| | | | | | | __/ | | (_| | | |__| |\ V / __/ | | | (_| | |_| | # \_____\__,_|_| |_| |_|\___|_| \__,_| \____/ \_/ \___|_| |_|\__,_|\__, | # __/ | # |___/ # # Camera Text Overlay Script - sets a given text as an overlay on camera feed ############################################################################### frontdoor_camera_text_overlay: sequence: - service: rest_command.set_frontdoor_camera_text_left_bottom data: message: "{{text}}" driveway_camera_text_overlay: sequence: - service: rest_command.set_driveway_camera_text_left_bottom data: message: "{{text}}" patio_camera_text_overlay: sequence: - service: rest_command.set_patio_camera_text_left_bottom data: message: "{{text}}" playarea_camera_text_overlay: sequence: - service: rest_command.set_playarea_camera_text_left_bottom data: message: "{{text}}" ############################################################################### # Stream2Chromecast script streams a given URL to Chromecast # But before it streams, it turns ON the media player if it is OFF, and after # streaming the URL, it saves the current stream name # BY calling media_player.turn_off, it forces Chromecast stream onto be active # on TV as soon as it turns ON TV stream2chromecast: sequence: - condition: template value_template: "{{ states('input_label.current_stream') != name }}" - service: media_player.play_media data: entity_id: media_player.chromecast_monitor media_content_id: "{{ url }}" media_content_type: "video" - service: input_label.set_value data: entity_id: input_label.current_stream value: "{{ name }}"