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.