Question about ESPHome: Post MQTT Data Every 5 Minutes

Hi everyone,

I’ve integrated several Xiaomi MiFlora sensors via ESPHome and am sending the data via MQTT to my server. The configuration works fine so far, but I want to make sure the sensor values are only posted every 5 minutes and not immediately as soon as they’re available. Below is my current configuration:

sensor:
  - platform: xiaomi_hhccjcy01
    mac_address: "5C:85:7E:12:ED:CA"
    temperature:
      name: "MiFlora1 Temperature"
      id: miflora1_temperature
    moisture:
      name: "MiFlora1 Moisture"
      id: miflora1_moisture
    illuminance:
      name: "MiFlora1 Illuminance"
      id: miflora1_illuminance
    conductivity:
      name: "MiFlora1 Soil Conductivity"
      id: miflora1_conductivity
    battery_level:
      name: "MiFlora1 Battery Level"
      id: miflora1_battery
    update_interval: 5min  # Update interval set here

  - platform: xiaomi_hhccjcy01
    mac_address: "5C:85:7E:12:ED:AB"
    temperature:
      name: "MiFlora2 Temperature"
      id: miflora2_temperature
    moisture:
      name: "MiFlora2 Moisture"
      id: miflora2_moisture
    illuminance:
      name: "MiFlora2 Illuminance"
      id: miflora2_illuminance
    conductivity:
      name: "MiFlora2 Soil Conductivity"
      id: miflora2_conductivity
    battery_level:
      name: "MiFlora2 Battery Level"
      id: miflora2_battery
    update_interval: 5min

interval:
  - interval: 5min
    then:
      - mqtt.publish:
          topic: "florasensordevice/sensor1/temperature"
          payload: !lambda |-
            return to_string(id(miflora1_temperature).state);
      - mqtt.publish:
          topic: "florasensordevice/sensor1/moisture"
          payload: !lambda |-
            return to_string(id(miflora1_moisture).state);
      ...

My Goal:

I want to prevent the sensor values from being sent immediately after startup or when changes happen, and instead, have them only sent every 5 minutes.

Thanks in advance for any advice!

So what’s wrong with your code? It only does what you asked.
You can use startup_delay on interval if it posts immediately at startup.

1 Like