Homeassistant Text Sensor on_value issue when booting

I have an Wemos D1 Mini running a Nextion display to control lights and a ceiling fan, which is working fine. I’ve been using this for quite a while,but have noticed some changes in behavior on bootup.

Fan and light (off the fan) on an iFan02 running Tasmota and MQTT. It’s been converted to the fan percentage speeds, so a HA template sensor is used to translate that to “off”, “high”, “medium”, or “low”.

Here’s a sample of the code for my question:

text_sensor:
  - platform: homeassistant
    name: "Fan Speed from HA"
    internal: true
    id: ha_fan_speed
    entity_id: sensor.office_ceiling_fan_speed
    on_value:
      then:
        - lambda: |-
            if(strcmp(x.c_str(),"off") == 0 ) {
              id(fan_speed) = 0;
              id(display_nextion).set_component_text("t0","Off");
            }
            if(strcmp(x.c_str(),"low") == 0) {
              id(fan_speed) = 1;
              id(display_nextion).set_component_text("t0","Low");
            }
            if(strcmp(x.c_str(),"medium") == 0) {
              id(fan_speed) = 2;
              id(display_nextion).set_component_text("t0","Med");
            }
            if(strcmp(x.c_str(),"high") == 0) {
              id(fan_speed) = 3;
              id(display_nextion).set_component_text("t0","Hi");
            }

If I change the fan speed in HA, it does reflect correctly on the Nextion display.

However, on bootup, it does not. Everything is blank. I have to change it to get it to sync up.

Previously, I’d boot the device, and within a few seconds (once HA connection is established), the Nextion would change to show the current status (e.g. fan on Medium or light on). I assume that the ‘on_value’ was triggered when the HA connection was established, but it doesn’t seem to be doing this anymore.

Any suggestions on how to “force” it, or a better way to handle this so that the states are reflected based on the status of the text sensors on boot (e.g. something else other than “on_value”)?

Thanks.

You answered your own question:

https://esphome.io/components/esphome.html#on-boot

Thanks. I’ve tried that (with -100 priority) and it doesn’t seem to update. I’m going to continue to troubleshoot, probably starting out with logging the values to see what they are.

This is a bit of an odd situation as I’m relying on reading a text sensor from home assistant (fan and light state) to update the Nextion display, especially on bootup. It’s not clear at what priority that’s available. I used the highest of -100 (“pretty much everything should be available”).

What’s odd is that the ‘on_value’ automation kicked in previously. On bootup, after a few seconds the panel would update to reflect the current status. At some point in ESPHome upgrades, it no longer does that. Obviously, everything works if I change the state of the light or fan in HA… the panel HMI display updates as it should.

I’ll report back on my findings.