# Pioneer vsx 921

**URL:** <https://discourse.nodered.org/t/pioneer-vsx-921/2239>\
**Category:** General\
**Created:** [12 August 2018 18:22 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239 "2018-08-12T18:22:23Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [12 August 2018 18:22 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/1 "2018-08-12T18:22:23Z")

</div>

Hello i have an Pioneer VSX 921 and i have a flow that i can control it.  
But i want a button on ex dashboard to turn up or down volume 10 notches. but when i get value from receiver it wont work in function with if this. what to do?

`[{"id":"6c0f88c4.2e46b8","type":"inject","z":"4e99ff3b.00121","name":"","topic":"Get Volume","payload":"?V","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":144.2857208251953,"y":304.2857313156128,"wires":[["a8ebbabd.1af658"]]},{"id":"c4ddf455.155238","type":"inject","z":"4e99ff3b.00121","name":"","topic":"Volume Up","payload":"VU","payloadType":"str","repeat":"","crontab":"","once":false,"x":129.71428680419922,"y":366.57142639160156,"wires":[["a8ebbabd.1af658"]]},{"id":"8ea0f05f.1b573","type":"inject","z":"4e99ff3b.00121","name":"","topic":"Volume Down","payload":"VD","payloadType":"str","repeat":"","crontab":"","once":false,"x":120.71428680419922,"y":411.57142639160156,"wires":[["a8ebbabd.1af658"]]},{"id":"a8ebbabd.1af658","type":"function","z":"4e99ff3b.00121","name":"Add <CR>","func":"msg.payload = msg.payload + '\\r';\n\nreturn msg;","outputs":1,"noerr":0,"x":364.8571357727051,"y":352.42857933044434,"wires":[["2a2a105c.47aa9"]]},{"id":"2a2a105c.47aa9","type":"tcp request","z":"4e99ff3b.00121","server":"192.168.1.7","port":"23","out":"time","splitc":"10","name":"Pioneer SCLX56 ","x":541.7143478393555,"y":353.42856311798096,"wires":[["d06c35dc.6b1e88"]]},{"id":"d06c35dc.6b1e88","type":"function","z":"4e99ff3b.00121","name":"Convert to String","func":"msg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"x":751.71435546875,"y":358.71427726745605,"wires":[["c7644439.6b3478","e77165d5.6e7348"]]},{"id":"c7644439.6b3478","type":"debug","z":"4e99ff3b.00121","name":"","active":true,"console":"false","complete":"payload","x":958.2857055664062,"y":314.00000762939453,"wires":[]},{"id":"e77165d5.6e7348","type":"function","z":"4e99ff3b.00121","name":"This doesn´t work","func":"if(msg.payload === \"VOL081\"){\n //then do this.\n //this is where it stops\n msg.payload = \"hh\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":937.1428871154785,"y":424.2856864929199,"wires":[["c7644439.6b3478"]]},{"id":"a26b82a5.dd0e3","type":"comment","z":"4e99ff3b.00121","name":"Info about the flow","info":"When i press Get Volume it gets EX VOL081 in \ndebug, from Convert to string function.\nbut the if this function wont read it","x":506.4285774230957,"y":85.71429347991943,"wires":[]}]`

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 August 2018 21:00 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/2 "2018-08-12T21:00:50Z")

</div>

For some reason your flow won't import (for me anyway). Did you use the Export to clipboard feature to get it and then paste it here? Have you got a line with three backticks before it and after it in the message?

However, if you have a function node that is not working as you expect (if that is the situation, I am not sure) then first use a debug node to show the data going into the function node and one showing what is coming out of the function node. If you still cannot work out the problem then show us the data going in and paste just the function node here.

---

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [12 August 2018 22:21 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/3 "2018-08-12T22:21:54Z")

</div>

