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
442 stars 62 forks source link

change for non rpi- sensor names #95

Open drumbo opened 1 year ago

drumbo commented 1 year ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]

Describe the solution you'd like A clear and concise description of what you want to happen.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Hi,

This is a fantastic capability so thank you for supporting it. I know it is primarily for raspberries - however it is mentioned on your help page about debian/ubuntu etc. I have tested it on my debian server and it works well except when I change the sensor_name from rpi-{hostname} to (in my case) deb-{hostname}

if I do that - then the script doesn't replace the hostname with the actual hostname resulting in deb-{hostname} in the MQTT message. I made this change to the python script - but I am not sure it is the correct way to do it. Is it possible to handle this rather fringe case?

get our hostnames so we can setup MQTT

getHostnames() if(sensor_name == default_sensor_name): sensor_name = 'rpi-{}'.format(rpi_hostname) else: sensor_name = sensor_name.replace('{hostname}','{}').format(rpi_hostname)

Thanks again

ironsheep commented 1 year ago

@drumbo I'm unclear if you found the config.ini setting:

# The MQTT name for this Raspberry Pi as a sensor
#sensor_name = rpi-{hostname}

If you set this to deb-hostname does it do what you want? Example:

# The MQTT name for this Raspberry Pi as a sensor
sensor_name = deb-{yourHostname}

(Replace the {yourHostname} with your actual host name)

If you are asking for a replacement prefix the current version does not do that but it wouldn't be too hard to add.

drumbo commented 1 year ago

Hi,

Yes - I did find that - however (if I remember correctly) it came out as "deb-" with no hostname. This seems to be due to the if statement which populates the hostname for rpi-xxxxx based on the server - but for deb- it doesn't. I understand one can simply put deb-xxxx - but as you grab the hostname for rpi - can it not be done for any other variant one uses?

if(sensor_name == default_sensor_name): sensor_name = 'rpi-{}'.format(rpi_hostname)

As the config = deb- this isn't hit and therefore the hostname is never set. Unless I am mistaken - having the else would then work. (although probably better

bsimmo commented 5 months ago

What you're asking is have it check for {hostname} in the string and have it replace it at run time, rather than having to manually change {hostname} in the config. This way you can just override rpi- with whatever you want and not worry about it on each device.