I've been fighting for two weeks trying to have the PIR sensor trigger a mqtt message.
I find that the PIR sensor output gets false triggers whenever the ESP radio is on.
I've finally gotten the crazy logic to work to turn the radio off when waiting for the PIR signal, then turning the radio on, publishing the mqtt message, and turning the radio back off.
Even then running the PIR on the same 3.3v supply as the ESP was just never reliable - more false triggers.
I finally powered the PIR separately and cured that issue.
Then I found that every 60 seconds I was getting another PIR trigger - turns out the ESP wdt was causing that.
Now after thinking I was finally successful I'm finding that after about 5 minutes or so of inactivity, when I got to reconnect radio and publish mqtt the radio connects to my AP but I no longer get my mqtt connection.
I tried raising the mqtt keep alive duration but that hasn't helped so far.
Everything works as long as I have PIR activity every < 5 minutes - but any pause in PIR over 5 minutes I no longer get mqtt connection...
I was going to just try to make the ESP reset if I get AP connection but no mqtt connection within 15 seconds - after a reset the whole thing seems to work... but as of late last night I couldn't get my "reset on no response" code to work.
Very frustrating.
This morning I was going to try the reset code again when I saw the announcement of the Arduino IDE ESP port and the first example is a mqtt publisher.
Once I get that to compile(a whole other issue ) I'm going to see if it works publishing every 5 or 10 minutes to see if I have the same problem.
Anyway - let me know if you have gotten your setup to work reliably - if so I'd love to see how you did it.