Need help rebuilding home automation raspberry pi

As I asked please post the flow inline, I get access denied on the link you posted, but that is not the preferred way to post flows.

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote ```)

``` 
   code goes here 
```

See this post for more details - How to share code or flow json

I strayed away from the real issue a bit by wondering about network topology, but it's good to know both Pies are connected the same.
Barring confusion between devices, we do see attempts to connect to Mosquitto, so messages do pass between the devices.

There are a couple of command line based tests that might be worth trying before you get into Node-red:

  1. Can Mosquitto on the old Pi talk to itself? Yes of course it can but let's just check!
    Open two terminal windows to the old Pi. In one run mosquitto_sub -h "localhost" -t "test/topic" and in the other mosquitto_pub -h "localhost" -t "test/topic" -m "A message from the old Pi"
    Hopefully, the message appears on the mosquitto_sub window.

  2. Can Mosquitto on the new Pi talk to itself? This should demonstrate that Mosquitto is running on the new Pi and that it accepts connection from localhost.
    Open two terminal windows to the new Pi. In one run mosquitto_sub -h "localhost" -t "test/topic" and in the other mosquitto_pub -h "localhost" -t "test/topic" -m "A message from the new Pi"
    Does this work?

Now there should be 4 terminal windows open, one on each Pi showing the Bash prompt, and one on each Pi running mosquitto_sub listening for messages.

  1. Can Mosquitto on the new Pi talk to the old Pi? I'd be very surprised if this fails.
    In the new Pi terminal mosquitto_pub window run mosquitto_pub -h "192.168.1.28" -t "test/topic" -m "cave canem" (use the IP address of your old Pi rather than 192.168.1.28)
    Does "cave canem" show up on the old Pi mosquitto_sub window?

  2. Can you send an MQTT message from the old Pi to the new one?
    If you can, Mosquitto is correctly set up and accepting connections from the local network beyond localhost.

You have to type ctrl c to end the mosquitto_sub sessions.
What IP addresses do the two Pies have?

Sorry but the machine had already been shutdown. For "jbudd" , I have run those tests before several times as they are part of the course where this came from. They are run twice, for each method, with or without credentials and they both passed each time. And this also involved the change in the "allow_anonymous true/false argument.

For Colin here is the code

[
    {
        "id": "689a8ea47644053d",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "b6155752bb50aee3",
        "type": "inject",
        "z": "689a8ea47644053d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "on",
        "payloadType": "str",
        "x": 90,
        "y": 40,
        "wires": [
            [
                "9a39b2806f7222a9"
            ]
        ]
    },
    {
        "id": "1bb338149dbb5a45",
        "type": "inject",
        "z": "689a8ea47644053d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "off",
        "payloadType": "str",
        "x": 90,
        "y": 80,
        "wires": [
            [
                "9a39b2806f7222a9"
            ]
        ]
    },
    {
        "id": "9a39b2806f7222a9",
        "type": "ui_switch",
        "z": "689a8ea47644053d",
        "name": "",
        "label": "hot water switch",
        "tooltip": "",
        "group": "59214996.9e7fa8",
        "order": 2,
        "width": 0,
        "height": 0,
        "passthru": true,
        "decouple": "false",
        "topic": "topic",
        "topicType": "msg",
        "style": "",
        "onvalue": "on",
        "onvalueType": "str",
        "onicon": "",
        "oncolor": "",
        "offvalue": "off",
        "offvalueType": "str",
        "officon": "",
        "offcolor": "",
        "animate": false,
        "className": "",
        "x": 260,
        "y": 40,
        "wires": [
            [
                "e3c33b8cea1044d3"
            ]
        ]
    },
    {
        "id": "e3c33b8cea1044d3",
        "type": "mqtt out",
        "z": "689a8ea47644053d",
        "name": "",
        "topic": "home/office/4004_05",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "db9e6b85.5d9138",
        "x": 300,
        "y": 100,
        "wires": []
    },
    {
        "id": "0c901105ef2f5220",
        "type": "mqtt in",
        "z": "689a8ea47644053d",
        "name": "home/office/4004_05/state",
        "topic": "home/office/4004_05/state",
        "qos": "0",
        "datatype": "utf8",
        "broker": "db9e6b85.5d9138",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 510,
        "y": 40,
        "wires": [
            [
                "13c8d3adde1bdcc5",
                "55c3de60066c6f24"
            ]
        ]
    },
    {
        "id": "55c3de60066c6f24",
        "type": "debug",
        "z": "689a8ea47644053d",
        "name": "payload",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 560,
        "y": 140,
        "wires": []
    },
    {
        "id": "13c8d3adde1bdcc5",
        "type": "ui_text",
        "z": "689a8ea47644053d",
        "group": "59214996.9e7fa8",
        "order": 3,
        "width": 0,
        "height": 0,
        "name": "hot water 05",
        "label": "hot water 05",
        "format": "{{msg.payload}}",
        "layout": "row-left",
        "className": "",
        "style": false,
        "font": "",
        "fontSize": 16,
        "color": "#000000",
        "x": 650,
        "y": 100,
        "wires": []
    },
    {
        "id": "617096ee77322e1f",
        "type": "inject",
        "z": "689a8ea47644053d",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 180,
        "y": 200,
        "wires": [
            [
                "dc65bce4f64b4193"
            ]
        ]
    },
    {
        "id": "dc65bce4f64b4193",
        "type": "mqtt out",
        "z": "689a8ea47644053d",
        "name": "test1",
        "topic": "test1",
        "qos": "0",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "db9e6b85.5d9138",
        "x": 310,
        "y": 200,
        "wires": []
    },
    {
        "id": "5a742421a7d6bf20",
        "type": "mqtt in",
        "z": "689a8ea47644053d",
        "name": "",
        "topic": "test1",
        "qos": "0",
        "datatype": "auto-detect",
        "broker": "db9e6b85.5d9138",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 430,
        "y": 200,
        "wires": [
            [
                "b577b09cb827cefc"
            ]
        ]
    },
    {
        "id": "b577b09cb827cefc",
        "type": "debug",
        "z": "689a8ea47644053d",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 200,
        "wires": []
    },
    {
        "id": "59214996.9e7fa8",
        "type": "ui_group",
        "name": "4004",
        "tab": "4c1cfcd6.cb35c4",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "db9e6b85.5d9138",
        "type": "mqtt-broker",
        "name": "home/office/4004_05",
        "broker": "localhost",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "4c1cfcd6.cb35c4",
        "type": "ui_tab",
        "name": "HOME",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    },
    {
        "id": "f4cd884f4e9b85e2",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-dashboard": "3.6.6"
        }
    }
]

Back to work on the rebuild

Concerning the switch; has the Mosquitto broker: user name and password been set to match on the switch?

What about the rest of the switch's configuration?

Reference: Setting up the Tasmota MQTT Switch (Sonoff)

Umm Your network is identical to @dynamicdave's with the possibly insignificant difference that your Pies are connected by ethernet and he shows his as wifi.

I find it unlikely that your procedures are exact duplicates of the ones I suggested in Post 105 above.

Firstly, you said you edited /etc/mosquitto/mosquitto.conf, wheras the above procedures populate /etc/mosquitto/conf.d/my.conf.

Secondly, nobody in their right mind would use printf "%s\n%s\n" "listener 1883" "allow_anonymous true" | sudo tee /etc/mosquitto/conf.d/my.conf when they could simply use sudo nano /etc/mosquitto/conf.d/my.conf, unless they were trying to avoid the use of an editor program.
When you posted the contents of your mosquitto.conf, the first few lines were in large font. It occurred to me that you maybe got spurious characters in the file, causing Mosquitto to reject it and fall back to defaults. So I offered an alternative approach not involving an editor.

Are you really saying that using mosquitto_pub and mosquitto_sub you have successfully passed MQTT messages from the old Pi to the new one?

And using mosquitto_sub have you ever seen messages published by the Sonoff arrive on the new Pi?

That is because the forum has interpreted it as markdown, so lines starting with # are interpreted as headers. I have edited the file to add triple backticks around the text.

Actually my set-up has the Pi connected by Ethernet CAT cable and the SonOff switch by WiFi.


Not completely accurate visually - it's the best I could draw.

1 Like

Here is the latest report. Sunday afternoon CDT
I rebuilt the system in accordance with "jbudd" procedure posted above (105) including the four line "mosquitto.conf" file and the two line "my.conf" file located in the conf.d directory. I logged into the new system on my pc and opened the nodered. The timestamp flow worked fine producing an output in the debug pane. However, this worked before . I then imported the flow that I put on here earlier and deployed it. IT WORKED except, there is still no output to the debug pane. The switch in question turns on and off as desired. But there is no message output.
I can operate the switch from another pc on the network as well but no message gets to that machine either. I then opened the old system in another window and compared settings and the only thing I noticed was that the old system has a box checked off that says "use legacy 3.1" protocol. I tried setting that in the new system and it made no difference so I returned it to the original 3.1.1 value.

I don't intend to try the added security mode until I get this to work.
Partial success.
I also do not intend to look at it any more this evening.
Charles

If the MQTT password is wrong, the Tasmota device will fail to connect to the broker.

The device will repeatedly attempt to connect, logging messages like MQT: Connect failed to [broker_ip]:1883, rc 5. Retry in X sec . The rc 5 indicates an "unauthorized" connection error due to invalid credentials.

The switch will be unresponsive to commands from the MQTT broker until the correct password is configured in the Tasmota web interface under Configuration > Configure MQTT .

Is this now your current situation?
You now have two Raspberry Pi boards each running Node-RED and the Mosquitto broker?
Do the boards have different IP addresses?
We know one is 192.168.1.151, what is the other's IP address ?

If they have different IP addresses, you could enter 192.168.1.151 as the broker credentials in the Node-RED flow on the NEW RPi, so that RPi would be using the broker on your old machine (that works correctly). It would isolate the broker on your new machine and would be a temporary measure just to aid debugging.

Looking at the flow you posted above, you still have localhost in all four MQTT nodes.

As @jbudd said...
IP address 127.0.0.1 AKA localhost is the Raspberry Pi itself. This is Node-RED trying to connect.
I cannot comprehend what circumstances might cause connection not authorised for localhost if allow_anonymous is true.

Been following this thread.

It "worked" tells me that the broker is receiving the topic, but the in node is not receiving the stat topic. It's confusing without actually seeing the flow you are actually testing with. If my understanding is correct, have you tried setting the in node to topic # you would then receive all publication from the broker.

Please supply the test flow you are currently using for clarification.

1 Like

This is what @E1cid means...


I would also select the Output option as 'auto-detect'

I notice your Debug node is turned-off, was that intentional ?

image

Should that not be localhost?

The OP is not using user names/passwords on the MQTT broker.
That can be verified by the fact the MQTT nodes connect and there is no user/pwd specified there.

Now that you have the switch connecting you can look in MQTTExplorer again to see what topics it is publishing on.

That's just a label/name. If it is 'clicked' it will show the broker's details 'localhost'

Yes, but to give the broker the name of one of the remote devices is just going to cause confusion.

1 Like

Becomes relevant when user names and passwords are used...

Monday morning here in north Texas. The whole thing is working now with the exception of showing the state message in the Debug pane. I can operate the switch from two pcs and from my phone using a simple user interface built right there in the NR flow page. I discovered that it was working by going to the MQTTEX as Colin suggested. The state was showing there when I injected to the in/out nodes.
https://drive.google.com/file/d/1xB8890TtLepZO7Oq06syh7NvLRliW71t/view?usp=sharing
https://drive.google.com/file/d/1f_hY-h4POOgUTznZ_6pfM4TYfFOpuheN/view?usp=sharing

So now the puzzle is why no debug entry? The state msg is what controls the on/off display on the simple interface(dashboard). The question is where does the message get lost. The message appears on the MQTTEX. And it operates the on/off display of the ui.

As I said before thanks to all who hung in there. I genuinely appreciate this
Charles

If you are still using the NR flow you posted above - then your Debug node is turned-off, was that intentional ? It is greyed-out. You need to click-it and turn it on to see the debug messages.