Creating devices in Home Assistant from MQTT templates

Creating devices in Home Assistant from MQTT templates

In addition to defining MQTT-based sensors to make them entities in Home Assistant, you can also group a bunch of sensors as a device.

acurite.yaml
mqtt:
  binary_sensor:
  - state_topic: rtl_433/Acurite-986/5197/battery_ok
    json_attributes_topic: rtl_433/Acurite-986/5197
    device_class: battery
    name: "Chest freezer temperature battery state"
    unique_id: chest_freezer_temperature_battery_state
    payload_on: '0'
    payload_off: '1'
    device:
      identifiers: 986-5197
      manufacturer: AcuRite
      name: Chest freezer temperature
      model: 986
      suggested_area: Green bedroom
  sensor:
  - state_topic: rtl_433/Acurite-986/5197/temperature_C
    json_attributes_topic: rtl_433/Acurite-986/5197
    device_class: temperature
    name: "Chest freezer temperature"
    unique_id: chest_freezer_temperature
    unit_of_measurement: "°C"
    value_template: '{{ value | round(0) }}'
    state_class: "measurement"
    device:
      identifiers: 986-5197
      manufacturer: AcuRite
      name: Chest freezer temperature
      model: 986
      suggested_area: Green bedroom

Once defined in YAML, reload the configuration and you'll notice your entities are now groups as a device. It even pre-populates your area if the suggested_area matches one that you already have.

MQTT sensors as devices in Home Assistant