# Http request for web relay

**URL:** <https://discourse.nodered.org/t/http-request-for-web-relay/94130>\
**Category:** General\
**Tags:** http-request\
**Created:** [24 December 2024 00:59 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130 "2024-12-24T00:59:04Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Democrat5](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Democrat5](https://discourse.nodered.org/u/Democrat5)\
**Post date:** [24 December 2024 00:59 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/1 "2024-12-24T00:59:04Z")

</div>

i am new to this and trying to use a http request to get the status of a multi 8-ch web relay.  
i get the below and the "output" is what i am interested in "10010100" one digit per relay first digit is 1 so the relay is on second digit is 0 relay 2 is off and so on. i want to split all 8 digits into there own output to turn a led on on the dashboard or get a true or false for each relay. how or what would be the best way for me to do what i am looking to do?

msg.payload : Object  
object  
cmd: "state"  
output: "10010100"  
input: "00000100"  
sn: "618e79"

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [24 December 2024 04:40 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/2 "2024-12-24T04:40:21Z")

</div>

There’s a great page in the docs ([Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

> [@Democrat5](#):
>
> i am new to this

I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

---

<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:** [24 December 2024 09:04 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/3 "2024-12-24T09:04:42Z")

</div>

> [@Democrat5](#):
>
> how or what would be the best way for me to do what i am looking to do?

As you are new start with low code methods, as you advance and feel more confident you can introduce code.  
here is a low code example, but take Steve's advise and watch the essential videos.

```auto
[{"id":"f916b186a40d0ca1","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload.output","v":"10010100","vt":"str"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":7540,"wires":[["7e19471fa95e50e1"]]},{"id":"7e19471fa95e50e1","type":"split","z":"d1395164b4eec73e","name":"","splt":"1","spltType":"len","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","property":"payload.output","x":350,"y":7540,"wires":[["da7d9d98a29c3151","24e9e6c7ef8caee9"]]},{"id":"da7d9d98a29c3151","type":"switch","z":"d1395164b4eec73e","name":"","property":"payload.output","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"0","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":470,"y":7540,"wires":[["4c6218d6960c47ca"],["bac4a41f2fe99b7d"]]},{"id":"24e9e6c7ef8caee9","type":"debug","z":"d1395164b4eec73e","name":"lsee full message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":464.2021179199219,"y":7489.7333984375,"wires":[]},{"id":"4c6218d6960c47ca","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":7520,"wires":[["c4a9adb6ee24b8e7"]]},{"id":"bac4a41f2fe99b7d","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":7560,"wires":[["c4a9adb6ee24b8e7"]]},{"id":"c4a9adb6ee24b8e7","type":"switch","z":"d1395164b4eec73e","name":"","property":"parts.index","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"false","repair":false,"outputs":3,"x":490,"y":7660,"wires":[["958cf7df0bfeaa37"],["a80d474f6bde337d"],["63328b91ba3adb0a"]]},{"id":"958cf7df0bfeaa37","type":"debug","z":"d1395164b4eec73e","name":"led 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":7640,"wires":[]},{"id":"a80d474f6bde337d","type":"debug","z":"d1395164b4eec73e","name":"led 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":7680,"wires":[]},{"id":"63328b91ba3adb0a","type":"debug","z":"d1395164b4eec73e","name":"led 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":630,"y":7720,"wires":[]}]

```

[How to import/export a flow](https://nodered.org/docs/user-guide/editor/workspace/import-export)

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [24 December 2024 09:46 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/4 "2024-12-24T09:46:49Z")

</div>

> [@Democrat5](#):
>
> output: "10010100"

The others have said how to get to the data you want but not how to split that data into the individual digits.

Because the data is a STRING, you can use JavaScript in a function node to split - something like:

```auto
msg.relayStatus = msg.payload.output.split('')
return msg

```

Which gives you the split data that looks like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/b/1bcce6076ffe73a0a9fe4550c6029d58a2f06ea0.png)

The status of relay 1 would be `msg.relayStatus[0]`

---

<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:** [24 December 2024 09:57 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/5 "2024-12-24T09:57:53Z")

</div>

> [@TotallyInformation](#):
>
> The others have said how to get to the data you want but not how to split that data into the individual digits.

I beleive my flow shows how to -

> [@Democrat5](#):
>
> i want to split all 8 digits into there own output to turn a led on on the dashboard or get a true or false for each relay

---

<div class="post-metadata">

**Author:** ![Democrat5](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Democrat5](https://discourse.nodered.org/u/Democrat5)\
**Post date:** [24 December 2024 21:42 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/6 "2024-12-24T21:42:59Z")

</div>

I could not get any of this to work.  
TotallyInformation just gave me the same output.  
E1cid i am not sure about any of this.  
i was able to get it into a array but still do not know if this will help me get to the end goal.  
msg.payload : array[8]  
array[8]  
0: "1"  
1: "0"  
2: "0"  
3: "0"  
4: "0"  
5: "1"  
6: "0"  
7: "0"

and i can a path of payload[0],payload[1],,, out of that

relay 0 and 5 is on.  
i will try reading more and go from there.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 December 2024 23:08 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/7 "2024-12-24T23:08:32Z")

</div>

You could do something like this:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/8/f8db52aec87184d129c171e81afa02a56018ad31.png)

in a function node:

```auto
const states = []
function checkRelays(state) {
    
    for (let i = 0; i < state.length; i++) {
        const relayState = state[i] === '1' ? true : false;
        states.push({payload:relayState})
    }
}

const input = checkRelays(msg.payload)

return [...states]

```

example flow:

```auto
[{"id":"256efbf179ac9630","type":"inject","z":"c8d44844ba5acdbd","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10010100","payloadType":"str","x":540,"y":3920,"wires":[["e1447b35ef93b036"]]},{"id":"4ef253c26a0aa929","type":"debug","z":"c8d44844ba5acdbd","name":"debug 670","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":3800,"wires":[]},{"id":"e1447b35ef93b036","type":"function","z":"c8d44844ba5acdbd","name":"function 312","func":"const states = []\nfunction checkRelays(state) {\n \n for (let i = 0; i < state.length; i++) {\n const relayState = state[i] === '1' ? true : false;\n states.push({payload:relayState})\n }\n}\n\nconst input = checkRelays(msg.payload)\n\nreturn [...states]","outputs":8,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":730,"y":3920,"wires":[["4ef253c26a0aa929"],["a5d8b089ba2a42ea"],["5a7e2b01179f6f96"],["ada2265851f99f40"],["161b03708cfe9666"],["20cb51b2f2bd0ace"],["1e9e1d8ae17ca8ef"],["34e2304bd12fd1a2"]]},{"id":"a5d8b089ba2a42ea","type":"debug","z":"c8d44844ba5acdbd","name":"debug 671","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":3840,"wires":[]},{"id":"5a7e2b01179f6f96","type":"debug","z":"c8d44844ba5acdbd","name":"debug 672","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":3880,"wires":[]},{"id":"ada2265851f99f40","type":"debug","z":"c8d44844ba5acdbd","name":"debug 673","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":3920,"wires":[]},{"id":"161b03708cfe9666","type":"debug","z":"c8d44844ba5acdbd","name":"debug 674","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":3960,"wires":[]},{"id":"20cb51b2f2bd0ace","type":"debug","z":"c8d44844ba5acdbd","name":"debug 675","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":4000,"wires":[]},{"id":"1e9e1d8ae17ca8ef","type":"debug","z":"c8d44844ba5acdbd","name":"debug 676","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":4040,"wires":[]},{"id":"34e2304bd12fd1a2","type":"debug","z":"c8d44844ba5acdbd","name":"debug 677","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":4080,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Democrat5](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Democrat5](https://discourse.nodered.org/u/Democrat5)\
**Post date:** [24 December 2024 23:26 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/8 "2024-12-24T23:26:48Z")

</div>

bakman2  
Yes, that did it Thank you.  
Thank you everyone for your help and merry Christmas.  
I am new and this looks to be a powerful thing and it is great to have a place where everyone helps with what they can. I still have a lot to learn.

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [24 December 2024 23:38 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/9 "2024-12-24T23:38:18Z")

</div>

Come to think of it; it could even be a one-liner:

```auto
return [...msg.payload.split("").map(x => x == '1' ? {payload:true} : {payload:false})]

```

---

<div class="post-metadata">

**Author:** ![Democrat5](https://avatars.discourse-cdn.com/v4/letter/d/ac91a4/32.png) [@Democrat5](https://discourse.nodered.org/u/Democrat5)\
**Post date:** [24 December 2024 23:45 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/10 "2024-12-24T23:45:44Z")

</div>

yes, that works as well.

---

<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:** [24 March 2025 23:46 UTC](https://discourse.nodered.org/t/http-request-for-web-relay/94130/11 "2025-03-24T23:46:35Z")

</div>

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