MQTT - blank state_topic allowed in code but not configuration
- Dominant language
- No language data
- Stars
- 313
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
### The problem
I have discovered that it is not possible to stop MQTT from publishing all sensor topics.
I am told that the C++ code allows for blank `state_topic` to prevent publishing per sensor, but the configuration validation prevents the blank topic.
https://github.com/esphome/esphome/blob/dev/esphome/components/mqtt/mqtt_component.cpp#L42-L46
https://github.com/esphome/esphome/blob/dev/esphome/config_validation.py#L1030-L1035
Could a blank `state_topic` be allowed to prevent the publishing by MQTT.
I am developing a custom component and only want to publish a custom payload to MQTT.
### Which version of ESPHome has the issue?
2022.9.2
### What type of installation are you using?
Home Assistant Add-on
### Which version of Home Assistant has the issue?
2022.9.7
### What platform are you using?
ESP8266
### Board
WEMOS D1 mini V3
### Component causing the issue
MQTT
### Example YAML snippet
```yaml
sensor:
- platform: emontx4
vrms:
id: iv
name: Vrms
retain: false
state_topic:
```
### Anything in the logs that might be useful for us?
_No response_
### Additional information
I also think that the automatic publishing of MQTT topics is something born out of the old mechanism for communicating with HA.
In a more diverse ecosystem, it should be possible to disable MQTT from publishing all these topics and flooding Brokers. A top level setting to disable all automatic publishing and then allow it to be enabled on a sensor by sensor basis.
So if Discovery disabled, allow as secondary setting to disable MQTT standard publishing.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.