Integrar Frigate en Home Assistant

Una vez instalado y configurado Frigate el siguiente paso lógico es integrarlo en nuestro Home Assistant.

Lo primero será crea una serie de cámaras MQTT

mqtt:
    
  camera:
  
    - name: mqtt_foscam_1
      unique_id: mqtt_foscam_1
      topic: frigate/foscam_1/person/snapshot
    
    - name: mqtt_foscam_2
      unique_id: mqtt_foscam_2
      topic: frigate/foscam_2/person/snapshot

    - name: mqtt_foscam_3
      unique_id: mqtt_foscam_3
      topic: frigate/foscam_3/person/snapshot

    - name: mqtt_hikvision_1
      unique_id: mqtt_hikvision_1
      topic: frigate/HIKVISION_1/person/snapshot
      
    - name: mqtt_hikvision_2
      unique_id: mqtt_hikvision_2
      topic: frigate/HIKVISION_2/person/snapshot
      
    - name: mqtt_ic_3116w
      unique_id: mqtt_ic_3116w
      topic: frigate/IC-3116W/person/snapshot   

Lo siguiente crear los sensores de deteccions de movimiento.

  ####################################################################
  # Sensores camaras frigate
  ####################################################################

    - name: "Frigate NVR"
      icon: hass:cctv
      state_topic: "frigate/available"
      payload_on: "online"
      payload_off: "offline"
      device_class: connectivity
                       
    - name: movimiento_foscam_1
      device_class: motion
      off_delay: 10
      state_topic: "frigate/events"
      value_template: >
        {% if (value_json['after']['camera'] == 'foscam_1') and (value_json['after']['label'] == 'person') and (value_json['after']['stationary'] == false) 
         and (value_json['after']['has_snapshot'] == true ) %}
          ON
        {% else %}
          OFF
        {% endif %}            
            
    - name: movimiento_foscam_2
      device_class: motion
      off_delay: 10
      state_topic: "frigate/events"
      value_template: >
        {% if (value_json['after']['camera'] == 'foscam_2') and (value_json['after']['label'] == 'person') and (value_json['after']['stationary'] == false) 
         and (value_json['after']['has_snapshot'] == true ) %}
          ON
        {% else %}
          OFF
        {% endif %}               

    - name: movimiento_foscam_3
      device_class: motion
      off_delay: 10
      state_topic: "frigate/events"
      value_template: >
        {% if (value_json['after']['camera'] == 'foscam_3') and (value_json['after']['label'] == 'person') and (value_json['after']['stationary'] == false) 
         and (value_json['after']['has_snapshot'] == true ) %}
          ON
        {% else %}
          OFF
        {% endif %}  

    - name: movimiento_hikvision_1
      device_class: motion
      off_delay: 10
      state_topic: "frigate/events"
      value_template: >
        {% if (value_json['after']['camera'] == 'HIKVISION_1') and (value_json['after']['label'] == 'person') and (value_json['after']['stationary'] == false) 
         and (value_json['after']['has_snapshot'] == true ) %}
          ON
        {% else %}
          OFF
        {% endif %}  

    - name: movimiento_hikvision_2
      device_class: motion
      off_delay: 10
      state_topic: "frigate/events"
      value_template: >
        {% if (value_json['after']['camera'] == 'HIKVISION_2') and (value_json['after']['label'] == 'person') and (value_json['after']['stationary'] == false) 
         and (value_json['after']['has_snapshot'] == true ) %}
          ON
        {% else %}
          OFF
        {% endif %}

    - name: movimiento_ic_3116w
      device_class: motion
      off_delay: 10
      state_topic: "frigate/events"
      value_template: >
        {% if (value_json['after']['camera'] == 'IC-3116W') and (value_json['after']['label'] == 'person') and (value_json['after']['stationary'] == false) 
         and (value_json['after']['has_snapshot'] == true ) %}
          ON
        {% else %}
          OFF
        {% endif %}

Una vez creados y funcionando ya podemos empezar con las automatizaciones , en este caso por ejemplo automatizaciones que guardan en jpg el snapshot que nos ha llegado por mqtt en función de cada cámara y lo envia por Telegram dando aviso por texto y añadiendo la imagen

- id: 'nuevo snapshot recibido camara 1'
  alias:  'nuevo snapshot recibido camara 1'
  variables:
    filepath: /config/www/cam_captures/1_{{now().year}}_{{now().month}}_{{now().day}}_{{now().hour}}_{{now().minute}}_{{now().second}}.jpg   
  trigger:
    - platform: state
      entity_id:  binary_sensor.movimiento_foscam_1
      from: 'off'
      to: 'on'    
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.mqtt_foscam_1
        filename: '{{ filepath }}'
    - delay: 00:00:05
    - service: notify.notif_telegram_ha_camaras
      data:
        title: Enviar imagenes
        message: Cam. 1 {{now().strftime("%d/%m %H:%M:%S")}}
        data:
          photo:
          - file: '{{ filepath }}'
            capture: Snapshoot
            caption: Cam. 1 {{now().strftime("%d/%m %H:%M:%S")}}      
            
- id: 'nuevo snapshot recibido camara 2'
  alias:  'nuevo snapshot recibido camara 2'
  variables:
    filepath: /config/www/cam_captures/2_{{now().year}}_{{now().month}}_{{now().day}}_{{now().hour}}_{{now().minute}}_{{now().second}}.jpg   
  trigger:
    - platform: state
      entity_id:  binary_sensor.movimiento_foscam_2
      from: 'off'
      to: 'on'    
  action:        
    - service: camera.snapshot
      data:
        entity_id: camera.mqtt_foscam_2
        filename: '{{ filepath }}'
    - delay: 00:00:05
    - service: notify.notif_telegram_ha_camaras
      data:
        title: Enviar imagenes
        message: Cam. 2 {{now().strftime("%d/%m %H:%M:%S")}}
        data:
          photo:
          - file: '{{ filepath }}'
            capture: Snapshoot
            caption: Cam. 2 {{now().strftime("%d/%m %H:%M:%S")}}                


