-
-
Notifications
You must be signed in to change notification settings - Fork 114
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MQTT auto-discovery/publish broken for analog sensors attached to GPIOs lower than 10 #915
Comments
Thanks for reporting. |
agree. Thanks for the detailed breakdown @gwilford |
Using "04" does look better. It would break existing uniq_id but only for configs using low GPIOs which I don't think are working anyway. However, changing the publish from "04" to "4" might break anyone who had manually configured an MQTT subscribe in HA... |
OK, just tested and can't seem to add a manual HA mqtt sensor with "0" prefix. This fails to parse:
with whereas this parses just fine:
In summary, I don't think changing the publish to "4" would break anyone who had tried to manually configure within HA and it may well be safer. |
I think this should be |
Sorry, spoke too soon. This does currently work if manually configured as below:
Either fix works for me though. |
in dev-16 |
Description
Attaching an analog sensor to GPIO 4 results in "unknown" values in HA
Steps to reproduce
Configure GPIO less than 10 (e.g. 4) as ADC in UI (no need to connect anything to the pin)
Check value of entity in HA - it will be "unknown"
Expected behaviour
The value in HA should be 0 (or the measured value)
The issue
Data from MQTT Explorer.
The MQTT auto-discovery config:
The MQTT publish:
The config refers to 4 whereas the publish is for 04
This is due to use of the following function in helpers.cpp for the publish but not for the config
Formatting the publish on line 375 of analogsensor.cpp:
JsonObject dataSensor = doc.createNestedObject(Helpers::smallitoa(s, sensor.gpio()));
Formatting the config on line 403:
snprintf(str, sizeof(str), "{{value_json['%d'].value}}", sensor.gpio());
Using smallitoa() to format the config or removing it from the publish should fix this.
Firmware v3.4.4
The text was updated successfully, but these errors were encountered: