Accessing camera stream externally

Also looking for an answer on this as I would like to include camera feeds in my HA-Dashboard without passing user/pass.

1 Like

If you run in local network you can probably use allowed networks configuration.

I figured it out using an extra template sensor.

- platform: template
    sensors:
      cam.###token:
        value_template: "{{ state_attr('camera.###', 'access_token') }}"

I donā€™t know how to write it in an homeassistant automation,
but using NodeRed it is possible to add the token to the rest of the url before sending it in a notification.
example_url: https://hass.#####.##/api/camera_proxy_stream/camera.###?token=+sensor.cam.###token
When the token updates, the sensor value updates also. No need voor http password.

Iā€™m using it with html5 notifications on android/chrome to send me an image when movement is detected. When i click the image in the notification, it shows the livestream of the camera.

@Jplmn, could you share an example of your html5 notification in NodeRed? Iā€™m currently doing the same thing using the normal yaml automation but it doesnā€™t seem like api_password is working anymore to view the live feedā€¦ I end up getting a 401 unauthorized errorā€¦

1 Like

I would also like to see an example please!

i tried to do ur template sensor, and i can see the value of the token correctly in developer tool states
but i cant figure out how to add it to nodered for it to successfully access the image.

this is my code in nodered html5 notification which doesnt seem to work

{
ā€œmessageā€: ā€œDeck Door is OPEN!ā€,
ā€œtargetā€: [
ā€œperson a phoneā€,
ā€œperson b phoneā€
],
ā€œdataā€: {
ā€œimageā€: ā€œhttp://xxxx.xxxx.org:8123/api/camera_proxy_stream/camera.living_room_camera?token=+sensor.cam_livingtokenā€
}
}

not sure if someone is still interested but maybe it helps a noob like me :wink:
I was also not able to send a notification with a picture, so I tried it as Jplmn suggested.
As Iā€™m an absolut beginner, I will explain as a beginner how I did it

modify configuration.yaml and add

sensor: !include sensors.yaml

created a sensors.yaml in the config folder (this is just to keep things clear, can be done directly in the configuration.yaml as well)

modify sensors.yaml

   - platform: template
     sensors:
        cam_token:
           value_template: "{{ state_attr('camera.garten', 'access_token') }}"

open node red:

  1. event: sate node (tigger)
  2. switch (do sort between different values ( on/off , im my case)
  3. current state node: Entity ID: sensor.cam_token, State Location is set to msg.token
  4. function node:
msg.payload =
{
   "data": {
      "title": "HaustĆ¼r",
      "message": "Jemand hat geklingelt",
      "data": {
         "image": "http://XXXX.duckdns.org:8123/api/camera_proxy/camera.garten?token="+msg.token
      }
   }
}
return msg;
  1. call service node: Domain: notify, Service: mobile_app_my_phone

Thatā€™s it, it works perfect.

Why do not simply get attributes.entity_picture from current state node of camera entity and add it to url?
No extra sensor creation needed :sunglasses:

Would you like to elaborate on how to do this for the less knowledgeable like myself?
An example would be nice.

Sure, here you go:

[
    {
        "id": "f08876ae.9612a8",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "81462ff.125bfd",
        "type": "api-call-service",
        "z": "f08876ae.9612a8",
        "name": "Motion detection notification",
        "server": "9eef096.9ae42f8",
        "version": 1,
        "debugenabled": false,
        "service_domain": "notify",
        "service": "mobile_app_mi_8_pro",
        "entityId": "",
        "data": "",
        "dataType": "json",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 680,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "9fb296ce.be4b08",
        "type": "api-current-state",
        "z": "f08876ae.9612a8",
        "name": "Camera",
        "server": "9eef096.9ae42f8",
        "version": 1,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "override_topic": false,
        "entity_id": "camera.yihack_v4",
        "state_type": "str",
        "state_location": "",
        "override_payload": "none",
        "entity_location": "token",
        "override_data": "msg",
        "blockInputOverrides": false,
        "x": 340,
        "y": 160,
        "wires": [
            [
                "f7811ac0.57c8e8"
            ]
        ]
    },
    {
        "id": "f7811ac0.57c8e8",
        "type": "function",
        "z": "f08876ae.9612a8",
        "name": "Get token",
        "func": "msg.payload = \n{\n    \"data\": {\n        \"title\": \"Your title\",\n        \"message\": \"Your message\",\n        \"data\": {\n            \"image\": \"https://domain.com\"+msg.token.attributes.entity_picture\n        }\n    }\n}\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 480,
        "y": 160,
        "wires": [
            [
                "81462ff.125bfd"
            ]
        ]
    },
    {
        "id": "7fd94a30.560ab4",
        "type": "inject",
        "z": "f08876ae.9612a8",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 160,
        "wires": [
            [
                "9fb296ce.be4b08"
            ]
        ]
    },
    {
        "id": "9eef096.9ae42f8",
        "type": "server",
        "z": "",
        "name": "Home Assistant",
        "addon": true
    }
]

Thanks, Iā€™ll give this a go.

That worked lovely, Thanks a million.

Came across this and wanted to point out for anyone else looking at this in the future, that you dont even need to specify the token if you are using home assistant companion mobile app and node red on your home assistant server. The below works fine as a notification.

{ "message": "Motion Detected Outside.", "data": { "image": "/api/camera_proxy/camera.front_door_camera" } }

anyone ever figure out how to make this work with a single url from his original question? I am trying to do the same thing, but I havenā€™t been able to figure it out yet. The camera token works, but it changes every 5 minutes, so I was hoping to be able to use a long lived one to pull into frigate for some object detection.

@broyuken1
Did you figure this out in the end?

No, I gave up on it. Iā€™ll give it another shot when I replace my cameras with something local instead of ring

without nodered:

service: notify.notify
data:
  title: Centralina Allarme
  message: >-
    test
  data:
    ttl: 0
    priority: high
    image: >-
      /api/camera_proxy/camera.camera_hub_g3_120c?token={{state_attr('camera.camera_hub_g3_120c',
      'access_token') }}
    clickAction: >-
      /api/camera_proxy/camera.camera_hub_g3_120c?token={{state_attr('camera.camera_hub_g3_120c',
      'access_token') }}

i love you, i was looking for this for sooo long.

it work perfect. thanks!

Is it possible to proxy the live video stream from home assistant externally to something like VLC?

Je suis aussi intƩressƩ par ce dernier point

I have an automation setup that sends a snapshot from a camera and Iā€™m trying to give an option to open a live stream of the camera. It works when Iā€™m connected to the network, but when on cellular, Safari opens a blank page. Any ideas? Below is my yaml for the notification. Thanks

service: notify.mobile_app_guyans_iphone
data:
  message: Someone rang the doorbell
  data:
    image: /local/tmp/snapshot-doorbell.jpg
    actions:
      - action: View Live Video
        title: View Live Video
        uri: >-
          /api/camera_proxy_stream/camera.doorbell?token={{state_attr('camera.doorbell','access_token')
          }}
enabled: true