NodeRed shooting after MQTT restart [SOLVED]

So I have a small problem.
I have a flow:


[
    {
        "id": "112985cb18f5dd1f",
        "type": "tab",
        "label": "desk",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9ca106e00539025c",
        "type": "group",
        "z": "112985cb18f5dd1f",
        "style": {
            "stroke": "#999999",
            "stroke-opacity": "1",
            "fill": "none",
            "fill-opacity": "1",
            "label": true,
            "label-position": "nw",
            "color": "#a4a4a4"
        },
        "nodes": [
            "6276c6364bdfa867",
            "1d7aaebb2df76434",
            "01b2a08fe671b917",
            "ee9a3a6b92e42f30",
            "d303543830d3213f",
            "9c0b231e13a8a62f",
            "489845f35920c576",
            "d067e4be3fa8f56f",
            "e39c35e97f99948f",
            "44ae8ab2f8815e9f",
            "9a2b1bf56e5cc7f0",
            "8d87670db5f22eec"
        ],
        "x": 134,
        "y": 1099,
        "w": 1292,
        "h": 289.5
    },
    {
        "id": "9f5a305fe93d3a52",
        "type": "switch",
        "z": "112985cb18f5dd1f",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "2",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "3",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "4",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "5",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "6",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 6,
        "x": 670,
        "y": 440,
        "wires": [
            [
                "83f1627e11412d1e"
            ],
            [
                "8bea4d36acad3ac5"
            ],
            [
                "1ad9cb1fac7dec03"
            ],
            [
                "f475e6a16e911108"
            ],
            [
                "5b44983739bf758c"
            ],
            [
                "ff3ec514f723f07b"
            ]
        ]
    },
    {
        "id": "86e9d3caa4f45ada",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "name": "Desk Left Lamp",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son03_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1100,
        "y": 240,
        "wires": [
            []
        ]
    },
    {
        "id": "83f1627e11412d1e",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 890,
        "y": 240,
        "wires": [
            [
                "86e9d3caa4f45ada"
            ]
        ]
    },
    {
        "id": "c09a5e38f8628de8",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "name": "Desk Big Lamp",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son04_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1100,
        "y": 340,
        "wires": [
            []
        ]
    },
    {
        "id": "8bea4d36acad3ac5",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 890,
        "y": 340,
        "wires": [
            [
                "c09a5e38f8628de8"
            ]
        ]
    },
    {
        "id": "5da164419846f15e",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "name": "Desk Right Lamp",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son05_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1110,
        "y": 440,
        "wires": [
            []
        ]
    },
    {
        "id": "1ad9cb1fac7dec03",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 890,
        "y": 440,
        "wires": [
            [
                "5da164419846f15e"
            ]
        ]
    },
    {
        "id": "9e9dc5b70765d58c",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "name": "Hot gun",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "switch",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "switch.esp32s4xsockets112blue_switch1"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1080,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "f475e6a16e911108",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 890,
        "y": 540,
        "wires": [
            [
                "9e9dc5b70765d58c"
            ]
        ]
    },
    {
        "id": "5b44983739bf758c",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 890,
        "y": 640,
        "wires": [
            [
                "d6de5e432869ff6a"
            ]
        ]
    },
    {
        "id": "d6de5e432869ff6a",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "name": "Solder",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "switch",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "switch.esp32s4xsockets112blue_switch2"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1070,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "483202f3032d2f61",
        "type": "server-state-changed",
        "z": "112985cb18f5dd1f",
        "name": "",
        "server": "708536aa.d63208",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.esp32042_button_pressed",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": false,
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 370,
        "y": 440,
        "wires": [
            [
                "9f5a305fe93d3a52"
            ]
        ]
    },
    {
        "id": "5820cf7cdb5bdf0f",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "button 5: solder",
        "info": "",
        "x": 1320,
        "y": 640,
        "wires": []
    },
    {
        "id": "6ff5efe8527c1046",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "button 4: hot gun",
        "info": "",
        "x": 1320,
        "y": 540,
        "wires": []
    },
    {
        "id": "5df116808ada73cb",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "button 3: desk right",
        "info": "",
        "x": 1330,
        "y": 440,
        "wires": []
    },
    {
        "id": "03ec1ea68c96b0e6",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "button 2: desk big",
        "info": "",
        "x": 1330,
        "y": 340,
        "wires": []
    },
    {
        "id": "32c1057f096cf8d9",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "button 1: desk left",
        "info": "",
        "x": 1330,
        "y": 240,
        "wires": []
    },
    {
        "id": "4b030d2166a88286",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "Push Button 6x Desk",
        "info": "",
        "x": 280,
        "y": 340,
        "wires": []
    },
    {
        "id": "6276c6364bdfa867",
        "type": "switch",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "button1x1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "button2x1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "button2x2",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 3,
        "x": 650,
        "y": 1340,
        "wires": [
            [
                "01b2a08fe671b917"
            ],
            [
                "d303543830d3213f"
            ],
            [
                "489845f35920c576"
            ]
        ]
    },
    {
        "id": "1d7aaebb2df76434",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "Desk Left Lamp",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son03_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1080,
        "y": 1140,
        "wires": [
            []
        ]
    },
    {
        "id": "01b2a08fe671b917",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 870,
        "y": 1140,
        "wires": [
            [
                "1d7aaebb2df76434"
            ]
        ]
    },
    {
        "id": "ee9a3a6b92e42f30",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "Desk Big Lamp",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son04_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1080,
        "y": 1240,
        "wires": [
            []
        ]
    },
    {
        "id": "d303543830d3213f",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 870,
        "y": 1240,
        "wires": [
            [
                "ee9a3a6b92e42f30"
            ]
        ]
    },
    {
        "id": "9c0b231e13a8a62f",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "Desk Right Lamp",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son05_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1090,
        "y": 1340,
        "wires": [
            []
        ]
    },
    {
        "id": "489845f35920c576",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 870,
        "y": 1340,
        "wires": [
            [
                "9c0b231e13a8a62f"
            ]
        ]
    },
    {
        "id": "d067e4be3fa8f56f",
        "type": "server-state-changed",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "",
        "server": "708536aa.d63208",
        "version": 4,
        "exposeToHomeAssistant": false,
        "haConfig": [
            {
                "property": "name",
                "value": ""
            },
            {
                "property": "icon",
                "value": ""
            }
        ],
        "entityidfilter": "sensor.esp32027_button433",
        "entityidfiltertype": "exact",
        "outputinitially": false,
        "state_type": "str",
        "haltifstate": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "outputs": 1,
        "output_only_on_state_change": false,
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "eventData"
            },
            {
                "property": "topic",
                "propertyType": "msg",
                "value": "",
                "valueType": "triggerId"
            }
        ],
        "x": 330,
        "y": 1340,
        "wires": [
            [
                "6276c6364bdfa867"
            ]
        ]
    },
    {
        "id": "e39c35e97f99948f",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "button 3: desk right",
        "info": "",
        "x": 1310,
        "y": 1340,
        "wires": []
    },
    {
        "id": "44ae8ab2f8815e9f",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "button 2: desk big",
        "info": "",
        "x": 1310,
        "y": 1240,
        "wires": []
    },
    {
        "id": "9a2b1bf56e5cc7f0",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "button 1: desk left",
        "info": "",
        "x": 1310,
        "y": 1140,
        "wires": []
    },
    {
        "id": "8d87670db5f22eec",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "d": true,
        "g": "9ca106e00539025c",
        "name": "433MHz switches",
        "info": "",
        "x": 250,
        "y": 1240,
        "wires": []
    },
    {
        "id": "ff3ec514f723f07b",
        "type": "delay",
        "z": "112985cb18f5dd1f",
        "name": "",
        "pauseType": "rate",
        "timeout": "5",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": true,
        "allowrate": false,
        "outputs": 1,
        "x": 890,
        "y": 720,
        "wires": [
            [
                "4f2a4a31b8ed5ab9"
            ]
        ]
    },
    {
        "id": "4f2a4a31b8ed5ab9",
        "type": "api-call-service",
        "z": "112985cb18f5dd1f",
        "name": "Small PS Right",
        "server": "708536aa.d63208",
        "version": 5,
        "debugenabled": false,
        "domain": "light",
        "service": "toggle",
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "light.sonoff_switch_minir2_son06_light"
        ],
        "data": "",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "queue": "none",
        "x": 1100,
        "y": 720,
        "wires": [
            []
        ]
    },
    {
        "id": "bb36f53e8e3d977e",
        "type": "comment",
        "z": "112985cb18f5dd1f",
        "name": "button 6: small PS right",
        "info": "",
        "x": 1340,
        "y": 720,
        "wires": []
    },
    {
        "id": "708536aa.d63208",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": false,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": true,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": "at: ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "h23",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": true
    }
]

