Converting JSON Object to boolean

Hi..Trying to control my blinds. Really new to this here...tried SEARCH but could not find a solution.

Using a NORA node that delivers a JSON Object
DEBUG:
msg.payload : Object

{ openPercent: 0 }

and
{ openPercent: 100 }

need to control a blind which is toggled with a http in node
this needs a boolean so I need to convert NORA BLINDS Node from JSON to BOOLEAN

Could not get SWITCH node running because it offers no JSON Source.
Got now stuck with this

Is there any help?

Regards Michael

You could use a conditional statement in a change node using JSONata or similar in a function node.
e.g.

[{"id":"711aea43.2409bc","type":"inject","z":"57675e72.26a0d8","name":"0","props":[{"p":"payload.openPercent","v":"0","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":920,"wires":[["fdc0d58.4081c28"]]},{"id":"fdc0d58.4081c28","type":"change","z":"57675e72.26a0d8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.openPercent > 0 ? true : false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":900,"wires":[["b84dcbfc.816ad"]]},{"id":"e92401aa.c1c7e","type":"inject","z":"57675e72.26a0d8","name":"100","props":[{"p":"payload.openPercent","v":"100","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":140,"y":860,"wires":[["fdc0d58.4081c28"]]},{"id":"b84dcbfc.816ad","type":"debug","z":"57675e72.26a0d8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":580,"y":900,"wires":[]}]

Hi. thnx for that fast response, but I don´t know how to interpret your answer. I am not yet used to programming functions. Sorry for that

Import the the flow by pressing ctrl i. Paste the code and click import, then click deploy.

The 2 inject nodes simulate msg.payload.openPercent values 1 and 100.
The change node checks if the msg,payload.openPercent is greater than 0. If it is outputs is true, if not greater outputs is false, and sets that output to msg.payload

Hi...wow..thnx .will have to try tomorrow. Will report if it worked for me​:+1::muscle:

@E1cid
Thnx allot. This worked​:muscle::grin::+1: Result is exactly what I needed. So the switch node combined with that J "syntax" is the key. Is there any chance for me to learn more about this. I try to read allot and watch youtube tutorials. Any idea where to find a Tut for a dumb noob like me​:thinking:

Got stuck again. Found out, that an output of the json object value will help me to control my blinds and move em in presents he steps. Can you give me a last hint?

Actually I control most of my smarthome with Iobroker, which took me a lot of time to "program" it for my needs. But node red is more powerful, but not that easy for me.
Thnx allot in advance
Michael

Hi
Jsonata https://jsonata.org/ is powerful, but you would be better served learning javascript. Jsonata you will pick up on your journey as you start manipulating objects and arrays.

My example was using jsonata, but you could do exactly the same using a function node and javascript, which is often faster and easier to understand.

As to your new issue i have no help as i have no idea what you are doing, when posing a question best to give a good discription of the input and what you expect as output, as you did in your original question. I find if i want to see how something is done, i look here https://flows.nodered.org/, and search for flows i can pull apart for ideas and examples.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.