- id: 'nuevo snapshot recibido camara 3'
  alias:  'nuevo snapshot recibido camara 3'
  variables:
    filepath: /config/www/cam_captures/3_{{now().year}}_{{now().month}}_{{now().day}}_{{now().hour}}_{{now().minute}}_{{now().second}}.jpg   
  trigger:
    - platform: state
      entity_id:  binary_sensor.movimiento_foscam_3
      from: 'off'
      to: 'on'    
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.mqtt_foscam_3
        filename: '{{ filepath }}'
    - delay: 00:00:05
    - service: notify.notif_telegram_ha_camaras
      data:
        title: Enviar imagenes
        message: Cam. 3 {{now().strftime("%d/%m %H:%M:%S")}}
        data:
          photo:
          - file: '{{ filepath }}'
            capture: Snapshoot
            caption: Cam. 3 {{now().strftime("%d/%m %H:%M:%S")}}                


- id: 'nuevo snapshot recibido camara 4'
  alias:  'nuevo snapshot recibido camara 4'
  variables:
    filepath: /config/www/cam_captures/4_{{now().year}}_{{now().month}}_{{now().day}}_{{now().hour}}_{{now().minute}}_{{now().second}}.jpg   
  trigger:
    - platform: state
      entity_id:  binary_sensor.movimiento_hikvision_1
      from: 'off'
      to: 'on'    
  action:  
    - service: camera.snapshot
      data:
        entity_id: camera.mqtt_hikvision_1
        filename: '{{ filepath }}'
    - delay: 00:00:05
    - service: notify.notif_telegram_ha_camaras
      data:
        title: Enviar imagenes
        message: Cam. 4 {{now().strftime("%d/%m %H:%M:%S")}}
        data:
          photo:
          - file: '{{ filepath }}'
            capture: Snapshoot
            caption: Cam. 4 {{now().strftime("%d/%m %H:%M:%S")}}                


- id: 'nuevo snapshot recibido camara 5'
  alias:  'nuevo snapshot recibido camara 5'
  variables:
    filepath: /config/www/cam_captures/5_{{now().year}}_{{now().month}}_{{now().day}}_{{now().hour}}_{{now().minute}}_{{now().second}}.jpg   
  trigger:
    - platform: state
      entity_id:  binary_sensor.movimiento_hikvision_2
      from: 'off'
      to: 'on'    
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.mqtt_hikvision_2
        filename: '{{ filepath }}'
    - delay: 00:00:05
    - service: notify.notif_telegram_ha_camaras
      data:
        title: Enviar imagenes
        message: Cam. 5 {{now().strftime("%d/%m %H:%M:%S")}}
        data:
          photo:
          - file: '{{ filepath }}'
            capture: Snapshoot
            caption: Cam. 5 {{now().strftime("%d/%m %H:%M:%S")}}                
 

- id: 'nuevo snapshot recibido camara 6'
  alias:  'nuevo snapshot recibido camara 6'
  variables:
    filepath: /config/www/cam_captures/6_{{now().year}}_{{now().month}}_{{now().day}}_{{now().hour}}_{{now().minute}}_{{now().second}}.jpg   
  trigger:
    - platform: state
      entity_id:  binary_sensor.movimiento_ic_3116w
      from: 'off'
      to: 'on'   
  action:
    - service: camera.snapshot
      data:
        entity_id: camera.mqtt_ic_3116w
        filename: '{{ filepath }}'
    - delay: 00:00:05
    - service: notify.notif_telegram_ha_camaras
      data:
        title: Enviar imagenes
        message: Cam. 6 {{now().strftime("%d/%m %H:%M:%S")}}
        data:
          photo:
          - file: '{{ filepath }}'
            capture: Snapshoot
            caption: Cam. 6 {{now().strftime("%d/%m %H:%M:%S")}}   

También lo añadimos a nuestro panel lovelace

  - type: vertical-stack
    cards:
      - type: entities
        title: Camaras 
        show_name: true
        show_state: false
        show_header_toggle: false
        columns: 3     
        entities:        
          - entity: binary_sensor.frigate_nvr
            name: Frigate NVR  
          - entity: camera.mqtt_foscam_1
            name: Camara 1   
          - entity: camera.mqtt_foscam_2
            name: Camara 2
          - entity: camera.mqtt_foscam_3
            name: Camara 3
          - entity: camera.mqtt_hikvision_1
            name: Camara 4
          - entity: camera.mqtt_hikvision_2
            name: Camara 5
          - entity: camera.mqtt_ic_3116w
            name: Camara 6

      - type: entities
        title: Sensores movimiento Camaras
        show_name: true
        show_state: false
        show_header_toggle: false
        columns: 3     
        entities:        
          - entity: binary_sensor.movimiento_foscam_1
            name: Camara 1   
          - entity: binary_sensor.movimiento_foscam_2
            name: Camara 2
          - entity: binary_sensor.movimiento_foscam_3
            name: Camara 3
          - entity: binary_sensor.movimiento_hikvision_1
            name: Camara 4
          - entity: binary_sensor.movimiento_hikvision_2
            name: Camara 5
          - entity: binary_sensor.movimiento_ic_3116w
            name: Camara 6

Y este seria el resultado al activarse la detección de movimiento

Y con esto y un bizcocho ……..

Deja un comentario