ironsheep / RPi-Reporter-MQTT2HA-Daemon

Linux service to collect and transfer Raspberry Pi data via MQTT to Home Assistant (for RPi Monitoring)
GNU General Public License v3.0
460 stars 64 forks source link

Would like the ability to connect multiple Rpi's to display in HA. #89

Closed andycockerill-cpi closed 1 year ago

andycockerill-cpi commented 1 year ago

Is your feature request related to a problem? Please describe. I have multiple Raspberry PI's, but can only seem to be able to connect one at a time to Home Assistant.

Describe the solution you'd like The ability connect more than one Rpi

Describe alternatives you've considered Considered setting up multiple mqtt instances, but HA only supports one at a time.

Additional context This from the HA logs... Platform mqtt does not generate unique IDs. ID RPi-Mon_monitor already exists - ignoring sensor.rpi_monitor...

ironsheep commented 1 year ago

@andycockerill-cpi You should already be able to do this. I have a dashboard of 20+ RPi devices in use in HA.

Please check each of your RPi's for a running version of ifconfig.

This is used by the Daemon script to get your RPi mac address from which it generates the unique ID for the RPi.

There are special install instructions for getting this installed on your RPi if it is not present. Check the top-level readme for these instructions.

Please reply here with what you find...

andycockerill-cpi commented 1 year ago

Thank you for the info, so should the entry reported by HA in the logs contain an mac address?

"RPi-Mon_monitor"

I do have ifconfig installed.

ironsheep commented 1 year ago

@andycockerill-cpi ok, so take a look here: https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/blob/master/HA-ADVERT.md#the-monitor-endpoint. this is one example of what is "advertised" to Home Assistant.

If you get MQTT explorer and point it to your MQTT Broker then you should see what your RPi's are advertising. Here's part of what I see for my installation:

Screenshot 2023-03-04 at 2 23 50 PM

What you are looking for is that the "uniq_id" value for each RPi you have is really unique and looks similar to what I'm showing.

I also have notes for how to run the daemon by hand to get a sense of what it's reporting: https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon#general-debug

bsimmo commented 1 year ago

For a Pi, the UniqueID would usually be created from its serial number (which is made up from its mac address if it has one) for most things. Not sure if this would solve problems where mac address may change as the one being read. I've not looked how you are using it from ifconfig, but If I turn off/on my WiFi and switch to/from Ethernet, wouldn't that create a new ID ? There are options that may change the mac? Or a PiZero/A+ and I just switch USB dongles. or if I stick in a USB WiFi USB and the order changes, it would have the chance of a new ID? or randomised mac option set.

I have the python code somewhere.

ironsheep commented 1 year ago

@bsimmo I use the mac from the connection that has an IP at the time the daemon starts. So the USB/dongles shouldn't matter, I think. If you have both wired and wifi connected it likely picks the first in the list.

Standing by to hear what @andycockerill-cpi next finds out...

andycockerill-cpi commented 1 year ago

Thank you for all your comments, and apologies for not getting back to you sooner. This has now started working for me, so maybe it was a timing issue or some such.

bsimmo commented 1 year ago

Just adding in case it could be added as an option for the UniqueID

The usual way to generate a serial on a RaspberryPi is using something like this. It avoids changes of wlan/lan/addon wifi/lan controllers and doesn't need other programs, it's baked into the SoC. On the odd chance it may be a problem. Can use 10:26 depending on how much you want, but don't think the first bit tell you anything of the actual serial.

def get_serial():
    # Extract serial from cpuinfo file
    cpuserial = "N0N0N0N0"
    try:
        f = open('/proc/cpuinfo','r')
        for line in f:
            if line[0:6]=='Serial':
                cpuserial = line[18:26]
        f.close()
    except:
        cpuserial = "ERROR000"

    return cpuserial

*On the odd chance it may be a problem.