```
[{"id":"4e99ff3b.00121","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"6c0f88c4.2e46b8","type":"inject","z":"4e99ff3b.00121","name":"","topic":"Get Volume","payload":"?V","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":"","x":144.2857208251953,"y":304.2857313156128,"wires":[["a8ebbabd.1af658"]]},{"id":"c4ddf455.155238","type":"inject","z":"4e99ff3b.00121","name":"","topic":"Volume Up","payload":"VU","payloadType":"str","repeat":"","crontab":"","once":false,"x":129.71428680419922,"y":366.57142639160156,"wires":[["a8ebbabd.1af658"]]},{"id":"8ea0f05f.1b573","type":"inject","z":"4e99ff3b.00121","name":"","topic":"Volume Down","payload":"VD","payloadType":"str","repeat":"","crontab":"","once":false,"x":120.71428680419922,"y":411.57142639160156,"wires":[["a8ebbabd.1af658"]]},{"id":"a8ebbabd.1af658","type":"function","z":"4e99ff3b.00121","name":"Add <CR>","func":"msg.payload = msg.payload + '\\r';\n\nreturn msg;","outputs":1,"noerr":0,"x":364.8571357727051,"y":352.42857933044434,"wires":[["2a2a105c.47aa9"]]},{"id":"2a2a105c.47aa9","type":"tcp request","z":"4e99ff3b.00121","server":"192.168.1.7","port":"23","out":"time","splitc":"10","name":"Pioneer SCLX56 ","x":541.7143478393555,"y":353.42856311798096,"wires":[["d06c35dc.6b1e88"]]},{"id":"d06c35dc.6b1e88","type":"function","z":"4e99ff3b.00121","name":"Convert to String","func":"msg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"x":751.71435546875,"y":358.71427726745605,"wires":[["c7644439.6b3478","e77165d5.6e7348"]]},{"id":"c7644439.6b3478","type":"debug","z":"4e99ff3b.00121","name":"","active":true,"console":"false","complete":"payload","x":958.2857055664062,"y":314.00000762939453,"wires":[]},{"id":"e77165d5.6e7348","type":"function","z":"4e99ff3b.00121","name":"This doesn´t work","func":"if(msg.payload === \"VOL081\"){\n //then do this.\n //this is where it stops\n msg.payload = \"hh\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":937.1428871154785,"y":424.2856864929199,"wires":[["c7644439.6b3478"]]},{"id":"a26b82a5.dd0e3","type":"comment","z":"4e99ff3b.00121","name":"Info about the flow","info":"When i press Get Volume it gets EX VOL081 in \ndebug, from Convert to string function.\nbut the if this function wont read it","x":506.4285774230957,"y":85.71429347991943,"wires":[]}]
```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [12 August 2018 23:06 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/4 "2018-08-12T23:06:31Z")

</div>

As @Colin said, I don't have a Pioneer VSX 921 but we still can help you.

Put a debug node (set to display the complete msg object) at the output of the Pioneer SCLX56 node and show us what it produces. That way someone could mimic that data and feed it into the rest of your flow to see what the results are.

I would also have two debug nodes, one for the Convert to String function and one for the 'This doesn't work' function to allow you to determine which node the debug message is coming from.

---

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [13 August 2018 00:00 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/5 "2018-08-13T00:00:39Z")

</div>

Here is from the pioneer node.  
{"\_msgid":"71c05bed.6ac724","topic":"Get Volume","payload":[86,79,76,48,56,49,13,10]}

convert to string node.

[86,79,76,48,56,49,13,10]

and the this does not work node nothing shows up

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 August 2018 08:04 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/6 "2018-08-13T08:04:30Z")

</div>

Ok, that says that the data you are betting backfrom the TCP node is not a buffer but a string array. Try this, first change the msg.payload to a buffer then to a string, so change your 'Convert to String' function to this:

```auto
msg.payload = Buffer.from(msg.payload);
msg.payload = msg.payload.toString();
return msg;

```

and see what you get

---

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [13 August 2018 09:21 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/7 "2018-08-13T09:21:33Z")

</div>

First two is from the Convert to string node and the "This does not work".  
The last is from the TCP node.

![35](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/243fe8aaf7d9c315d53a303c90f3c0703e353a4a.png)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [13 August 2018 09:56 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/8 "2018-08-13T09:56:29Z")

</div>

So with 1 & 2 you have a string that contains the current volume setting

Assuming you want to display on a slider in the dashboard you can easily strip off the VOL and the carriage return.

---

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [13 August 2018 10:09 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/9 "2018-08-13T10:09:18Z")

</div>

Yes but the string wont work in the function. That is the problem

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 August 2018 10:26 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/10 "2018-08-13T10:26:36Z")

</div>

> [@Steffen](#):
>
> Yes but the string wont work in the function. That is the problem

Which string? The debugs you show look fine, so what won't work? Give us a step by step of what is happening and what you want/expect to happen.

---

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [13 August 2018 10:29 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/11 "2018-08-13T10:29:48Z")

</div>

I want to use the string ex VOL081 in an if this in the function so i controll the volume with the function

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 August 2018 10:35 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/12 "2018-08-13T10:35:05Z")

</div>

Ok, so your IF statement `if (msg.payload === "VOL081")` doesn't work which means that msg.payload coes not contain the **exact** value 'VOL081'. Look at the results of the debug nodes and tell me why they don't match **exactly**.

---

<div class="post-metadata">

**Author:** ![Steffen](https://avatars.discourse-cdn.com/v4/letter/s/df788c/32.png) [@Steffen](https://discourse.nodered.org/u/Steffen)\
**Post date:** [13 August 2018 12:18 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/13 "2018-08-13T12:18:43Z")

</div>

I have tried "VOL081↵" which is displayed in the debug also.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [13 August 2018 15:29 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/14 "2018-08-13T15:29:30Z")

</div>

If you look at the debug of the buffer, you have 8 items, but "VOL081' is only 6. Comparinge something that is 6 in length againse something that is 8 in length is going to result in a not equal condition.

I would grab the first 6 characters of the msg.payload before doing the compare.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [13 August 2018 15:38 UTC](https://discourse.nodered.org/t/pioneer-vsx-921/2239/15 "2018-08-13T15:38:40Z")

</div>

Aha, good catch Paul... those last two characters are CR/NL

Before doing the comparison, you could try to use the trim function:

```auto
if (msg.payload.trim() === "VOL081")

```
