# Volume slider for Node-red Dashboard

**URL:** <https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188>\
**Category:** Dashboard\
**Created:** [11 January 2020 07:52 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188 "2020-01-11T07:52:58Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 07:52 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/1 "2020-01-11T07:52:58Z")

</div>

Hello,

I am very new here and I have just registered to solve my problem. I want to use Node-RED in order to control Kodi. I am able to control play-pause with this code: {"jsonrpc": "2.0", "method": "Player.PlayPause", "params": { "playerid": 1 }, "id": 1}

I am doing well with this code: { "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": "increment" }, "id": 1 } However, obviously, it is always increasing even my slider decreasing.

I want to use a slider to increase or decrease volume, but I couldn't find any solution, and I stuck! Can anyone help me?

---

<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:** [11 January 2020 08:12 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/2 "2020-01-11T08:12:53Z")

</div>

I am pretty sure the API has a setvolume capability, have you looked at the API spec?

---

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 13:41 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/3 "2020-01-11T13:41:03Z")

</div>

Hello Colin,

Yes I have already check the API but i couldn't realize how to write-identify slider value in the code. There is a suggestion like this:

{ "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": '$VALUE' }, "id": 1 }

how can I write the $Value of slider in this code? I couldn't understand variable writing in Node-Red is there any example or document (the document that explains as much as clear and basic level)

I am really new on Node-Red. Thank you for your understanding and quick reply.

Best wishes!

---

<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:** [11 January 2020 14:01 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/4 "2020-01-11T14:01:55Z")

</div>

The message from the slider will have the value in msg.payload. Is the jsonrpc message you have shown a string or a javascript object? If it is a string then you can, for example, use a template (not ui\_template), node to insert the payload. How to do that is described in the info panel for that node, Alternatively, in a function node, you could do

```auto
msg.whatever = `{ "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": ${msg.payload}, "id": 1 }`

```

If you are generating a javascript object then you can say, if the object is in a variable called myvariable, something like

```auto
myvariable.parms = {volume: msg.payload}

```

If you can't get it to work show us how you are creating the api object.

---

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 14:52 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/5 "2020-01-11T14:52:38Z")

</div>

Hello Colin

I am really thankful of your patience, sorry for my dumbness. For 2 days and nights I am trying to solve the problem but everything got mixed time by time...

```auto
[{"id":"9df3623e.2b5ee","type":"ui_slider","z":"4d0eb8d4.1912b8","name":"","label":"slider","tooltip":"","group":"2f101410.857cfc","order":3,"width":"4","height":"1","passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":1,"x":441.02081298828125,"y":396.4444274902344,"wires":[["87f99022.ff577"]],"info":"var Value = { payload: msg.payload };\r\nreturn Value;"},{"id":"2f101410.857cfc","type":"ui_group","z":"","name":"Group 7","tab":"743f23a2.ece61c","order":7,"disp":true,"width":"23","collapse":false},{"id":"743f23a2.ece61c","type":"ui_tab","z":"","name":"R10 Dome","icon":"home","order":1,"disabled":false,"hidden":false}]

```

This is Kodi related code with the slider bar. I can send you if you want to see all the flow, but they are related to my smart home modules.

I will focus on your message now. Additionally, I really don't understand js programming, it is looking very mixed for me...

---

<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:** [11 January 2020 15:46 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/6 "2020-01-11T15:46:14Z")

</div>

I need to see how you are generating the increment/decrement message, you don't seem to have posted that node. That is all I need, then it can be modified to do volume set rather than inc/dec.

---

<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:** [11 January 2020 15:59 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/8 "2020-01-11T15:59:10Z")

</div>

OK, I understand the confusion now, you are just setting that in the Kodi node.  
What is the full name of the module/node you have installed to get the kodi node? Probably node-red-contrib-something.

---

<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:** [11 January 2020 16:06 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/9 "2020-01-11T16:06:56Z")

</div>

Having had a search I guess it is node-red-contrib-kodi. If you look at the information tab for it you can see that you can pass it a javascript object, so if you feed your slider into a function node containing the code below and pass that on to the kodi node it should work

```auto
msg.payload = { jsonrpc: "2.0", method: "Application.SetVolume", params: { volume: msg.payload, id: 1 }
return msg

```

---

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 16:26 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/10 "2020-01-11T16:26:33Z")

</div>

Thank you Colin, I am trying to work with your advices. It is not working so far but I will keep try. Also, I will let you know the result. I hope I can do that! 🙂

,Sorry, I have just seen your previous entry, yes it is node-red-contrib-kodi. Also, It is still not working. I don't understand where I am wrong..

---

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 16:43 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/11 "2020-01-11T16:43:15Z")

</div>

Hello again,

Thank you very much of your advices. I had a small step forward by you. However, I can see the results with text node, I can see the volume values but there is error again, server is not recognize the volume. According to node-red-contrib-kodi example, there should not a command in kodi-in node. I don't understand where I am missing. I also have used your previous advice as

```auto
{ "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": ${msg.payload}, "id": 1 }

```

but no result...

---

<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:** [11 January 2020 17:01 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/12 "2020-01-11T17:01:42Z")

</div>

Does it work if you put the jsonrpc command directly into the kodi node but with a number instead of the slider value?  
If so then if you put a debug node on the output of the Function node what does it show as you move the slider?

---

<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:** [11 January 2020 17:16 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/14 "2020-01-11T17:16:44Z")

</div>

Where did I say to do that? I said to use a function node. Go back and read my message again. However I don't know where you got the syntax for the structure. It does not look like that in the example flow on the node's home page. I suggest you import that flow and see what it is doing.

> **[node-red-contrib-kodi](https://flows.nodered.org/node/node-red-contrib-kodi)**
>
> Node-RED nodes for communicating with a Kodi (former XBMC).

---

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 17:19 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/15 "2020-01-11T17:19:41Z")

</div>

> [@Colin](#):
>
> Having had a search I guess it is node-red-contrib-kodi. If you look at the information tab for it you can see that you can pass it a javascript object, so if you feed your slider into a function node containing the code below and pass that on to the kodi node it should work

I already did this. But I think I have misunderstood here "Does it work if you put the jsonrpc command directly into the kodi node but with a number instead of the slider value?" sorry about that. I will try your last advice. Thank you very much.

---

<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:** [11 January 2020 17:29 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/16 "2020-01-11T17:29:29Z")

</div>

> [@konrul](#):
>
> I already did this

OK, I hadn't looked at the flow, I was going on the description.  
Firstly I don't understand what a Kiodi In node has got to do with it.  
Secondly the output of the function node has got to go to the Kodi Out node.  
However, as I said in the last post, looking at the example flow it does not look as if you have the correct structure for the command.

---

<div class="post-metadata">

**Author:** ![konrul](https://avatars.discourse-cdn.com/v4/letter/k/b19c9b/32.png) [@konrul](https://discourse.nodered.org/u/konrul)\
**Post date:** [11 January 2020 17:31 UTC](https://discourse.nodered.org/t/volume-slider-for-node-red-dashboard/20188/17 "2020-01-11T17:31:51Z")

</div>

Hello Colin,

Problem solved!

```auto
msg.payload = { "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": msg.payload }, "id": 1 }
return msg

```

I wrote the first code

```auto
{ "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": "increment" }, "id": 1 }

```

This gave me result. Then I have change "increment" with your code, like this:

```auto
msg.payload = { "jsonrpc": "2.0", "method": "Application.SetVolume", "params": { "volume": msg.payload }, "id": 1 }
return msg

```

Then it has worked. Thank you very much for your patience, efforts, and kindness!
