TasmotaManager/fulltopic_equals_fix_summary.md

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:

  1. Current approach (setting=value): http://{ip}/cm?cmnd=FullTopic={full_topic}
  2. URL encoded value: http://{ip}/cm?cmnd=FullTopic={urllib.parse.quote(full_topic)}
  3. Using space (%20) instead of equals: http://{ip}/cm?cmnd=FullTopic%20{full_topic}
  4. Backslash before equals: http://{ip}/cm?cmnd=FullTopic\={full_topic}
  5. Double equals: http://{ip}/cm?cmnd=FullTopic=={full_topic}
  6. No separator (direct value): http://{ip}/cm?cmnd=FullTopic{full_topic}

The testing revealed that three approaches worked correctly:

  1. Using space (%20) instead of equals
  2. Backslash before equals
  3. 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:

  1. In the configure_unknown_device method:
# 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}"
  1. In the check_mqtt_settings function:
# 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.