2.7 KiB
FullTopic Equals Sign Fix Summary
Issue Description
When setting the MQTT FullTopic parameter, an extra equals sign ('=') was being added to the beginning of the value. For example, instead of setting the FullTopic to %prefix%/%topic%/, it was being set to =%prefix%/%topic%/.
Root Cause
The issue was related to how the Tasmota device interprets the command when an equals sign is used as a separator between the command and the value. When using the format:
http://{ip}/cm?cmnd=FullTopic={value}
The Tasmota device was interpreting this as a command to set the FullTopic to ={value} rather than just {value}.
Investigation
A test script was created to reproduce the issue and test different approaches for setting the FullTopic parameter. The script tested several methods:
- Current approach (setting=value):
http://{ip}/cm?cmnd=FullTopic={full_topic} - URL encoded value:
http://{ip}/cm?cmnd=FullTopic={urllib.parse.quote(full_topic)} - Using space (%20) instead of equals:
http://{ip}/cm?cmnd=FullTopic%20{full_topic} - Backslash before equals:
http://{ip}/cm?cmnd=FullTopic\={full_topic} - Double equals:
http://{ip}/cm?cmnd=FullTopic=={full_topic} - No separator (direct value):
http://{ip}/cm?cmnd=FullTopic{full_topic}
The testing revealed that three approaches worked correctly:
- Using space (%20) instead of equals
- Backslash before equals
- No separator (direct value)
Solution
The "no separator" approach was chosen as the simplest and most reliable solution. The code was modified in two places:
- In the
configure_unknown_devicemethod:
# For FullTopic, we need to avoid adding a space (%20) or equals sign between the command and value
if setting == "FullTopic":
url = f"http://{ip}/cm?cmnd={setting}{value}"
else:
url = f"http://{ip}/cm?cmnd={setting}%20{value}"
- In the
check_mqtt_settingsfunction:
# For FullTopic, we need to avoid adding a space (%20) or equals sign between the command and value
if setting == "FullTopic":
url = f"http://{ip}/cm?cmnd={setting}{value}"
else:
url = f"http://{ip}/cm?cmnd={setting}%20{value}"
Testing
The fix was tested by running the TasmotaManager.py script with the --Device parameter and verifying that the FullTopic parameter was set correctly without the extra '=' at the beginning of the value.
Before the fix:
{"FullTopic":"=%prefix%/%topic%/"}
After the fix:
{"FullTopic":"%prefix%/%topic%/"}
Conclusion
The issue has been resolved by changing how the FullTopic parameter is set. Instead of using an equals sign as a separator between the command and value, the fix uses no separator at all, which prevents the Tasmota device from adding an extra equals sign to the beginning of the value.