Skip to content
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

ESPHome: Using metadata for improving instant Grafana dashboards #71

Open
amotl opened this issue Nov 20, 2021 · 1 comment
Open

ESPHome: Using metadata for improving instant Grafana dashboards #71

amotl opened this issue Nov 20, 2021 · 1 comment

Comments

@amotl
Copy link
Member

amotl commented Nov 20, 2021

Hi once more,

while working on the support for ESPHome (#67), we found that it offers a nice capability in the spirit that it will publish metadata information about each sensor to the MQTT broker on startup. The corresponding JSON payload(s), as outlined below, are published to the /config topic suffix.

From this metadata information, Kotori would be able to derive relevant information to make the "instant-on" experience more pleasant. For example, by using the full name of the sensor like "name": "EVB-02-BME280 Relative Humidity" and its "unit_of_measurement": "%".

Example:

MQTT topic homeassistant/sensor/evb-ea-ind-02/evb-02-bme280_relative_humidity/config
JSON payload:

{
  "device_class": "humidity",
  "unit_of_measurement": "%",
  "state_class": "measurement",
  "name": "EVB-02-BME280 Relative Humidity",
  "state_topic": "evb-ea-ind-02/sensor/evb-02-bme280_relative_humidity/state",
  "availability_topic": "evb-ea-ind-02/status",
  "unique_id": "ESPsensorevb-02-bme280_relative_humidity",
  "device": {
    "identifiers": "c45bbe8d092c",
    "name": "evb-ea-ind-02",
    "sw_version": "esphome v2021.10.3 Nov 20 2021, 20:46:50",
    "model": "esp32dev",
    "manufacturer": "espressif"
  }
}

With kind regards,
Andreas.


mosquitto_sub -h daq.example.org -t '#' -v
homeassistant/sensor/evb-ea-ind-02/mpu9150_dt/config {"unit_of_measurement":"°","name":"MPU9150_dT","state_topic":"evb-ea-ind-02/sensor/mpu9150_dt/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_dt","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_compass_x/config {"unit_of_measurement":"°","name":"MPU9150_Compass_X","state_topic":"evb-ea-ind-02/sensor/mpu9150_compass_x/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_compass_x","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_compass_y/config {"unit_of_measurement":"°","name":"MPU9150_Compass_Y","state_topic":"evb-ea-ind-02/sensor/mpu9150_compass_y/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_compass_y","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_compass_z/config {"unit_of_measurement":"°","name":"MPU9150_Compass_Z","state_topic":"evb-ea-ind-02/sensor/mpu9150_compass_z/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_compass_z","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_gyro_x/config {"unit_of_measurement":"°","name":"MPU9150_Gyro_X","state_topic":"evb-ea-ind-02/sensor/mpu9150_gyro_x/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_gyro_x","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_gyro_y/config {"unit_of_measurement":"°","name":"MPU9150_Gyro_Y","state_topic":"evb-ea-ind-02/sensor/mpu9150_gyro_y/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_gyro_y","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_gyro_z/config {"unit_of_measurement":"°","name":"MPU9150_Gyro_Z","state_topic":"evb-ea-ind-02/sensor/mpu9150_gyro_z/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_gyro_z","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_acceleration_x/config {"unit_of_measurement":"°","name":"MPU9150_Acceleration_X","state_topic":"evb-ea-ind-02/sensor/mpu9150_acceleration_x/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_acceleration_x","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_acceleration_y/config {"unit_of_measurement":"°","name":"MPU9150_Acceleration_Y","state_topic":"evb-ea-ind-02/sensor/mpu9150_acceleration_y/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_acceleration_y","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/mpu9150_acceleration_z/config {"unit_of_measurement":"°","name":"MPU9150_Acceleration_Z","state_topic":"evb-ea-ind-02/sensor/mpu9150_acceleration_z/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensormpu9150_acceleration_z","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/evb-02-bme280_temperature/config {"device_class":"temperature","unit_of_measurement":"°C","state_class":"measurement","name":"EVB-02-BME280 Temperature","state_topic":"evb-ea-ind-02/sensor/evb-02-bme280_temperature/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorevb-02-bme280_temperature","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/evb-02-bme280_pressure/config {"device_class":"pressure","unit_of_measurement":"hPa","state_class":"measurement","name":"EVB-02-BME280 Pressure","state_topic":"evb-ea-ind-02/sensor/evb-02-bme280_pressure/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorevb-02-bme280_pressure","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/evb-02-bme280_relative_humidity/config {"device_class":"humidity","unit_of_measurement":"%","state_class":"measurement","name":"EVB-02-BME280 Relative Humidity","state_topic":"evb-ea-ind-02/sensor/evb-02-bme280_relative_humidity/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorevb-02-bme280_relative_humidity","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/evb-02-altitude/config {"unit_of_measurement":"m","name":"EVB-02-Altitude","icon":"mdi:signal","state_topic":"evb-ea-ind-02/sensor/evb-02-altitude/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorevb-02-altitude","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/hx711_value/config {"unit_of_measurement":"kg","state_class":"measurement","name":"HX711 Value","icon":"mdi:scale","state_topic":"evb-ea-ind-02/sensor/hx711_value/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorhx711_value","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/evb-02-absolute_humidity/config {"unit_of_measurement":"g/m³","name":"EVB-02-Absolute Humidity","icon":"mdi:water","state_topic":"evb-ea-ind-02/sensor/evb-02-absolute_humidity/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorevb-02-absolute_humidity","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
homeassistant/sensor/evb-ea-ind-02/evb-02-dew_point/config {"unit_of_measurement":"°C","name":"EVB-02-Dew Point","icon":"mdi:thermometer-alert","state_topic":"evb-ea-ind-02/sensor/evb-02-dew_point/state","availability_topic":"evb-ea-ind-02/status","unique_id":"ESPsensorevb-02-dew_point","device":{"identifiers":"c45bbe8d092c","name":"evb-ea-ind-02","sw_version":"esphome v2021.10.3 Nov 20 2021, 20:46:50","model":"esp32dev","manufacturer":"espressif"}}
@amotl
Copy link
Member Author

amotl commented Dec 7, 2021

We just discovered that this style and mechanism of sensor announcements to the MQTT bus is actually called »MQTT discovery«, as defined by Home Assistant at [1]. On behalf of a quick research, we also discovered corresponding generic implementations for C++/Arduino [2], and Python [3].

[1] https://www.home-assistant.io/docs/mqtt/discovery/
[2] https://github.com/plapointe6/HAMqttDevice
[3] https://pypi.org/project/homeassistant-mqtt-binding/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant