Volume slider for Node-red Dashboard


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?

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

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!

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

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

myvariable.parms = {volume: msg.payload}

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

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...

[{"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...

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.

Hello again,

this is for increment

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

and this is for decrement

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

but these are good for buttons. Not for the slider.

Edit: this is the flow related to above (for increment)

[{"id":"ad6c62e7.8067","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"a1487f72.f453f","type":"kodi-out","z":"ad6c62e7.8067","name":"","controller":"1347a145.c0d54f","unit_number":"1","output":"1","kodicommand":"{ \"jsonrpc\": \"2.0\", \"method\": \"Application.SetVolume\", \"params\": { \"volume\": \"increment\" }, \"id\": 1 }","x":985.017333984375,"y":259.0104064941406,"wires":[]},{"id":"14399831.26cd98","type":"inject","z":"ad6c62e7.8067","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":483.01720428466797,"y":471.3541564941406,"wires":[["a1487f72.f453f"]]},{"id":"1347a145.c0d54f","type":"kodi-controller","z":"","name":"kodi","host":"","port":"1010"}]

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.

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

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

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! :slight_smile:

,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..

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

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

but no result...

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?

I put this code:

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

into kodi-in node

and I got these messages in debug

11.01.2020 20:04:37node: kodi
msg : string[72]
"error calling send: TypeError: Cannot read property 'apply' of undefined"
11.01.2020 20:04:37node: kodi
msg : string[64]
"send error: TypeError: Cannot read property 'apply' of undefined"

here is the flow if there is any help to ease sloution

[{"id":"ad6c62e7.8067","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"5fdc8037.dec71","type":"kodi-out","z":"ad6c62e7.8067","name":"","controller":"1347a145.c0d54f","unit_number":"1","output":"1","kodicommand":"{ \"jsonrpc\": \"2.0\", \"method\": \"Application.SetVolume\", \"params\": { \"volume\": \"increment\" }, \"id\": 1 }","x":797.0035095214844,"y":306.0104064941406,"wires":[]},{"id":"468fbb98.bba5e4","type":"kodi-out","z":"ad6c62e7.8067","name":"","controller":"1347a145.c0d54f","unit_number":"1","output":"1","kodicommand":"{ \"jsonrpc\": \"2.0\", \"method\": \"Application.SetVolume\", \"params\": { \"volume\": \"decrement\" }, \"id\": 1 }","x":792.4374046325684,"y":384.2883253097534,"wires":[]},{"id":"47f64ebe.02fd","type":"ui_slider","z":"ad6c62e7.8067","name":"","label":"slider","tooltip":"","group":"2f101410.857cfc","order":3,"width":0,"height":0,"passthru":true,"outs":"all","topic":"","min":0,"max":"100","step":1,"x":249,"y":342.0000305175781,"wires":[["ab15656e.2678a8"]]},{"id":"c20892cb.47753","type":"kodi-out","z":"ad6c62e7.8067","name":"kodi","controller":"ed747e1e.90c9b","unit_number":"1","output":"1","kodicommand":"{ jsonrpc: \"2.0\", method: \"Application.SetVolume\", params: { volume: 89, id: 1 }}","x":797.9965476989746,"y":235.22931671142578,"wires":[]},{"id":"dff53e67.6e19b","type":"ui_text","z":"ad6c62e7.8067","group":"2f101410.857cfc","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":537.9965438842773,"y":203.7952938079834,"wires":[],"info":"{ \"jsonrpc\": \"2.0\", \"method\": \"Application.SetVolume\", \"params\": { \"volume\": ${msg.payload}, \"id\": 1 }`"},{"id":"ab15656e.2678a8","type":"function","z":"ad6c62e7.8067","name":"volume1","func":"msg.payload = { jsonrpc: \"2.0\", method: \"Application.SetVolume\", params: { volume: msg.payload, id: 1 }}\nreturn msg","outputs":1,"noerr":0,"x":405.9965515136719,"y":415.8194885253906,"wires":[["dff53e67.6e19b"]]},{"id":"bef75994.6f7a28","type":"inject","z":"ad6c62e7.8067","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":687.9930725097656,"y":177.57294464111328,"wires":[["c20892cb.47753"]]},{"id":"92546b0f.da65e8","type":"kodi-in","z":"ad6c62e7.8067","name":"","controller":"d202ce84.24c45","x":425.43748474121094,"y":576.3994674682617,"wires":[["d5fb37f2.da2af8","4ed15013.ad8cc"]]},{"id":"d5fb37f2.da2af8","type":"debug","z":"ad6c62e7.8067","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":625.4374847412109,"y":576.3994674682617,"wires":[]},{"id":"4ed15013.ad8cc","type":"ui_text","z":"ad6c62e7.8067","group":"2f101410.857cfc","order":2,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","x":555.0035552978516,"y":488.1253547668457,"wires":[]},{"id":"1347a145.c0d54f","type":"kodi-controller","z":"","name":"kodi","host":"","port":"1010"},{"id":"2f101410.857cfc","type":"ui_group","z":"","name":"Group 7","tab":"743f23a2.ece61c","order":7,"disp":true,"width":"23","collapse":false},{"id":"ed747e1e.90c9b","type":"kodi-controller","z":"","name":"kodi","host":"localhost","port":"9090"},{"id":"d202ce84.24c45","type":"kodi-controller","z":"","name":"kodi","host":"localhost","port":"9090"},{"id":"743f23a2.ece61c","type":"ui_tab","z":"","name":"R10 Dome","icon":"home","order":1,"disabled":false,"hidden":false}]

Thank you

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.

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.

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.

Hello Colin,

Problem solved!

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

I wrote the first code

{ "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:

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!

1 Like