RPi-Reporter-MQTT2HA-Daemon
                                
                                
                                
                                    RPi-Reporter-MQTT2HA-Daemon copied to clipboard
                            
                            
                            
                        Should {hostname} be replaced with hostname?
Checklist:
- [X] I updated to the latest version available
 - [X] I checked that my MQTT broker is otherwise working
 
Release with the issue:
2024.01.28 master
Last working release (if known): N/A
Hardware, Operating System, Python version:
RPi zeros, Raspbian 11
Description of problem:
I've tried to setup this project on 3 RPi I got - 2 had no problem displaying their name (hostname -f),  1 had such a problem.  However, to be sure in config.ini I set fallback to their names.
When running systemctl status I see for all of them the following:
systemctl status isp-rpi-reporter.service
● isp-rpi-reporter.service - RPi Reporter MQTT Client/Daemon
     Loaded: loaded (/opt/RPi-Reporter-MQTT2HA-Daemon/isp-rpi-reporter.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2024-01-28 00:59:41 GMT; 2s ago
       Docs: https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon
   Main PID: 28680 (python3)
     Status: "Jan 28 00:59:40 - * NOTIFY: on_message() Topic=[home/rpi-nodes/command/rpi-{hostname}/status] payload=[b'offline'] command=[status]."
      Tasks: 4 (limit: 414)
        CPU: 13.648s
     CGroup: /system.slice/isp-rpi-reporter.service
             └─28680 /usr/bin/python3 -u /opt/RPi-Reporter-MQTT2HA-Daemon/ISP-RPi-mqtt-daemon.py
In Status line I see "rpi-{hostname}" - is this correct? I mean, since this is my first setup with this project, I had the following doubts:
- the hostname was not found and was not replaced
 - I should have replaced {hostname} in config.ini with real name (it is not so obvious)
 - the log shows topic before evaluation of the placeholder and there's nothing to worry about
 
Expectations:
- I think in status (logs) one should see the final result
 - example 
config.ini.distshould have additional explanation abovetopicthat {hostname} will be replaced with a proper hostname (using fallback if required) - If there was a problem with hostname resolution, the topic nor the name should not contain 
no_address_associated_with_hostname, but something likefqdn-unknownorfqdn-unknown-IP(where IP is the IP :) ). The sensor name looks like this (even if I fixed the problem hostname resolution /I guess I need to reset sth and re-add it to HA):sensor.rpi_my_raspberrypi_rpi_monitor_hostname_no_address_associated_with_hostname. And btw, why hostname is present in two times in entity name (on the beginning and at the end)? 
When I leave {hostname} in configuration. Still I don't know if it should be replaced automatically, or I should edit that.
In the config.ini you create.
This
The MQTT name for this Raspberry Pi as a sensor
#sensor_name = rpi-{hostname}
Should be left as is with the # to have it ignored in the program and send the hostname the Pi itself has been given by you.
You only un-comment that and alter the hostname to give it something different to the default or if it is not working. Change rpi-{hostname} to whatever you want, this is the sensor name not the actual hostname you are changing. It is there as some people wanted deb-{hostname} or ubuntu-{hostname} or even Sillysensoratrpi{hostname}devicething
On Sun, 28 Jan 2024, 3:45 pm Piotr Skowronek, @.***> wrote:
obraz.png (view on web) https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/assets/360665/d6515fac-b445-4a4c-929f-7c830dddcb71
When I leave {hostname} in configuration. Still I don't know if it should be replaced automatically, or I should edit that.
— Reply to this email directly, view it on GitHub https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/issues/131#issuecomment-1913639184, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXN2F4YKAG46NPAVE2P3YQZXADAVCNFSM6AAAAABCNY2UECVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJTGYZTSMJYGQ . You are receiving this because you are subscribed to this thread.Message ID: @.*** com>
Are you using RaspberryPi OS from RaspberryPi.com / Pi Imager or some other version of it?
PiOS '11' is Bullseye so should just work.
Hostname it retrieved from /bin/hostname -f If that doesn't work, try fix that.
If you cannot then you change # default domain to use when hostname -f doesn't return a proper fqdn #fallback_domain = home
Remove the # and change home to whatever you want.
Are you using RaspberryPi OS from RaspberryPi.com / Pi Imager or some other version of it?
I have bullseye RaspberryPi OS.
PiOS '11' is Bullseye so should just work.
Hostname it retrieved from /bin/hostname -f If that doesn't work, try fix that.
I've already mentioned that I've fixed the problem with hostname -f.
If you cannot then you change # default domain to use when hostname -f doesn't return a proper fqdn #fallback_domain = home
The comment in config.ini.dist above sensor_name should better state this:
"Should be left as is with the # to have it ignored in the program and send
the hostname the Pi itself has been given by you. "
Otherwise one may think that sensor_name = rpi-{hostname} must be un-commented, and {hostname} will be replaced in runtime either by hostname or fallback_domain.
Remove the # and change home to whatever you want.
Thanks. But what I aim here is to make this behavior more obvious - both in README.md (installation part) and in config.ini.dist .
You'll see some other topics/pulls that are open that do just this or talk about it, I have just commented to a few just now so you can see some. #122 #126 So you're not the only one. Feel free to edit and make a pull request, though there are a few good ones waiting already, #126 #106 @ironsheep seems to be busy, away, working things out.
Remember this is his project for something he wanted, everything else is a bonus and tagged on for others :)
Given that change is not talked about in the normal setup, it's really an advanced setup. Maybe an advanced setup/wiki page needs creating for the other options. and linked to from ironsheep/RPi-Reporter-MQTT2HA-Daemon: Linux service to collect and transfer Raspberry Pi data via MQTT to Home Assistant (for RPi Monitoring) (github.com) https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon?tab=readme-ov-file#configuration ?
I was unsure if you had fixed the hostname on the one not working, hence you were editing the config.ini to try fix it, just the wrong bit.
On Sun, 28 Jan 2024 at 17:37, Piotr Skowronek @.***> wrote:
Are you using RaspberryPi OS from RaspberryPi.com / Pi Imager or some other version of it?
I have bullseye RaspberryPi OS.
PiOS '11' is Bullseye so should just work.
Hostname it retrieved from /bin/hostname -f If that doesn't work, try fix that.
I've already mentioned that I've fixed the problem with hostname -f.
If you cannot then you change # default domain to use when hostname -f doesn't return a proper fqdn #fallback_domain = home
The comment in config.ini.dist above sensor_name should better state this: "Should be left as is with the # to have it ignored in the program and send the hostname the Pi itself has been given by you. "
Otherwise one may think that sensor_name = rpi-{hostname} must be un-commented, and {hostname} will be replaced in runtime either by hostname or fallback_domain.
Remove the # and change home to whatever you want.
Thanks. But what I aim here is to make this behavior more obvious - both in README.md (installation part) and in config.ini.dist .
— Reply to this email directly, view it on GitHub https://github.com/ironsheep/RPi-Reporter-MQTT2HA-Daemon/issues/131#issuecomment-1913670391, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACYAXNYT52DTPX5XRIMMGL3YQ2EHJAVCNFSM6AAAAABCNY2UECVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMJTGY3TAMZZGE . You are receiving this because you commented.Message ID: @.***>
Remember this is his project for something he wanted, everything else is a bonus and tagged on for others :)
Yup, and this is very great project! I've already submitted 2 PR to it to make it more easier to use :)
First I wanted to see whether {hostname} should be dereferenced or not. I see those PR you have mentioned @bsimmo - Let's wait for PR review. Personally I would add better comments to config.ini.dist to explain the behavior and what's the default.
Maybe let's keep this "bug" open so it could be discussed how to make it more obvious how to use it.