0

RPC SetValue not working with a string variable

Gianluca Tozzi 4 years ago in Devices / Other updated 4 years ago 6

I followed the knowledge base example to change a boolean variable, and that's working.

This is the template:

https://RPC_username:RPC_password@server_ip_address/API/RPC/SetValue

{"objectName":"Devices\KNX\Light 1","valueName":"Value","value":"true"}

What if the variable is a string type?

{"objectName":"Devices\KNX\Light 1","valueName":"Value","value":"STRINGTEST"}

This command is not working.

Strange that if I try to write a value of "true" or "false" it is accepted!

Obviously the command should be different.  But I cannot find anywhere the correct sintax.


Please anyone has succeded in solving this problem?

Thank you.



 

Hi,

That's happening because in the above example, the variable (which is a true/false value) will only accept True or False text (it's a KNX Light, so it's not expecting other values rather than True or False).

First, you need to start using double slashes when writing the node path, as it's referred on the RPC documentation;


So your actual command should be something like:


{"objectName":"Devices\\KNX\\Light 1","valueName":"Value","value":"STRINGTEST"}

Second, make sure that the variable that you'll be using to receive the string, is actually a string variable. It's true that you can send the text True or False to a boolean variable. But if it's a string, make sure that the variable is actually a string, so it can receive any kind of text.

If you want to send a string to a value, you need to wrap the text in both " and '. Example (remove the spaces) " ' test ' "

I've created a string variable on my bOS, and sent a string from Tasker (Android app) by using the RPC, and it's working.

Hope it helps.

Best regards

Hi Ricardo,

your suggestions were right. Now it's working!

I needed to change a Bos string value with a Node-Red function.

As you told me I have to send a string surrounded at least by " ", it is working even if you don't surround with ' '.

So, I write the function node this way:

newvalue = "\"" + string + "\"";
msg.method = "POST";
msg.url = "msg.payload" class="redactor-autoparser-object">http://user:password@serverip/API/RPC/SetValue";
msg.payload
= {"objectName":"Tasks\\Messages\\msg1","valueName":"Value","value": newvalue};

and then send to an Http request node.

Thank you very much for your kind help Ricardo.

Hi Ricardo,

your suggestions were right.  Now it's working!

I needed to change a Bos string value with a Node-Red function.

As you told me I have to send a string surrounded at least by " ", it is working even if you don't surround with ' '.

So, I write the function node this way:

newvalue = "\"" + string + "\"";
msg.method = "POST";
msg.url = "msg.payload" class="redactor-autoparser-object">http://user:password@serverip/API/RPC/SetValue";
msg.payload
= {"objectName":"Tasks\\Messages\\msg1","valueName":"Value","value": newvalue};

and then send to an Http request node.

Thank you very much for your kind help Ricardo.

PS: The RPC documentation is a little bit oudated, and it actually doesn't refer the need to use the double slashes, but it does.


So if anyone is having troubles with RPC, please use the double \\ slashes when writing down the node path, as stated in my previous reply.

Best regards


Yep, documentation is "non existent", despite all the good things we raise here that would normally make its way into a very basic manual. Trial and error until someone finds something that makes things crash is the norm

To make the point, the most basic thing which is publishing what gets updated every time there is a new release is just omitted, so you´re left to surprises to see what will work and what will not