Trying to send Nest camera snapshot via Telegram bot

I’ve installed the Nest integration and whilst I’ve been able to get a camera snapshot sent to my phone via :

  - service: notify.mobile_app_myphone
    data:
      title: motion detected
      message: front door motion detected
       data:
       image: /api/camera_proxy/camera.front_door

I’m struggling how to send the same image to a telegram group so that I can have multiplie recipients.

What I currently have that doesn’t work:

  - service: telegram_bot.send_photo
    data:
      url: /api/camera_proxy/camera.front_door
      caption: Door bell pressed
      target: 123456

This should help:

  action:
  - service: camera.snapshot
    data:
      entity_id: camera.rear
      filename: '/config/www/snapshots/gate.jpg'
  - service: notify.telegram_general
    data:
      message: ''
      data:
        photo:
        - file: /config/www/snapshots/gate.jpg
          caption: >
            {% if is_state('binary_sensor.lane_gate_contact', 'on') %}
              The lane gate is open.
            {% else %}
              The lane gate is closed.
            {% endif %}

Thanks for taking the time to reply. My HASS instance (2021.11.4) is saying config is valid but when I go into automations to check it, notify.telegram_general isn’t in the drop down list?

That’s my telegram notification service. You were supposed to use it as an example not copy it verbatim.

show’s how much I know about this stuff!

Hi, I wanted to point out there has been an update to the nest media APIs so you can more accurately capture media associated with a specific event. Check out Nest - Home Assistant for more detail and also see the updated trigger documentation.

Did you get any further with it?

I’m exactly in the same boat.

I tried this method, from the nest documentation, but it didn’t help either:

  message: Doorbell Pressed
  title: Someone pressed the doorbell
  data:
    image: >-
      /api/nest/event_media/X3b1ef4636d68b7fdae2c220fe67f11a/XyIxNjMxMDYxODkxIiwgIm46MSJd/thumbnail

@tom_l your example is not working with the new nest cameras (battery), as far as I understand. It returns a standard (almost) black frame.
doorbell

I think this is basically a feature request for the telegram integration to support authenticated media player urls. My impression is that we now have the capabilities to support requesting signed urls from automations so this is possible to address if someone prioritizes fixing it.

I think support for getting signed media URLs for telegram isn’t there, so my question is: is it possible to get local file name knowing event id, so I can send the file?

No, telegram will need to support media urls to do this.

To clarify: The files do exist on disk and you can try to reverse engineer the format, but its not intended to be accessed this way and is not supported, will break without warning, etc.

As soon as I figured out filenames are timestamps, I was able to get a hacky workaround.
The issue /config/nest isn’t a secure directory to send files from. So the first step was to do a shell script to copy files:

shell_command:
  copy_nest: cp -r /config/nest/event_media/ /config/www/nestimgs/

and then the automation:

alias: Doorbell to Telegram
description: ""
trigger:
  - platform: device
    device_id: <DEVICE_ID>
    domain: nest
    type: doorbell_chime
condition: []
action:
  - service: shell_command.copy_nest
    data: {}
  - service: telegram_bot.send_animation
    data:
      caption: Doorbell!
      file: >-
        /config/www/nestimgs/event_media/{{ trigger.event.data.device_id }}/{{
        as_timestamp(trigger.event.data.timestamp) | int }}-doorbell_chime.mp4
mode: single

Works as a charm

instead of copy whole folder every time, you can also copy only the event picture:

shell_command:
  copy_doorbell_img: cp /config/nest/event_media{{ path }} /config/www/doorbell.jpg

and the action:

- service: shell_command.copy_doorbell_img
  data:
    path: /{{ trigger.event.data.device_id }}/{{as_timestamp(trigger.event.data.timestamp) | int }}-doorbell_chime.jpg
- service: telegram_bot.send_animation
  data:
    caption: Doorbell!
    file: /config/www/doorbell.jpg
1 Like

Perfect. This solved my problem. It is mp4 for me, so for what it’s worth here is my automation setup. I like that it is only sending one file and overwriting. I don’t need all those files.

configuration.yaml

shell_command:
    copy_doorbell_img: cp /config/nest/event_media{{ path }} /config/www/doorbell.mp4

And the automation (I am picking up people but you could change the type of file according to what you need):

alias: Doorbell Camera Person
description: ""
trigger:
  - platform: device
    device_id: 5555555a55bf155ac55e55ea555ec55d
    domain: nest
    type: camera_person
condition: []
action:
  - service: shell_command.copy_doorbell_img
    data:
      path: >-
        /{{ trigger.event.data.device_id
        }}/{{as_timestamp(trigger.event.data.timestamp) | int
        }}-camera_person.mp4
  - service: telegram_bot.send_animation
    data:
      caption: Person!
      file: /config/www/doorbell.mp4
mode: single