3.2 KiB
UniFi OS Hostname Tracking Fix
Issue Description
The UniFi OS has an issue with keeping track of host names. If a hostname is updated and the connection reset, UniFi will not keep track of the new name. When in Device mode, when the user enters a new hostname, the script updates the name, but UniFi OS may not pick up the new name.
Solution Implemented
A new feature has been added to the TasmotaManager.py script to address this issue. The solution works as follows:
-
When in Device mode (processing by IP) and a device's hostname or name matches an unknown_device_pattern:
- The script now checks the device's self-reported hostname before declaring it as unknown
- It makes an HTTP request to the device using the Tasmota Status 5 command to get network information
- It extracts the self-reported hostname from the response
-
Decision logic:
- If the device's self-reported hostname also matches an unknown_device_pattern, the device is declared as unknown (both UniFi and device agree)
- If the device's self-reported hostname does NOT match any unknown_device_pattern, the device is NOT declared as unknown (assuming UniFi OS bug)
- If the device doesn't respond or there's an error getting the self-reported hostname, the script falls back to using the UniFi-reported name
-
Error handling:
- HTTP request failures
- JSON parsing errors
- Missing hostname in response
- Other exceptions
Code Changes
The main changes were made in the process_single_device method in TasmotaManager.py:
- Renamed the original hostname check result to
unifi_name_matches_unknownto distinguish it from the finalis_unknowndetermination - Added code to check the device's self-reported hostname when in Device mode
- Implemented the decision logic described above
- Added detailed logging to track the decision-making process
- Added comments explaining the purpose of the feature
Testing
To test this feature in a real environment:
- Find a device that has been renamed but UniFi still shows the old name
- Run TasmotaManager in Device mode with the IP address of the device
- Verify that the script correctly identifies the device's self-reported hostname
- Confirm that the device is not declared as unknown if its self-reported hostname doesn't match unknown_device_patterns
Benefits
This enhancement improves the user experience by:
- Reducing false positives when identifying unknown devices
- Working around the UniFi OS bug that doesn't properly track hostname changes
- Providing more accurate device identification in Device mode
- Adding detailed logging to help troubleshoot hostname-related issues
Alternative Solution for UDM-SE
For UDM-SE devices specifically, there is an alternative workaround to force UniFi to recognize new host names:
- Navigate to the UDM-SE admin interface
- Go to "Settings/Control Plane/Console/Restart"
- Restart the UDM-SE
- When the UDM-SE comes back online (which takes several minutes), it will have the updated host names
This method can be useful in situations where the script's built-in workaround is not sufficient or when you need to ensure that all devices have their correct hostnames recognized by the UniFi controller.