I have a few videos on my channel that show you how to connect NodeMCU based devices to openHab via MQTT. Check out either of these topics, specifically part 3 of the video series (which show MQTT):
The sensor one will probably be better suited for what you’re trying to do (i.e. send MQTT data from ESP8266 to OH).
I set up something similar to what you’re trying to do. I have a PIR sensor hooked up to my Kube, and every time motion is detected, the Kube sends a “1” to the “motion” MQTT topic. In openHab, I have a rule set up that fires on that motion event, and if it is night time, it sends a color/brightness command to a Hue lightbulb. This lights up my ensuite hallway light a dim red if motion is detected at night.