Volume slider for Node-red Dashboard

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?

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.

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?

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