The problem is when I push the switch (which will open it) it should read D2 as being LOW and set D7 LED to LOW. It’s not. The D7 LED remains HIGH regardless of the switch, and the publish method does not fire either.
I do notice that when I close the switch, the D7 LED dims just a bit -maybe just a power thing…
Ah, that could be the problem as I see in the logs that it fires off 4 “open” statuses before stopping and not responding. I need to adjust my code to only respond once if it detects the switch open, or once if closed.
Ideally, I’d like to just monitor the switch status and publis that event one time.
Yeah - without a pulldown your results will be unpredictable.
You should also debounce the input, or else you may see some spurious results (although the publish() in yoour example might take so long that the bouncing is done by the time loop() iterates.) Debouncing is good practice whenever set of physical contacts is invoved regardless.