HTTP response based on last status of variable

Hi, I'm trying to build little tricky flow for purpose as follows:

I have the Hikvision IP camera installed on door and this camera is sending alarm to Node-RED using hikvision-alarm-in when detect motion. In debug window I have:

code: "VideoMotion"
action: "Start"
index: 1
time: "2020-11-30T19:50:07.830Z"

Now I need to publish status "motion" or "idle" on HTTP endpoint that can be readable with javascript on another Raspberry Pi that displaying camera images and switching cameras based on motion event. This script is updating every 1 second, so I want to query NodeRED every 1 second via HTTP GET if the motion alarm from camera was recevied.

But I don't know how to switch variable status based on action: "Start" and "Stop" message received from Hikvision node and work with this status in HTTP response.

Thanks for your help.

So you want to convert the "Start" to "motion" and "Stop" to "Idle"
You could use a function or change node. Or even switch node and two possible routes.
Change node example

[{"id":"5cc60b28.f825bc","type":"change","z":"8d22ae29.7df6d","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.action = \"Start\" ? \"motion\" : \"idle\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":2880,"wires":[["39c1c718.e9731"]]},{"id":"39c1c718.e9731","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":2860,"wires":[]},{"id":"e0597e54.0f3c18","type":"inject","z":"8d22ae29.7df6d","name":"","props":[{"p":"payload.action","v":"Start","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":2880,"wires":[["5cc60b28.f825bc"]]}]

Thank you. Your solution is interesting because of "if" statement. I was resolved my question with

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.