-
Notifications
You must be signed in to change notification settings - Fork 15
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
Sensors with Multiple Values #6
Comments
You may be able to do this with plapointe6/HaMqttConfigBuilder Here how: // Publish this to: homeassistant/sensor/sensorBedroomT/config
String generateConfigPayload1() {
return HaMqttConfigBuilder()
.add("device_class", "temperature")
.add("name", "Temperature")
.add("state_topic", "homeassistant/sensor/sensorBedroom/state")
.add("unit_of_measurement", "°C")
.add("value_template", "{{ value_json.temperature}}")
.generatePayload();
}
// Publish this to: homeassistant/sensor/sensorBedroomH/config
String generateConfigPayload2() {
return HaMqttConfigBuilder()
.add("device_class", "humidity")
.add("name", "Humidity")
.add("state_topic", "homeassistant/sensor/sensorBedroom/state")
.add("unit_of_measurement", "%")
.add("value_template", "{{ value_json.humidity}}")
.generatePayload();
}
// To generate { "temperature": 23.20, "humidity": 43.70 }
String generateValuesPayload(const double temperature, const double humidity) {
return HaMqttConfigBuilder()
.add("temperature", temperature)
.add("humidity", humidity)
.generatePayload();
} I will replace HAMqttDevice by the new lib HaMqttConfigBuilder soon in my other projects. |
Oh, cool! What the main difference between HAMqttDevice and the new HaMqttConfigBuilder? |
HaMqttConfigBuilder is simple and tiny. It is a tool to generate key/value pairs into a JSON string. So, why replace HAMqttDevice with HaMqttConfigBuilder if HAMqttDevice does, in fact, more things?
I will update my IoT devices soon and I will put more examples into HaMqttConfigBuilder. |
As per the Home Assistant MQTT Discovery Documentation, it is possible to define a single sensor that can define multiple values in a single payload (with multiple configs needed) by defineing a
value_template
for each that use the samestate_topic
.As far as I can tell, this is not possible with this library. Is that correct? Would it be much work to add support for this?
https://www.home-assistant.io/docs/mqtt/discovery/#sensors-with-multiple-values
The text was updated successfully, but these errors were encountered: