0
votes

I have a simple lamps controller (on a raspberry) that subscribes MQTT messages '/floor1/terrace/lamps', turns on up-to 9 lamps and publishes the newly set pattern via '/floor1/terrace/lamps_r'. Additionally a local switch may also change this pattern and will therefore publish it on '/floor1/terrace/lamps_r'. The pattern is a number to hold a bit-pattern that corresponds to the lamp outputs.

I'd wanted to control these lamps using a node-red-dashboard and have them updated according to their current state, so I created an ui-dropdown with the corresponding patterns (moon symbols)

Selector on dashboard

The flow receives 'lamps_r' to show it on ui-dropdown (pass msg through selected) and sends the message if it changes to 'lamps'

Flow to receive and send on update

This works flawlessly, however after a mqtt disconnection (broker down or network disconnect) this rapidly cycles through the patterns defined in the ui-dropdown forever.

Here's the flow

[
    {
        "id": "4ec0402f.174028",
        "type": "mqtt out",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "floor1/terrace/lamps",
        "qos": "0",
        "retain": "false",
        "broker": "26e8c216.d6cd06",
        "x": 900,
        "y": 200,
        "wires": []
    },
    {
        "id": "a6324306.af9eb8",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "incoming",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 580,
        "y": 320,
        "wires": []
    },
    {
        "id": "4097bb88.a6b6fc",
        "type": "ui_dropdown",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "label": "Lamps",
        "tooltip": "",
        "place": "Select option",
        "group": "83e0c62c.0828d8",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "multiple": false,
        "options": [
            {
                "label": "????????????????????????????????????",
                "value": 0,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 1,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 56,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 17,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 170,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 85,
                "type": "num"
            },
            {
                "label": "????????????????????????????????????",
                "value": 255,
                "type": "num"
            }
        ],
        "payload": "",
        "topic": "",
        "x": 510,
        "y": 200,
        "wires": [
            [
                "29bfc4ae.3bfd64"
            ]
        ]
    },
    {
        "id": "1592291a.25645f",
        "type": "mqtt in",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "floor1/terrace/lamps_r",
        "qos": "2",
        "datatype": "json",
        "broker": "26e8c216.d6cd06",
        "x": 320,
        "y": 200,
        "wires": [
            [
                "4097bb88.a6b6fc",
                "a6324306.af9eb8"
            ]
        ]
    },
    {
        "id": "123f5abc.e6551d",
        "type": "comment",
        "z": "f6f2187d.f17ca8",
        "name": "MQTT message propagation",
        "info": "the dropdown element only shows the received state if the message is passed through!\nTo avoid an endless cycle 'only_if_changed' filters the message propagation if the current state was changed already.",
        "x": 640,
        "y": 260,
        "wires": []
    },
    {
        "id": "7776ebb4.fafda4",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "outgoing",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 930,
        "y": 320,
        "wires": []
    },
    {
        "id": "29bfc4ae.3bfd64",
        "type": "rbe",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "func": "rbe",
        "gap": "",
        "start": "",
        "inout": "out",
        "property": "payload",
        "x": 670,
        "y": 200,
        "wires": [
            [
                "4ec0402f.174028",
                "7776ebb4.fafda4"
            ]
        ]
    },
    {
        "id": "26e8c216.d6cd06",
        "type": "mqtt-broker",
        "name": "Morpheus",
        "broker": "morpheus.lan",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "83e0c62c.0828d8",
        "type": "ui_group",
        "name": "Default",
        "tab": "c3af9807.77191",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "c3af9807.77191",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

I'm a complete newbie on node-red and pretty clueless about what might be going on.

1

1 Answers

0
votes

Well this is not an answer as to why the endless cycle appears, but at least a workaround that might be helpful to others.

Modified Flow

I inject a property 'from_input' into the message, when it is read from the readback MQTT object and filter the message in 'filter readback'. This allows to distinguish messages that are read back from the ones generated by a selection in the ui-dropdown node:

The complete flow:

[
    {
        "id": "4ec0402f.174028",
        "type": "mqtt out",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "floor1/terrace/lamps",
        "qos": "0",
        "retain": "false",
        "broker": "26e8c216.d6cd06",
        "x": 1060,
        "y": 200,
        "wires": []
    },
    {
        "id": "a6324306.af9eb8",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "incoming",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 620,
        "y": 260,
        "wires": []
    },
    {
        "id": "4097bb88.a6b6fc",
        "type": "ui_dropdown",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "label": "Lamps",
        "tooltip": "",
        "place": "Select option",
        "group": "83e0c62c.0828d8",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": true,
        "multiple": false,
        "options": [
            {
                "label": "🌑🌑🌑🌑🌑🌑🌑🌑🌑",
                "value": 0,
                "type": "num"
            },
            {
                "label": "🌕🌑🌑🌑🌑🌑🌑🌑🌕",
                "value": 1,
                "type": "num"
            },
            {
                "label": "🌑🌑🌑🌕🌕🌕🌑🌑🌑",
                "value": 56,
                "type": "num"
            },
            {
                "label": "🌕🌑🌑🌑🌕🌑🌑🌑🌕",
                "value": 17,
                "type": "num"
            },
            {
                "label": "🌑🌕🌑🌕🌑🌕🌑🌕🌑",
                "value": 170,
                "type": "num"
            },
            {
                "label": "🌕🌑🌕🌑🌕🌑🌕🌑🌕",
                "value": 85,
                "type": "num"
            },
            {
                "label": "🌕🌕🌕🌕🌕🌕🌕🌕🌕",
                "value": 255,
                "type": "num"
            }
        ],
        "payload": "",
        "topic": "",
        "x": 610,
        "y": 200,
        "wires": [
            [
                "8ff45087.04324"
            ]
        ]
    },
    {
        "id": "1592291a.25645f",
        "type": "mqtt in",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "topic": "floor1/terrace/lamps_r",
        "qos": "2",
        "datatype": "json",
        "broker": "26e8c216.d6cd06",
        "x": 180,
        "y": 200,
        "wires": [
            [
                "e756f46d.03854"
            ]
        ]
    },
    {
        "id": "7776ebb4.fafda4",
        "type": "debug",
        "z": "f6f2187d.f17ca8",
        "name": "outgoing",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1020,
        "y": 260,
        "wires": []
    },
    {
        "id": "e756f46d.03854",
        "type": "change",
        "z": "f6f2187d.f17ca8",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "from_input",
                "pt": "msg",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 410,
        "y": 200,
        "wires": [
            [
                "4097bb88.a6b6fc",
                "a6324306.af9eb8"
            ]
        ]
    },
    {
        "id": "8ff45087.04324",
        "type": "function",
        "z": "f6f2187d.f17ca8",
        "name": "filter readback",
        "func": "if (!msg.hasOwnProperty('from_input'))\n    return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 800,
        "y": 200,
        "wires": [
            [
                "7776ebb4.fafda4",
                "4ec0402f.174028"
            ]
        ],
        "info": "check if 'from_input' is set, if not pass the message on"
    },
    {
        "id": "26e8c216.d6cd06",
        "type": "mqtt-broker",
        "name": "Morpheus",
        "broker": "morpheus.lan",
        "port": "1883",
        "clientid": "",
        "usetls": false,
        "compatmode": false,
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "willTopic": "",
        "willQos": "0",
        "willPayload": ""
    },
    {
        "id": "83e0c62c.0828d8",
        "type": "ui_group",
        "name": "Default",
        "tab": "c3af9807.77191",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false
    },
    {
        "id": "c3af9807.77191",
        "type": "ui_tab",
        "name": "Home",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]