MQTT Publish Messages

Hi There,

Need the community assistant before I pull out all my hair

I’m trying to put together a very simple wireless window sensor. I’ve been following the youtube post by “the hook up” called " $5 DIY Wireless MQTT Smart Home Window Sensors" the project seem very simple and straight forward. How wrong I was, this is my 7th day on the project and I only now have the ESP-01 sending MQTT messages to Home Assistant. It is meant to show “open”, “close” or close and battery voltage but instead I see “{“State”:“open”, “voltage”:“3669”}” as the output when the chip is triggered.

image

Sensor.yaml code

- platform: mqtt
  name: "KitchenWindow"
  state_topic: "kitchenwindow"

Currently running HA 0.93.2

code - https://github.com/thehookup/MQTT_Window_Sensors

sketches -
Window_Static_CONFIGURE.ino
windows.yaml

I know I’m missing something, please assist

Thanks, Nick

Hi,

I’m more of a copy past guy and have no idea how to code BUT looking at what the sensor returns, that’s JSON so you would need a template to split it out, something like the below should give you open or closed.

 - platform: mqtt
   name: "KitchenWindow"
   state_topic: "kitchenwindow"
   state_value_template: "{{ value_json.State }}"
   ##value_template: "{{ value_json.State }}"  <--try this if the above line doesn't work.

Good luck

Simon

Thanks Simon the “value_template” did the trick

image

Thanks for your help

Nick