Door/ window notification over MQTT example

I am Looking for and example to get sensors from my NodeMCU published to my HA over MQTT then receive notification on my phone.
Background
I set up my local MQTT mosquito. And found an example to turn on off an LED on the node MCU using HA. and that work find. Now I am looking to receive data from the Node MCU. Multiple sensor to HA. So I can use it for my door and wind sensor. Thank you.

Check into this:

Thanks but this is a Blink LED project over MQTT from what i understand. I have similar project. I am looking more of a project to receive notification from NodeMCU GPIO to HA.

Yes, but in that link is the mqtt a component. You can use that to send payloads to HA.
That payload can contain you NodeMCU sensor values.
That is the way you can recieve data from the esp32 to you mqtt broker and thus HA.

Have a look at ESPEasy:
https://www.letscontrolit.com/wiki/index.php/ESPEasy

@Romkabouter I dont know hoe to modify the code for payload. I can turn on off a switch but i dont know how to change the code to receive from the Node MCU. that is the quesion

Ah ok, do a search on google:“nodemcu sensor mqtt”

I got several hits with example code, you must adjust this to your need obviously but it should be enough to get you started.

I don’t know if you use c++ ore arduino, but for both I saw code in the search results :slight_smile:

I use tasmota on w wemos d1 mini. so should be similar

tasmota setup
module generic
D3 Switch1
D6 Relay1

run switchmode1 1 from the console

config.yaml

binary_sensor:

  • platform: mqtt
    name: “Laundry Door”
    state_topic: “stat/laundry-door/POWER”
    payload_on: “ON”
    payload_off: “OFF”
    qos: 0
    device_class: opening
    retain: true

Thanks brother, it took me a while to figure out how to load Tasmota to NodeMCU using IDE without errors, I had some library issue, I haven’t play with it yet but this sounds a good start. Thank you for making me aware of tasmota.

I generally flash his sonoff.bin binary release using flashesp8266.exe

On earlier versions (before 5.11 maybe) the wifi is preconfig to ssid indebuurt1 and pass VnsqrtnrsddbrN I set a hotspot on my phone to connect to it and then change the above to my home wifi

I think flasher exe came from here https://github.com/BattloXX/ESPEasyFlasher

Hi friend I was able to set the sensor in Tasmota switching on /off. on D5 to Ground. but I cant get the door status to switch on/off in HA, i can see the icon but it says door close …Close I never set any topic or description for close I dont know what HA is getting close from.

this is the config file:
binary_sensor:
platform: mqtt
name: “Door”
state_topic: “stat/alarm/SENSOR”
payload_on: “ON”
payload_off: “OFF”
qos: 0
device_class: opening
retain: true

take a look at the console in tasmota interface while triggering the sensor. The topic should match the state topic

This below is from my console… see stat/laundry-door/POWER is same as my state topic above. I haven’t seen the word /SENSOR in mine

16:54:31 MQT: stat/laundry-door/RESULT = {“POWER”:“OFF”}
16:54:31 MQT: stat/laundry-door/POWER = OFF

You were right on the topic I had it wrong, I though that was it, but unfortunately after fixing the topic string it did not work. its not switching ON/OFF in Hassio. I don’t know if you can figure out what is wrong in the config codes, here it is with the Sonof consol

binary_sensor:
  platform: mqtt
  name: “living Room Window”
  state_topic: “cmnd/alarm/POWER”
  payload_on: “ON”
  payload_off: “OFF”
  qos: 0
  device_class: opening
  retain: true

04:56:10 MQT: cmnd/alarm/POWER = OFF
04:56:44 MQT: cmnd/alarm/POWER = ON

I was able to fine why it was not working, just for the record I was missing to indent 4 spaces not 2 after binary sensor:

I asked this question already somewhere else, how do I add 2 more door sensors?

I haven’t done it but I assume set another input to Switch2 and setting switchmode2 1 on the console and so on. Not sure how the additional switches would look on the MQTT side. It would be a mater of trial and error while looking at what pops up on the console log.

@tastycarp I was able to figure it out someone else sent me his Tasmota set up. What I find out was in order to have different topics like Power1 power 2 etc…you need to set a relay for each switch. Thanks.