# HTTP response based on last status of variable

**URL:** <https://discourse.nodered.org/t/http-response-based-on-last-status-of-variable/36771>\
**Category:** General\
**Created:** [30 November 2020 20:08 UTC](https://discourse.nodered.org/t/http-response-based-on-last-status-of-variable/36771 "2020-11-30T20:08:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![oliver.es](https://avatars.discourse-cdn.com/v4/letter/o/dc4da7/32.png) [@oliver.es](https://discourse.nodered.org/u/oliver.es)\
**Post date:** [30 November 2020 20:08 UTC](https://discourse.nodered.org/t/http-response-based-on-last-status-of-variable/36771/1 "2020-11-30T20:08:23Z")

</div>

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:

```auto
object
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.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2020 21:28 UTC](https://discourse.nodered.org/t/http-response-based-on-last-status-of-variable/36771/2 "2020-11-30T21:28:03Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![oliver.es](https://avatars.discourse-cdn.com/v4/letter/o/dc4da7/32.png) [@oliver.es](https://discourse.nodered.org/u/oliver.es)\
**Post date:** [30 November 2020 22:20 UTC](https://discourse.nodered.org/t/http-response-based-on-last-status-of-variable/36771/3 "2020-11-30T22:20:05Z")

</div>

Thank you. Your solution is interesting because of "if" statement. I was resolved my question with [https://cookbook.nodered.org/http/include-data-from-another-flow](https://cookbook.nodered.org/http/include-data-from-another-flow)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [14 December 2020 22:20 UTC](https://discourse.nodered.org/t/http-response-based-on-last-status-of-variable/36771/4 "2020-12-14T22:20:06Z")

</div>

Closed on 14 December 2020 22:20 UTC

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