ESPHome Sensors in predefined Order possible?

Hi there. I have some ESP Temperature and Humidity Sensors. After initial Problems I now face a Problem I dont get through with.
The Sensors Measure Temperature and Humidity and after this I have a Template Sensor Calculating the Dewpoint.
Every so often ESPHome trys to calculate the Dewpoint before the other Values got in. Then it sends NaN as Value and Homeassistant prints “Non numeric Value”
How can I get past this?
Here the Logoutput when this happens:

[13:12:31][D][sensor:093]: 'WZ_Dew': Sending state -nan °C with 1 decimals of accuracy
[13:12:37][D][dht:048]: Got Temperature=25.6°C Humidity=64.8%
[13:12:37][D][sensor:093]: 'WZ_Temp': Sending state 25.60000 °C with 1 decimals of accuracy
[13:12:37][D][sensor:093]: 'WZ_Humi': Sending state 64.80000 % with 0 decimals of accuracy``
type or paste code here

and my Code:

esphome:

  name: air-wz

  friendly_name: Luftqualitaet Wohnzimmer

esp8266:

  board: esp01_1m

# Enable logging

logger:

# Enable Home Assistant API

api:

  encryption:

    key: "/+WycRcYqUeo5A5aUZqYgLqB7If6ogRcR32EIEmO38k="

ota:

  password: "0ab4e2c9af038305b048e091f4accea9"

wifi:

  ssid: !secret wifi_ssid

  password: !secret wifi_password

  fast_connect: true

  manual_ip:

    static_ip: 192.168.128.12

    gateway: 192.168.178.1

    subnet: 255.255.128.0

    dns1: 192.168.178.1

  # Enable fallback hotspot (captive portal) in case wifi connection fails

  ap:

    ssid: "Air-K Fallback Hotspot"

    password: "8acVOYkjEfz2"

captive_portal:

sensor:

  - platform: dht

    pin: GPIO2

    model: AM2302

    temperature:

      name: "WZ_Temp"

      id: WZ_Temp

      unit_of_measurement: "°C"

    humidity:

      name: "WZ_Humi"

      id: WZ_Humi

      unit_of_measurement: "%"

     

  - platform: template

    name: "WZ_Dew"

    lambda: |-

      return (243.5*(log(id(WZ_Humi).state/100)+((17.67*id(WZ_Temp).state)/

      (243.5+id(WZ_Temp).state)))/(17.67-log(id(WZ_Humi).state/100)-

      ((17.67*id(WZ_Temp).state)/(243.5+id(WZ_Temp).state))));

    unit_of_measurement: °C

    icon: 'mdi:thermometer-alert'

deep_sleep:

  run_duration: 60s

  sleep_duration: 300s

Try this:

  1. Remove the lambda from the template sensor
  2. On the other sensor put a sensor.template.publish: with the lambda
sensor:

  - platform: dht
    pin: GPIO2
    model: AM2302
    temperature:
      name: "WZ_Temp"
      id: WZ_Temp
      unit_of_measurement: "°C"
    humidity:
      name: "WZ_Humi"
      id: WZ_Humi
      unit_of_measurement: "%"
      on_value:
        - sensor.template.publish:
            id: template_sens
            state: !lambda |-
              return (243.5*(log(id(WZ_Humi).state/100)+((17.67*id(WZ_Temp).state)/
              (243.5+id(WZ_Temp).state)))/(17.67-log(id(WZ_Humi).state/100)-
              ((17.67*id(WZ_Temp).state)/(243.5+id(WZ_Temp).state))));

  - platform: template
    name: "WZ_Dew"
    id: wd_dew
    unit_of_measurement: °C
    icon: 'mdi:thermometer-alert'

Oh and welcome to the HA community :smiley: