Adorkable / node-red-contrib-ui-led

A simple LED status indicator for the Node-RED Dashboard
MIT License
16 stars 12 forks source link

JSON input can only match on exact msg.payload string #48

Closed deelerke closed 3 years ago

deelerke commented 4 years ago

hi, there is an option to select JSON input for the msg.payload, but it seems to only test the whole string. So the LED would only colorize when the complete string is matched. Is it possible to select which JSON element & value to test? For example: an input would look like: { "Light1":0,"Light2":1,"Light3":0,"Light4":1 } And then have the led node to test: if "Light1" == "1" then color = "green"
if "Light1" == "0" then color = "grey" That way you can connect many ui-leds to a single input and select on what element to light up.

see: https://discourse.nodered.org/t/simple-json-input-string-to-leds-on-dash/20003

THANKS!

yoiang commented 4 years ago

Hello @deelerke ! Sorry for the very late reply! As outlined in the thread you currently will have to split up the values that come through your initial payload and direct the appropriate one to the LED you'd like to process that value. It is a lot of repetitive work but a lot of that can be solved by using subflows.

I am struggling to think of a robust but also intuitive way to allow using properties within an object type payload. Are there any other nodes you feel do this well? Perhaps an option to compare the direct value or as an object and if one selects object they must also specify a property. This could get complicated, people requesting path support for sub-sub-sub properties, etc.

Edit below:

It's been a little since I've messed around with the node, just played a little more and I have some thoughts, let me know what you think:

Right now the node is using Node-RED's compareObjects method which tests exact match. We could add an option that says instead test that the properties of the matching payload defined in the Colors for value of msg.payload are all present and equal in our actual payload.

So for example:

Match

Test

{
   "value" : false,
   "value2" : true
}

Payload

{
   "value" : false,
   "value1.5" : false,
   "value2" : true
}

No match

Test

{
   "value" : false,
   "value2" : true
}

Payload // Missing "value2"

{
   "value" : false,
   "value1.5" : false
}

Payload // value2's value does not match

{
   "value" : false,
   "value1.5" : false,
   "value2" : false
}
yoiang commented 3 years ago

Looking back on this I think there isn't a very extendable but also non-power user style interface that I can imagine, and it feels like it would be more flexible to keep this functionality in a separate place, such as a function or switch node.

However if anyone still has a strong argument feel free to drop it here!