PerMalmberg / node-red-contrib-boolean-logic

Node-RED nodes to perform Boolean logic
MIT License
11 stars 7 forks source link

Adding a simple if-node that returns a payload of true/false #6

Closed magma1447 closed 3 years ago

magma1447 commented 5 years ago

First off, I want to thank you for this awesome node package. It's exactly what I was considering creating myself. It really solves the multiple inputs -issue in a decent way.

I would however wish that you added one more node into the package. A simple node that checked for type and value and returned true/false in the payload depending on that.

For example. I am using node-red-contrib-schedex as one of the inputs. It can only return strings (not booleans). I am currently returning 'true' and 'false'. Currently I have this small function:

msg.payload = (msg.payload === 'true') ? true : false;
return msg;

However, I prefer to not use functions, it decreases the readability and simplicity.

I also have presence from Home Assistant as input. That value is always 'home' or 'away'. I have a similar code snippet for that.

msg.payload = (msg.payload == 'home') ? true : false;
return msg;

I would very much like to replace these two function nodes with a simple check that returns true or false in msg.payload, depending on a check of type and value in payload.

Is this something you would consider? If you are not interested in creating it yourself, would you accept a pull request? I have not yet written any nodes for Node-red, but I assume it's not rocket science, and that I therefore should be able to figure it out.

Attaching a screenshot of the flow where I tested this. screenshot_20190628_17:28:27_2846

PerMalmberg commented 5 years ago

Hello @magma1447

I'm glad to hear that it is useful for you.

I haven't used Node-Red for several years, so I have no real interest to work on things related to it. Also, I don't think the functionality you want is in line with what the components in this package solves. As such, I suggest you create your own component. It is really easy, especially if you base it on an existing one.

Glad sommar på dig :)