Abstract :
ESPHOME sends an MQTT message per sensor, binary sensor, textsensor …). If many sensors are in use, then a large number of messages are sent to the MQTT Brocker via the network.
Improvement: Bundling of the MQTT messages per sensor that are connected to a board.
Example: ESP32 with DHT, BH1750FVI, AS3935, SDS011.
ESPHOME MQTT: 24 MQTT messages ESPHOME Custom MQTT: 1 Message!
I am currently using platform: uptime to only send one MQTT message.
- How can I prevent values that are not available (NaN) from being sent as a payload.
- How can I group the values of the sensors in the payload?
I haven’t found a way to do this through the root object.
Is there a solution for this ?
# Uptime Sensor
# see: https://esphome.io/components/sensor/uptime.html?highlight=uptime
- platform: uptime
id: upti
name: "${friendly_name} Uptime"
update_interval: ${publish_interval}
state_topic: tele/${device_name}/uptime
on_value:
- wait_until:
mqtt.connected:
- mqtt.publish_json:
topic: tele/$device_id/infodata
payload: |-
root["dht_temperature"] = id(temp).state;
root["dht_humidity"] = id(rh).state;
root["dht_humidity_abs"] = id(rha).state;
root["dht_dewpoint"] = isnan(id(taupunkt).state) ? id(temp).state : id(taupunkt).state;
root["dht_heatindex"] = isnan(id(heatindex).state) ? id(temp).state : id(heatindex).state;
root["bh1750_light"] = id(lightsensor).state;
root["sds011_pm10"] = isnan(id(pm10).state) ? -1 : id(pm10).state;
root["sds011_pm25"] = isnan(id(pm25).state) ? -1 : id(pm25).state;
root["ightning_energy"] = isnan(id(asbe).state) ? -1 : id(asbe).state;
root["lightning_distance"] = isnan(id(asdis).state) ? 10000 : id(asdis).state;
root["lightning_warning"] = id(sturm).state;
root["sun_elevation"] = isnan(id(sune).state) ? -1 : id(sune).state;
root["sun_azimuth"] = isnan(id(suna).state) ? -1 : id(suna).state;
root["sun_sunrise"] = id(sunup).state;
root["sun_sunset"] = id(sundown).state;
root["wifisignal"] = id(wifisignal).state;
root["wifiip"] = id(wifiip).state;
root["wifissid"] = id(wifissid).state;
root["wifibssid"] = id(wifibssid).state;
root["uptime"] = id(upti).state;
root["timestamp"] = id(systime).state;
root["version"] = id(appver).state;
root["appversion"] = "${appversion}";
root["attribution"] ="${attribution}";
- logger.log: "MQTT Data published"
Result:
{
"dht_temperature": 24.4,
"dht_humidity": 65.6,
"dht_humidity_abs": 14.49275,
"dht_dewpoint": 17.41075,
"dht_heatindex": 24.4,
"bh1750_light": 68.33333,
"sds011_pm10": 6.7,
"sds011_pm25": 3.7,
"ightning_energy": -1,
"lightning_distance": 10000,
"lightning_warning": false,
"sun_elevation": 32.72499,
"sun_azimuth": 245.7026,
"sun_sunrise": "06:33:18",
"sun_sunset": "20:08:40",
"wifisignal": -56,
"wifiip": "10.1.1.71",
"wifissid": "McNessi",
"wifibssid": "88:1B:A6:34:3E:82",
"uptime": 5334.562,
"timestamp": "2020-08-28 16:44:49",
"version": "1.15.0b4 Aug 27 2020, 14:49:39",
"appversion": "1.0.0",
"attribution": "Data provided by ESPHome"
}
This would be the result I want:
{
"dht": {
"temperature": 24.5,
"humidity": 55.2,
"humidity_abs": 12.39751,
"dewpoint": 14.91253,
"heatindex": 24.5
},
"bh1750": {
"light": 69.16666
},
"sds011": {
"pm10": 5.4,
"pm25": 3.1
},
"as3935": {
"lightning": -1,
"distance": 10000,
"warning": false
},
"sun": {
"elevation": 48.97265,
"azimuth": 208.4818,
"sunrise": "06:33:18",
"sunset": "20:08:40"
},
"wifi": {
"signal": -55,
"ip": "10.1.1.71",
"ssid": "McNessi",
"bssid": "88:1F:A1:34:3E:82"
},
"system": {
"uptime": 56.503,
"timestamp": "2020-08-28 14:35:11",
"version": "1.15.0b4 Aug 27 2020, 14:49:39",
"appversion": "1.0.0",
"attribution": "Data provided by ESPHome"
}
}
How can I solve this ?