mqtt:
  broker: !secret mqtt_broker
  username: esphome
  password: !secret mqtt_password
  id: mqtt_homeassistant
  # We have some common entities across multiple devices,
  # e.g. Reset button, and component+object_id doesn't cut it
  # to provide uniqueness.
  discovery_unique_id_generator: mac
  # No point in publishing NaN as it will not be accepted by
  # HA and only generate error messages.
  publish_nan_as_none: true
  on_connect:
    - sensor.duty_time.start: mqtt_connection_uptime
  on_disconnect:
    - sensor.duty_time.stop: mqtt_connection_uptime
    - sensor.duty_time.reset: mqtt_connection_uptime

sensor:
  - platform: duty_time
    id: mqtt_connection_uptime
    name: "ESP chip MQTT connection uptime"
    entity_category: diagnostic
    accuracy_decimals: 0
