I have been stressing all day over a lambda construct that was making if-then decisions. Basically, press a button to increment to the next switch in sequence. (The actual project is irrelevant).
The button press was generated with some precision and the lambda code should have worked. On an oscilloscope, the button press was a reliable 50ms measured at the GPIO pin.
Then I was tipped off to the ESP_LOGD macro:
- lambda: |-
ESP_LOGD("custom", "Press duration: %d", id(press_duration));
if (id(press_duration) < 100) {
id(sequence_switch).turn_on();
} else if (id(press_duration) >= 400) {
id(scene1).turn_off();
id(scene2).turn_off();
id(scene3).turn_off();
id(scene4).turn_off();
id(current_scene) = 0;
}
The debug output was:
[22:21:45][D][custom:157]: Press duration: 170
[22:21:47][D][custom:157]: Press duration: 190
[22:21:49][D][custom:157]: Press duration: 180
Apparently, I was not accounting for the latency delay in processing the GPIO input. But this debug tool showed me immediately what my problem was.
Hope this helps someone.