Struggle with boolean

Hi, I am pretty new here and started working with NR a couple of weeks ago, so still a novice.

Currently struggeling with simple boolean logic. I just want to made a simple AND logic, where
one input is a state-change and the other one a simple boolean_switch. I could not bring this into work, does anybody have an idea on that? Thank you.

image
image

[{"id":"e3081cd7.670e1","type":"BooleanLogicUltimate","z":"b04b838e.cc29c","name":"","filtertrue":"onlytrue","persist":true,"sInitializeWith":"false","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"payload","x":450,"y":180,"wires":[["3ded3887.f8a1c8","58d92cf.b2ba7d4"],[],[]]}]

Hi Dave, welcome to the forum.
Your flow is not importable, please read this post about how to share flows in the forum.
You can then edit your post using the pencil icon, and make the necessary changes.

Hi Paul, thank you for letting me know about the correct format, hope it is now OK, Dave

1 Like

Aah I see that you are using the node-red-contrib-boolean-logic-ultimate node.
I can't help with that node as I've never used it, or have it in my palette.

I usually get around similar logic problems by using the more common node-RED nodes such as node-red-contrib-simple-gate which has inbuilt persistence, and maybe an easier option.

It's hard to give you better advice without knowing what your project is, and how you want it to work.

Thank you,
I really want to do just a simple AND function. Saying when a signal (given from a switch) changes from off to on AND a boolean switch is on then let the output = ON, otherwise = OFF.

Really not yet seen any functionable solution for that. Thank you

Really not yet seen any functionable solution for that. Thank you

This is done regularly.
I don't use home assistant, so have no idea what it produces or how your flow works.

Like the simple gate suggestion would work. But personally, I prefer (flow/global/node) contexts to keep track of states. ie. the HA node sets a flow variable instead of sending it off through the flow, and whenever you need to know the state, simply read the context value.

OK, but this not exactly what I look for. Simple example: switch on a light ONLY when 2 boolean inputs are on, if one them changes to off, then the light must switch to off too.
sounds simple but I could not implement it correctly. Any help?

Try this example flow

[{"id":"5dfa49af.8e191","type":"inject","z":"c28fcd8e.4dd2b","name":"device1 - on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":118,"y":360,"wires":[["78a3fe6f.1a52d8","56683060.4a9a1"]]},{"id":"56683060.4a9a1","type":"switch","z":"c28fcd8e.4dd2b","name":"device1_state ?","property":"device1_state","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":392,"y":480,"wires":[["a0c76c9f.589c3"],["264f939a.c8bdfc"]]},{"id":"a0c76c9f.589c3","type":"switch","z":"c28fcd8e.4dd2b","name":"device2_state ?","property":"device2_state","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":584,"y":456,"wires":[["afa86581.9147d"],["68a594bd.066c24"]]},{"id":"373c972b.ab751","type":"inject","z":"c28fcd8e.4dd2b","name":"device1 - off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":118,"y":408,"wires":[["78a3fe6f.1a52d8","56683060.4a9a1"]]},{"id":"78a3fe6f.1a52d8","type":"change","z":"c28fcd8e.4dd2b","name":"","rules":[{"t":"set","p":"device1_state","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":412,"y":360,"wires":[[]]},{"id":"5a6e05d6.24d3ec","type":"inject","z":"c28fcd8e.4dd2b","name":"device2 - on","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":118,"y":552,"wires":[["d894a266.bfaa2","56683060.4a9a1"]]},{"id":"1efdeebb.f56f41","type":"inject","z":"c28fcd8e.4dd2b","name":"device2 - off","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":118,"y":624,"wires":[["d894a266.bfaa2","56683060.4a9a1"]]},{"id":"d894a266.bfaa2","type":"change","z":"c28fcd8e.4dd2b","name":"","rules":[{"t":"set","p":"device2_state","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":388,"y":624,"wires":[[]]},{"id":"ba713890.7006a","type":"debug","z":"c28fcd8e.4dd2b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":951,"y":432,"wires":[],"l":false},{"id":"afa86581.9147d","type":"change","z":"c28fcd8e.4dd2b","name":"dev1 and dev2 on","rules":[{"t":"set","p":"payload","pt":"msg","to":"Both on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":786,"y":432,"wires":[["ba713890.7006a"]]},{"id":"264f939a.c8bdfc","type":"change","z":"c28fcd8e.4dd2b","name":"dev1 off","rules":[{"t":"set","p":"payload","pt":"msg","to":"dev 1 is off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":588,"y":504,"wires":[["b8a8c38.dca9ac"]]},{"id":"c5bbe1e5.5a24a8","type":"debug","z":"c28fcd8e.4dd2b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":951,"y":480,"wires":[],"l":false},{"id":"68a594bd.066c24","type":"change","z":"c28fcd8e.4dd2b","name":"dev1 = on, dev2 = off","rules":[{"t":"set","p":"payload","pt":"msg","to":"dev1 = on, dev2 = off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":796,"y":480,"wires":[["c5bbe1e5.5a24a8"]]},{"id":"b8a8c38.dca9ac","type":"debug","z":"c28fcd8e.4dd2b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":711,"y":528,"wires":[],"l":false},{"id":"975c1230.cac36","type":"change","z":"c28fcd8e.4dd2b","name":"","rules":[{"t":"set","p":"device1_state","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":207,"y":168,"wires":[[]],"l":false},{"id":"28a5ecd9.8f921c","type":"change","z":"c28fcd8e.4dd2b","name":"","rules":[{"t":"set","p":"device2_state","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":207,"y":216,"wires":[[]],"l":false},{"id":"a2d5a4eb.e27a1","type":"inject","z":"c28fcd8e.4dd2b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":109,"y":192,"wires":[["975c1230.cac36","28a5ecd9.8f921c"]],"l":false},{"id":"7aa780d2.581bd8","type":"comment","z":"c28fcd8e.4dd2b","name":"intialize variables - they need to exist before flow works","info":"","x":270,"y":120,"wires":[]}]

It is a very literal flow.

I have found node-red-contrib-bool-gate good for such applications.

Admin Edit: surrounded your code with backticks as it was not importable

I have that one too, but not able to implement such simple flow. Below example does work until first time both switches have been on, then the light is on even if only one input is on.

[
    {
        "id": "7a9e8cd2.3dbc64",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "b2293f72.fdabd",
        "type": "debug",
        "z": "7a9e8cd2.3dbc64",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 470,
        "y": 180,
        "wires": []
    },
    {
        "id": "a1d982d3.3ad08",
        "type": "debug",
        "z": "7a9e8cd2.3dbc64",
        "name": "amb",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 430,
        "y": 340,
        "wires": []
    },
    {
        "id": "c97da7b5.50a9d8",
        "type": "server-state-changed",
        "z": "7a9e8cd2.3dbc64",
        "name": "",
        "server": "a11aa034.815b8",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.security",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "habool",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "x": 190,
        "y": 220,
        "wires": [
            [
                "3df6af6.801745",
                "b2293f72.fdabd"
            ],
            []
        ]
    },
    {
        "id": "3e622d7.80817d2",
        "type": "server-state-changed",
        "z": "7a9e8cd2.3dbc64",
        "name": "",
        "server": "a11aa034.815b8",
        "version": 1,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "input_boolean.amblight",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "habool",
        "haltifstate": "on",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 2,
        "output_only_on_state_change": true,
        "for": 0,
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "x": 190,
        "y": 280,
        "wires": [
            [
                "3df6af6.801745",
                "a1d982d3.3ad08"
            ],
            []
        ]
    },
    {
        "id": "286b8fc6.b8744",
        "type": "api-call-service",
        "z": "7a9e8cd2.3dbc64",
        "name": "",
        "server": "a3cbae53.1f436",
        "version": 1,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_on",
        "entityId": "switch.shelly1_reserve_3",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 790,
        "y": 200,
        "wires": [
            []
        ]
    },
    {
        "id": "517522f6.9fbf2c",
        "type": "api-call-service",
        "z": "7a9e8cd2.3dbc64",
        "name": "",
        "server": "a3cbae53.1f436",
        "version": 1,
        "debugenabled": false,
        "service_domain": "switch",
        "service": "turn_off",
        "entityId": "switch.shelly1_reserve_3",
        "data": "",
        "dataType": "jsonata",
        "mergecontext": "",
        "output_location": "",
        "output_location_type": "none",
        "mustacheAltTags": false,
        "x": 790,
        "y": 280,
        "wires": [
            []
        ]
    },
    {
        "id": "3df6af6.801745",
        "type": "BooleanLogic",
        "z": "7a9e8cd2.3dbc64",
        "name": "",
        "operation": "AND",
        "inputCount": "2",
        "topic": "result",
        "x": 480,
        "y": 240,
        "wires": [
            [
                "286b8fc6.b8744"
            ]
        ]
    },
    {
        "id": "a11aa034.815b8",
        "type": "server",
        "name": "RasPi2",
        "legacy": false,
        "addon": true,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true
    },
    {
        "id": "a3cbae53.1f436",
        "type": "server",
        "name": "Home Assistant",
        "addon": true
    }
]

That isn't node-red-contrib-bool-gate.

sorry, just changed but still no success - see below, thank you

[{"id":"1975b7b0.57e908","type":"and-gate","z":"3d71077c.496e98","name":"","rules":[{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":"input_boolean.security"},{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":"input_boolean.amblight"}],"outputTopic":"","gateType":"and","emitOnlyIfTrue":false,"x":520,"y":220,"wires":[["791518d2.0d00d8","dbf4ea16.ffa358"]]},{"id":"7265a0ad.4f9f5","type":"debug","z":"3d71077c.496e98","name":"secu","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":160,"wires":[]},{"id":"4387de51.ec71a","type":"debug","z":"3d71077c.496e98","name":"amb","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":340,"wires":[]},{"id":"192464.f66bcb9c","type":"server-state-changed","z":"3d71077c.496e98","name":"","server":"a11aa034.815b8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.security","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":230,"y":200,"wires":[["7265a0ad.4f9f5","1975b7b0.57e908"],[]]},{"id":"11cf3ea5.91fb71","type":"server-state-changed","z":"3d71077c.496e98","name":"","server":"a11aa034.815b8","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.amblight","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":230,"y":260,"wires":[["4387de51.ec71a","1975b7b0.57e908"],[]]},{"id":"791518d2.0d00d8","type":"api-call-service","z":"3d71077c.496e98","name":"","server":"a11aa034.815b8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.shelly1_reserve_3","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":830,"y":180,"wires":[[]]},{"id":"fb999f26.8b80a","type":"api-call-service","z":"3d71077c.496e98","name":"","server":"a11aa034.815b8","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.shelly1_reserve_3","data":"","dataType":"jsonata","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":830,"y":260,"wires":[[]]},{"id":"dbf4ea16.ffa358","type":"debug","z":"3d71077c.496e98","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":140,"wires":[]},{"id":"a11aa034.815b8","type":"server","name":"RasPi2","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

As per the posts above, please format your flow correctly when pasting it in the forum!

thank you, changed, Dave

1 Like

You have not configured the AND node with the appropriate data to tell it what to do. You have to tell it about both the inputs using two rules and tell it which topics to look for. node-red-contrib-bool-gate (node) - Node-RED

have you red the documentation for boolean ultimate on github?? they have an example there that is pretty much what you are asking for. Take a look at: https://github.com/Supergiovane/node-red-contrib-boolean-logic-ultimate

yes, I did, but did not really work as I expcted.

Hi Colin,
could you help me finding the right configuration for my application. Really not sure what I have to put into for topic. Thank you

Below flow does always trigger the output when the inputs are still "off"

[{"id":"1975b7b0.57e908","type":"and-gate","z":"3d71077c.496e98","name":"","rules":[{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":"input_boolean.security"},{"t":"eq","v":"on","vt":"str","propertyType":"msg","property":"payload","topic":"input_boolean.amblight"}],"outputTopic":"","gateType":"and","emitOnlyIfTrue":false,"x":520,"y":220,"wires":[["791518d2.0d00d8","dbf4ea16.ffa358"]]}]

try this one and tell where are you struggeling

[{"id":"e3081cd7.670e1","type":"BooleanLogicUltimate","z":"73cba448.81c14c","name":"","filtertrue":"both","persist":true,"sInitializeWith":"false","triggertopic":"trigger","outputtriggeredby":"all","inputCount":2,"topic":"result","x":600,"y":3360,"wires":[["71ca6a67.86cdf4"],[],[]]},{"id":"da07fdb8.500f1","type":"inject","z":"73cba448.81c14c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button2","payload":"true","payloadType":"bool","x":290,"y":3300,"wires":[["e3081cd7.670e1"]]},{"id":"98b1fa98.0f2688","type":"inject","z":"73cba448.81c14c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button1","payload":"true","payloadType":"bool","x":290,"y":3440,"wires":[["e3081cd7.670e1"]]},{"id":"71ca6a67.86cdf4","type":"debug","z":"73cba448.81c14c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":850,"y":3360,"wires":[]},{"id":"817c4961.bd8628","type":"inject","z":"73cba448.81c14c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button2","payload":"false","payloadType":"bool","x":290,"y":3340,"wires":[["e3081cd7.670e1"]]},{"id":"b24f6681.532498","type":"inject","z":"73cba448.81c14c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button1","payload":"false","payloadType":"bool","x":290,"y":3480,"wires":[["e3081cd7.670e1"]]},{"id":"a05c68b8.b6a2f8","type":"comment","z":"73cba448.81c14c","name":"if 2 buttons are true, then payload: true, else payload: false","info":"","x":690,"y":3300,"wires":[]}]

after changing the output to "only true results" it works. But right now missing a false output, so
getting the false state of the logic, any idea?