input_text: camera14_status: name: Camera14 Status icon: mdi:cctv input_select: camera14_preset: name: Camera14 Preset options: - Deck - Sandbox - Grove - Grass - Yard - Stairs - BesideStairs input_button: # PTZ Controls cam14_ptz_up: name: Cam14 PTZ Up icon: mdi:arrow-up cam14_ptz_right_up: name: Cam14 PTZ Right Up icon: mdi:arrow-top-right cam14_ptz_right: name: Cam14 PTZ Right icon: mdi:arrow-right cam14_ptz_right_down: name: Cam14 Right Down icon: mdi:arrow-bottom-right cam14_ptz_down: name: Cam14 PTZ Down icon: mdi:arrow-down cam14_ptz_left_down: name: Cam14 PTZ Left Down icon: mdi:arrow-bottom-left cam14_ptz_left: name: Cam14 PTZ Left icon: mdi:arrow-left cam14_ptz_left_up: name: Cam14 Left Up icon: mdi:arrow-top-left cam14_ptz_zoom_in: name: Cam14 Zoom In icon: mdi:magnify-plus cam14_ptz_zoom_out: name: Cam14 Zoom Out icon: mdi:magnify-minus # Camera Preset cam14_ptz_preset_1: name: Cam14 Deck icon: mdi:grill cam14_ptz_preset_2: name: Cam14 Sandbox icon: mdi:pail cam14_ptz_preset_3: name: Cam14 Yard icon: mdi:slide cam14_ptz_preset_4: name: Cam14 Grove icon: mdi:forest cam14_ptz_preset_5: name: Cam14 Stairs icon: mdi:stairs cam14_ptz_preset_6: name: Cam14 Preset 6 icon: mdi:stairs-down cam14_ptz_preset_7: name: Cam14 Preset 7 icon: mdi:grass cam14_ptz_preset_8: name: Cam14 Preset 8 icon: mdi:map-marker cam14_ptz_preset_9: name: Cam14 Preset 9 icon: mdi:map-marker cam14_ptz_preset_10: name: Cam14 Preset 10 icon: mdi:map-marker automation: # - id: automation_cam14_ptz_controls # alias: Cam14 PTZ Controls # mode: queued # trigger: # - id: up # platform: state # entity_id: input_button.cam14_ptz_up # - id: right_up # platform: state # entity_id: input_button.cam14_ptz_right_up # - id: right # platform: state # entity_id: input_button.cam14_ptz_right # - id: right_down # platform: state # entity_id: input_button.cam14_ptz_right_down # - id: down # platform: state # entity_id: input_button.cam14_ptz_down # - id: left_down # platform: state # entity_id: input_button.cam14_ptz_left_down # - id: left # platform: state # entity_id: input_button.cam14_ptz_left # - id: left_up # platform: state # entity_id: input_button.cam14_ptz_left_up # - id: zoom_in # platform: state # entity_id: input_button.cam14_ptz_zoom_in # - id: zoom_out # platform: state # entity_id: input_button.cam14_ptz_zoom_out # condition: [] # action: # - service: amcrest.ptz_control # data: # entity_id: camera.frigate_cam14 # movement: "{{ trigger.id }}" # travel_time: 0.5 # - delay: '00:00:01' # - id: automation_manage_frigate_cam14_motion # mode: single # alias: Manage Frigate Cam14 Motion # description: "" # trigger: # - platform: state # entity_id: input_boolean.cycle_cam14 # - platform: homeassistant # event: start # - platform: event # event_type: automation_reloaded # action: # - choose: # - conditions: # - condition: state # entity_id: input_boolean.cycle_cam14 # state: 'off' # sequence: # - service: switch.turn_on # target: # entity_id: switch.frigate_cam14_motion # default: # - service: switch.turn_off # target: # entity_id: switch.frigate_cam14_motion - id: automation_cycle_back_yard_camera mode: single alias: Cycle Back Yard Camera description: "" trigger: - platform: state entity_id: input_boolean.cycle_cam14 - platform: homeassistant event: start - platform: event event_type: automation_reloaded condition: - "{{ states('camera.frigate_cam14') not in ['unknown', 'unavailable'] }}" # - alias: "The input_boolean controlling the cycling of cam14 is on" # condition: state # entity_id: input_boolean.cycle_cam14 # state: "on" # - alias: "No people or animals detected by Frigate for the last 5 seconds" # condition: state # entity_id: binary_sensor.frigate_cam14_all_occupancy # state: "off" # for: # hours: 0 # minutes: 0 # seconds: 5 # # Either the camera isn't looking at the deck # # or the camera is looking at the deck and the deck motion sensor has been off for at least 30 seconds # # or the camera is looking at the deck and the patio door has been closed for at least 30 seconds # - condition: or # conditions: # - alias: "The input_select isn't set to Deck" # condition: not # conditions: # - condition: state # entity_id: input_select.camera14_preset # state: "Deck" # - alias: "The input_select is set to Deck and there hasn't been motion detected on the deck for the last 30 seconds" # condition: and # conditions: # - condition: state # entity_id: input_select.camera14_preset # state: "Deck" # - condition: state # entity_id: binary_sensor.deck_motion # state: "off" # for: # seconds: 30 # - alias: "The input_select is set to deck and the patio door has been shut for at least 30 seconds" # condition: and # conditions: # - condition: state # entity_id: input_select.camera14_preset # state: "Deck" # - condition: state # entity_id: binary_sensor.patio_door_contact # state: "off" # for: # seconds: 30 action: # - alias: "This always cycles the back yard camera every 45 seconds. It should stop cycling when a person is found, but this version doesn't" # repeat: # while: "{{ is_state('input_boolean.cycle_cam14', 'on') }}" # sequence: # - service: input_select.select_next # data: # cycle: true # target: # entity_id: input_select.camera14_preset # - delay: "00:00:45" - alias: "This should only cycle the back yard camera, if a person isn't found." repeat: while: "{{ is_state('input_boolean.cycle_cam14', 'on') }}" sequence: - choose: # If the camera is looking at the deck and the deck motion sensor is on, then wait 5 seconds. - conditions: - condition: state entity_id: input_select.camera14_preset state: Deck - condition: state entity_id: binary_sensor.deck_motion state: "on" sequence: - service: input_text.set_value target: entity_id: input_text.camera14_status data: value: "Deck" - delay: 5 # If a person is not found, cycle to the next preset, then wait 30 seconds. - conditions: - condition: template value_template: "{{ is_state('binary_sensor.frigate_cam14_person_occupancy','off') }}" sequence: - service: input_text.set_value target: entity_id: input_text.camera14_status data: value: "Cycling" - service: input_select.select_next data: cycle: true target: entity_id: input_select.camera14_preset - delay: 30 # If a person is found, check if the person is still present every 5 seconds default: - service: input_text.set_value target: entity_id: input_text.camera14_status data: value: "Focusing" - repeat: while: "{{ is_state('binary_sensor.frigate_cam14_person_occupancy','off') }}" sequence: - delay: 5 - service: input_text.set_value target: entity_id: input_text.camera14_status data: value: "Static" - id: automation_look_at_deck mode: restart alias: "Look at deck" description: "When the patio door is opened, set the camera to the deck preset, if frigate isn't currently detecting anything" trigger: - platform: state entity_id: binary_sensor.patio_door_contact from: "off" to: "on" condition: - condition: numeric_state entity_id: sensor.frigate_cam14_all_count below: 2 - "{{ states('camera.frigate_cam14') not in ['unknown', 'unavailable'] }}" action: # We don't need to turn off cycling the back yard camera. # - service: input_boolean.turn_off # target: # entity_id: input_boolean.cycle_cam14 - service: input_text.set_value target: entity_id: input_text.camera14_status data: value: "Deck" - service: input_select.select_option data: option: Deck target: entity_id: input_select.camera14_preset # the Cycle cam 14 automation already checks if something is detected. All we need to do is force cam14 to look at the deck # - delay: "00:00:05" # - repeat: # while: "{{ is_state('binary_sensor.frigate_cam14_all_occupancy', 'on')}}" # sequence: # - delay: "00:00:05" # - service: input_boolean.turn_on # target: # entity_id: input_boolean.cycle_cam14 - id: automation_back_yard_snapshot mode: restart alias: "Back Yard Snapshot" trigger: - platform: homeassistant event: start - platform: state entity_id: camera.frigate_cam14 to: "streaming" action: - service: camera.snapshot target: entity_id: camera.frigate_cam14 data: filename: "/config/tmp/snapshots/cam14-{{states('input_select.camera14_preset')}}-{{now().strftime('%y%m%d-%H%M%S')}}.jpg" - id: automation_cam14_ptz_preset alias: Cam14 PTZ Presets mode: single max_exceeded: silent trigger: - id: Preset 1 platform: state entity_id: input_button.cam14_ptz_preset_1 - id: Preset 2 platform: state entity_id: input_button.cam14_ptz_preset_2 - id: Preset 3 platform: state entity_id: input_button.cam14_ptz_preset_3 - id: Preset 4 platform: state entity_id: input_button.cam14_ptz_preset_4 - id: Preset 5 platform: state entity_id: input_button.cam14_ptz_preset_5 - id: Preset 6 platform: state entity_id: input_button.cam14_ptz_preset_6 - id: Preset 7 platform: state entity_id: input_button.cam14_ptz_preset_7 - id: Preset 8 platform: state entity_id: input_button.cam14_ptz_preset_8 - id: Preset 9 platform: state entity_id: input_button.cam14_ptz_preset_9 - id: Preset 10 platform: state entity_id: input_button.cam14_ptz_preset_10 condition: - "{{ states('camera.frigate_cam14') not in ['unknown', 'unavailable'] }}" action: - choose: - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 1}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "Deck" - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 2}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "Sandbox" - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 3}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "Yard" - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 4}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "Grove" - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 5}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "Stairs" - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 6}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "BesideStairs" - conditions: > {{ trigger.id|replace('Preset ','')|int(default=0) == 7}} sequence: - service: input_select.select_option target: entity_id: input_select.camera14_preset data: option: "Grass" - service: "shell_command.back_yard_preset_{{ trigger.id|replace('Preset ','')|int(default=1) }}" # - service: amcrest.goto_preset # data: # entity_id: camera.frigate_cam14 # preset: "{{ trigger.id|replace('Preset ','')|int(default=1) }}" - delay: "00:00:2" - id: automation_cam14_ptz_move alias: Cam14 PTZ Move mode: restart trigger: - platform: state entity_id: input_select.camera14_preset - platform: state entity_id: camera.frigate_cam14 from: unavailable - platform: homeassistant event: start - platform: time_pattern minutes: /10 condition: - "{{ states('camera.frigate_cam14') not in ['unknown', 'unavailable'] }}" action: - choose: - conditions: - condition: state entity_id: input_select.camera14_preset state: Sandbox sequence: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_2 - conditions: - condition: state entity_id: input_select.camera14_preset state: Yard sequence: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_3 - conditions: - condition: state entity_id: input_select.camera14_preset state: Grove sequence: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_4 - conditions: - condition: state entity_id: input_select.camera14_preset state: Stairs sequence: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_5 - conditions: - condition: state entity_id: input_select.camera14_preset state: BesideStairs sequence: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_6 - conditions: - condition: state entity_id: input_select.camera14_preset state: Grass sequence: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_7 default: - service: input_button.press data: {} target: entity_id: input_button.cam14_ptz_preset_1 template: - binary_sensor: - name: Deck Person Occupancy unique_id: templatebinarysensor.deck_person_occupancy availability: "{{ states('binary_sensor.possible_deck_person_occupancy') not in ['unknown', 'unavailable'] }}" state: "{{ is_state('binary_sensor.possible_deck_person_occupancy','on') and is_state('input_select.camera14_preset','Deck') }}" icon: > {% if is_state('binary_sensor.deck_person_occupancy','on') %} mdi:motion-sensor {% else %} mdi:motion-sensor-off {% endif %} - name: Deck Animal Motion unique_id: templatebinarysensor.deck_animal_occupancy availability: "{{ states('binary_sensor.possible_deck_animal_occupancy') not in ['unknown', 'unavailable'] }}" state: "{{ is_state('binary_sensor.possible_deck_animal_occupancy','on') and is_state('input_select.camera14_preset','Deck') }}" icon: mdi:bird - sensor: - name: Deck Person Count unique_id: templatesensor.deck_person_count availability: "{{ states('sensor.possible_deck_person_count') not in ['unknown', 'unavailable'] }}" unit_of_measurement: objects state: > {% if is_state('input_select.camera14_preset','Deck') %} {{ states('sensor.possible_deck_person_count') }} {% else %} 0 {% endif %} icon: mdi:shield-account - name: Deck Animal Count unique_id: templatesensor.deck_animal_count availability: "{{ states('sensor.possible_deck_animal_count') not in ['unknown', 'unavailable'] }}" unit_of_measurement: objects state: > {% if is_state('input_select.camera14_preset','Deck') %} {{ states('sensor.possible_deck_animal_count') }} {% else %} 0 {% endif %} icon: mdi:paw