How to get boolean from JSON node to LED node

Just started learning Node Red and I'm having great difficulty trying to turn an LED on/off based on a value in a JSON block.

I put the following in an INJECT node:
{"voltage": 30,"heateron":true}

The INJECT node connects to a JSON node which then connects to a GAUGE node.
My gauge works fine when I use msg.payload.voltage
However, I cannot do the same with an LED node, example msg.payload.heateron

So how do I get the boolean true/false value from the JSON node to turn on the LED ?

Welcome to the Forum.

The json node isn't necessary here, as msg.payload.voltage and msg.payload.heateron will handle the relevant values directly from the JSON object.

[{"id":"dcadfbbcf13f3955","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"10610ae81f65d607","type":"inject","z":"dcadfbbcf13f3955","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"voltage\":30,\"heateron\":true}","payloadType":"json","x":190,"y":240,"wires":[["e7d4dcf5245de1bf","66ed6e4c48f4aab8"]]},{"id":"e7d4dcf5245de1bf","type":"debug","z":"dcadfbbcf13f3955","name":"Isolate voltage","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.voltage","targetType":"msg","statusVal":"","statusType":"auto","x":380,"y":200,"wires":[]},{"id":"66ed6e4c48f4aab8","type":"debug","z":"dcadfbbcf13f3955","name":"Isolate heateron","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.heateron","targetType":"msg","statusVal":"","statusType":"auto","x":380,"y":260,"wires":[]}]

Thanks Dave, but I'm afraid I'm just left more confused. There does not appear to be anywhere in the LED node to use msg.payload.heateron so not sure how I can use it.
From what I've read, the LED node expects either a true or false input so somehow I need to read the heateron boolean value and get that "injected" into the LED node.

I'm not wanting to push out @dynamicdave and his help.

(No, I haven't looked at the code he posted)

Open the LED node and change it from just payload to payload.heateron

I think that may be a reason it isn't working.

(But as I haven't seen your code either, I can't be sure.)

The payload is a rather generic term. (Nothing wrong with using it though)

But usually the payload is a simple thing like true/false or stuff like that.
But here it is a json message which means payload doesn't exist in the usual format/strucutre.

It is now msg.payload.heateron and msg.payload.voltage

So you need to look at the more specific payload.heateron part

Use a change node to move msg.payload.heaton to msg.payload.

As a beginner you may benefit form watching the essentials videos, they have a great deal of information that will help you as a beginner with node-red.

By the way welcome to the forum.

If you look at the LED node you'll see it expects the true/false to be in msg.payload, so you need to move the property to the correct place - with a change node.

Note: This is the LED node for Dashboard-1 (D2 may be different).



Here's the above demo flow - just IMPORT it and have a play.

[{"id":"dcadfbbcf13f3955","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"10610ae81f65d607","type":"inject","z":"dcadfbbcf13f3955","name":"voltage = 3, heateron = true","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"voltage\":30,\"heateron\":true}","payloadType":"json","x":160,"y":200,"wires":[["4685871be5d4e500"]]},{"id":"4685871be5d4e500","type":"change","z":"dcadfbbcf13f3955","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.heateron","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":240,"wires":[["35c18b511d14be8e","8afcc9e196feecfe"]]},{"id":"8afcc9e196feecfe","type":"ui_led","z":"dcadfbbcf13f3955","order":2,"group":"29bb735723a8be77","width":0,"height":0,"label":"","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"#ff0000","value":"false","valueType":"bool"},{"color":"#008000","value":"true","valueType":"bool"}],"allowColorForValueInMessage":false,"shape":"circle","showGlow":true,"name":"","x":590,"y":240,"wires":[]},{"id":"35c18b511d14be8e","type":"debug","z":"dcadfbbcf13f3955","name":"LED state","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":300,"wires":[]},{"id":"b95c753607250817","type":"inject","z":"dcadfbbcf13f3955","name":"voltage = 3, heateron = false","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"voltage\":30,\"heateron\":false}","payloadType":"json","x":160,"y":280,"wires":[["4685871be5d4e500"]]},{"id":"29bb735723a8be77","type":"ui_group","name":"dashboard_group","tab":"246a538c.3d84b4","order":null,"disp":true,"width":6},{"id":"246a538c.3d84b4","type":"ui_tab","name":"SMART Home - lighting","icon":"home","order":1,"disabled":false,"hidden":false}]

The problem is like I mentioned in my opening post:
"However, I cannot do the same with an LED node, example msg.payload.heateron"

There is no value box in the LED node where you can alter what the message is. I therefore cannot use msg.payload.heateron directly in the LED node.
The gauge node is different and no problem, as there is a value box and I change it from "msg.payload" to "msg.payload.voltage" and the gauge works as expected. Just can't do the same thing in the LED node.

Aha, that's it Dave, that worked a treat.
It's very sneaky in that change node that I don't change the value to a boolean but instead it gets changed to msg.payload.heateron.
Yes, looks like I've got a lot to learn.

Thanks to all of you for the kind help, and for the welcomes. Nice to be here.

Keith

Glad you have got it working.

The change node is changing the position of the property in the payload so it matches the LED node's requirements of where it expects the property to be. Happens a lot in Node-RED.

As @E1cid suggested - have a look at the Essential Videos - well worth the time and energy.