# NodeRed shooting after MQTT restart \[SOLVED\]

**URL:** <https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520>\
**Category:** General\
**Created:** [23 September 2023 14:37 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520 "2023-09-23T14:37:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 14:37 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/1 "2023-09-23T14:37:42Z")

</div>

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

```auto

[
    {
        "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:

 ![Screenshot 2023-09-23 at 15.35.09](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/6/e606a1926b66b73afad3299c3132d1f849dec8f6.jpeg)

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

---

<div class="post-metadata">

**Author:** ![marcus-j-davies](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/marcus-j-davies/32/103435_2.png) [@marcus-j-davies](https://discourse.nodered.org/u/marcus-j-davies)\
**Post date:** [23 September 2023 14:42 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/2 "2023-09-23T14:42:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 15:04 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/3 "2023-09-23T15:04:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 15:29 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/4 "2023-09-23T15:29:10Z")

</div>

> [@homonto](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 15:41 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/5 "2023-09-23T15:41:21Z")

</div>

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

 ![Screenshot 2023-09-23 at 16.40.45](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/f/efeb8d010ee8b87206bb9cec1b9e62a1d3f6b12b.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 15:48 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/6 "2023-09-23T15:48:23Z")

</div>

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

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/b/3b092580941b35d7e1510a294e15d5b23a700ec1.png)

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

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 15:52 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/7 "2023-09-23T15:52:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 15:57 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/8 "2023-09-23T15:57:09Z")

</div>

You will have to ask on an HA forum then.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 15:59 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/9 "2023-09-23T15:59:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 16:03 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/10 "2023-09-23T16:03:52Z")

</div>

`{"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"}`

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 16:04 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/11 "2023-09-23T16:04:23Z")

</div>

![Screenshot 2023-09-23 at 17.04.05](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/e/4e92aca6e3796d91541eb54542a2ed3b9d100ec8.png)

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 16:05 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/12 "2023-09-23T16:05:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 16:18 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/13 "2023-09-23T16:18:55Z")

</div>

Looks like a HA problem then.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 16:21 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/14 "2023-09-23T16:21:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 16:28 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/15 "2023-09-23T16:28:59Z")

</div>

let me check again

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 16:30 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/16 "2023-09-23T16:30:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 17:07 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/17 "2023-09-23T17:07:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 17:18 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/18 "2023-09-23T17:18:53Z")

</div>

HA is quite nice piece of software 😉

---

<div class="post-metadata">

**Author:** ![homonto](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/homonto/32/68035_2.png) [@homonto](https://discourse.nodered.org/u/homonto)\
**Post date:** [23 September 2023 18:24 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/19 "2023-09-23T18:24:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [23 September 2023 18:54 UTC](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520/20 "2023-09-23T18:54:42Z")

</div>

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

> [@homonto](#):
>
> HA is quite nice piece of software

Are you sure?

[Next page](https://discourse.nodered.org/t/nodered-shooting-after-mqtt-restart-solved/81520.md?page=2)
