Receive lan webhook with camera snapshot (surveillance station) in home assistant

Hi all

I'm struggling to workout how to get node red to receive a webhook notification from surveillance station with snapshot . I have found several node pallets but they seem to be for wan

Has anyone set this up or something similar they can share ?

Thank you

A webhook simply calls an HTTP endpoint.

node-red can do endpoints: Node-RED Cookbook : Node-RED

Thank you. I'll just have to workout how to process the snapshot . I have other notifications working with snapshots but that's from my doorbell.

So I know how to setup surveillence station to post to a url:

I see http in - it says it's relevant to /endpoint - i'm not sure where the endpoint is configured.

what sort of response would i need to send? a 200 success?

thank you for the help

You mean relative - as in related.

e.g. - if your node-red editor is at http://192.168.0.2:1880 then /motion_porch (as a relative URL) would be at http://192.168.0.2:1880/motion_porch

Probably - but that happens automatically.

To see what is going on, simply return the HTTP request and view what was sent using a debug node...
image

1 Like

Thank you very much. I should be able to get this going now.

i'm running node red within home assistant (add on). So i am using my home assistant URL though that is not working as i'm guessing it's expecting auth.

do you know how I can get it auth'd? would it be via long lived auth token? I see node red has one already to access home assistant. so not sure how to access it

thank you again

I believe HA adds a slug to the path - open the HTTP-IN node settings editor, I think there is a tooltip or info comment on the edit panel telling you the URL to use

not that I can see

payload
For a GET request, contains an object of any query string parameters. Otherwise, contains the body of the HTTP request.
reqobject
An HTTP request object. This object contains multiple properties that provide information about the request.

  • body - the body of the incoming request. The format will depend on the request.
  • headers - an object containing the HTTP request headers.
  • query - an object containing any query string parameters.
  • params - an object containing any route parameters.
  • cookies - an object containing the cookies for the request.
  • files - if enabled within the node, an object containing any files uploaded as part of a POST request.

resobject
An HTTP response object. This property should not be used directly; the HTTP Response node documents how to respond to a request. This property must remain attached to the message passed to the response node.

Details

The node will listen on the configured path for requests of a particular type. The path can be fully specified, such as /user, or include named parameters that accept any value, such as /user/:name. When named parameters are used, their actual value in a request can be accessed under msg.req.params.

For requests that include a body, such as a POST or PUT, the contents of the request is made available as msg.payload.

If the content type of the request can be determined, the body will be parsed to any appropriate type. For example, application/json will be parsed to its JavaScript object representation.

Note: this node does not send any response to the request. The flow must include an HTTP Response node to complete the request.

Notificationdebug 5

Found this thread and going through it now: HTTP In URL when using Node Red with HASS Supervisor - Node-RED - Home Assistant Community but i think i'll be stuck on auth

That is the help info. I said on the edit dialog. scratch that, I just spotted your earlier screenshot...

So that means your URL would be http://192.168.0.2:1880/endpoint/motion_porch


PS: It is always helpful to mention "home assistant" in your post (as often the answer is different)

1 Like

Hmm i've tried with and without user/pass on the url and the web request from surveillance station (test) is failing.

http://user:password@192.168.0.2:1880/endpoint/porch ( set it as /porch and porch on the http in) and yeah failing hmm .

once i've got this working this will bring a lot of powerful options. but it aint easy :slight_smile:

Is that IP address actually the IP of your node-red server? I wrote that as a demo URL

No I am changing it when posting here . I am using correct ip address .

However it's my home assistant ip address thag could be the issue. I don't know how to get my node red server address. As it's within home assistant (supervised add on on virtual machine in Synology)

Understand. However, the IP address of the device is likely different to the internal IP address inside the container. You might have to head over to the HA forums for advice.

I have Node Red on a raspberry pi +B accessing a raspberry pi Zero W bearing a picamera 2 running MotionEYE which displays the static image of initial movement in Video as well as the video the ui Dashboard. If you think my experience would assist, I'll put up some more information.

Oh my yes please do. My end goal is to have access to the alert snapshot. As they are just emailed to me now. And also to use it in notification actions.
Is your node red running on supervisor?
Thank you

Node red not running on supervisor.

A Call to a Web Hook can be set in MotionEYE either in the Motion Notifications or the File Storage settings.

image

Note the addition of ?%f to the webhook. This has the effect of appending the file name to the url. In m case it has a unique date and time of the recording.

In Node Red
image

For Static image of initial movement in Video
http://192.168.1.22:8765/movie/1/preview/*plus_unique_date/and_time.mp4*

For Video
http://192.168.1.22:8765/movie/1/playback/*plus_unique_date/and_time.mp4*

For pictures
http://192.168.1.22:8765/picture/1/preview/*plus_unique_date/and_time.mpg*

The output from the Web Hook can be used for finding the unique name of the image or video, so that it can be appended to the playback http address. This can be done using JSONATA in a Change node

e.g. For pictures the msg.payload from Http request, an Http In (set to POST and url /webhookfile) is set to the value in a Change node
$replace(req._parsedUrl.query,"/var/lib/motioneye/Camera1","http://192.168.n.n:8765/picture/1/preview")

and for the Static image of initial movement

$replace(req._parsedUrl.query,"/var/lib/motioneye/Camera1","http://192.168.n.n:8765/movie/1/preview")

On my pi MotionEYE stores the images at "/var/lib/motioneye/Camera1", but yours may be at a different location.

image

an Http request can then be made to download an image or mp4.

You will need node-red-node-base64

The ui_template can be used for displaying a static image

In Summary: An Http Request (set to: GET, and payload as Send as request body, with Return as a binary buffer) is processed by Base64 (Action : Encode as Base64) and output in a ui Template (set to: Reload last value on refresh - so that the image persists in the dashboard on refresh). Using the following Template

<style>

    img{

        object-fit:contain;

    }

</style>



<img src="data:image/png;base64,{{msg.payload}}" />

the image fills the desired grid pattern set by Size.

Just noticed I have inconsistencies in the above please ignore the Webhook is sometimes denoted as Webhook_img....so long as they are the same in MotionEYE and on Node red they can be called whatever you wish.

I have the template displaying the static picture which when clicked displays the video so contains additional code.

<style>
    img {
        object-fit: contain;
    }
</style>

<img src = "data:image/png;base64,{{msg.payload}}" ng-hide = "showToggle" ng-click = "send({payload:msg.vid});showToggle=!showToggle" />

<video controls id="video" width="100%" heigth="100%" playsinline poster ></video>

<script>
    (function(scope) {
        // Watch for messages being send to this template node
        scope.$watch('msg', function (msg) {      
            if (msg) {
                var video = document.getElementById('video');
                video.src = msg.payload;
                video.play();
            }       
         }); 
    })(scope); 
</script>
1 Like

thank you so much - this will be a massive help once I workout how to call node red on supervisor within home assistant. i really appreciate it.

I just had to use the default node red port and it worked. entered my ha creds .bingo!

now I just have to work out how to auth into node red. i am not getting test failed but now auth failed. Using the format http://user:pass@192.168.1.1:1880 gives failed auth.

I am running node red in supervisor - and i'm not sure how to get access to settings.js to edit the http auth settings.