or in the pic format:

and everytime HA restarts or MQTT server restarts the first node shoots again the last value.
The message is sent with NO RETAIN flag.
Problem is: "button 2" means: toggle the relay 2 - so when the lamp was OFF, MQTT restarted, now I have lamp ON ;-(
(similar for button 1-6)

How to configure NR or HA or whatever else to avoid such issue?
Imagine: restart of MQTT in the night and the light (or solder) is ON till I come and turn it OFF

thx

Hi @homonto

On the basis the first Node is from HA - this is something you will need to take up with the HA devs.
Whilst we do have HA users here, most here do not use HA

ha, I was actually not sure if HA or NR are guilty.

Connect a debug node to the output of the first node. If you see the problematic data there then the problem would appear to lie in that node.

To check what is being retained in MQTT (if anything) then install MQTTExplorer and see what it says.

hi @Colin
as you can see, MQTT message is NOT retained

Then it is the HA node that is introducing the problem. Perhaps you need to select one or more of the options.

image

Current state is unknown possibly? Though how it can trigger an event if it doesn't know the state I have no idea.

so, for sure it is NOT a problem of the device - the device has 6 push buttons and if you press any, it will send MQTT message to HA: "button pressed number 2" - then, this is processed by NR: every press is toggle - if you press 1 time button 2 it will turn from ON to OFF - depending what was before.
Problem is: restart of MQTT or HA. In both cases there is "the last event" repeated, so if I turned OFF relay 2, it will now be turned ON by NR flow.
I cannot tick: "ignore if previous is the same like current" - I would not be able to toggle anymore.
So I tried all and nothing really helps

You will have to ask on an HA forum then.

First, though, show us what you see in the debug node connected to the first node. Set it to Output Complete Message.

{"payload":"1","data":{"entity_id":"sensor.esp32042_button_pressed","old_state":{"entity_id":"sensor.esp32042_button_pressed","state":"unavailable","attributes":{"friendly_name":"Button x6 desk (042) button_pressed"},"last_changed":"2023-09-23T16:03:02.931858+00:00","last_updated":"2023-09-23T16:03:02.931858+00:00","context":{"id":"01HB1CFDMKQGFM6P7EAGQDXA62","parent_id":null,"user_id":null},"original_state":"unavailable"},"new_state":{"entity_id":"sensor.esp32042_button_pressed","state":"1","attributes":{"friendly_name":"Button x6 desk (042) button_pressed"},"last_changed":"2023-09-23T16:03:18.350490+00:00","last_updated":"2023-09-23T16:03:18.350490+00:00","context":{"id":"01HB1CFWPERWJH9RS7Z38NFR6P","parent_id":null,"user_id":null},"original_state":"1","timeSinceChangedMs":1842}},"topic":"sensor.esp32042_button_pressed","_msgid":"377dc6a273bda8fa"}

so last button was 1, then I turned off MQTT server, turned on, and then, button 1 came again without pressing it
and this is the issue
FOR SURE device did NOT connect to MQTT again - it sleeps until pressed

Looks like a HA problem then.

Doesn't 'previous state unavailable' supress that message?

1 Like

let me check again

that WORKS - thank you @Colin
(don't know why it wasn't before)
but
is this a workaround or that is it should be?

No idea, all of my input has been guesswork here as I know nothing about HA.

1 Like

HA is quite nice piece of software :wink:

because button has previous state 'unavailable' (after MQTT restart), pressing the button for the first time also does not work either - only the second press makes it working (because first press is from unavailable to i.e. 1 - NR does not fire, second push is from 1 to whatever else (even to 1) and then NR does the job)

that is why I was saying: "it does not solve the problem"
hmm

Ask on an HA forum and let us know if you find the answer.

Are you sure?