Mqtt switch receive state

Hey there,
I am just getting started with Home Assistant and tried out things a little bit.
I am Using Mosquitto as my mqtt broker
Added a switch to home assistant and my ESP8266 is working flawlessly.

But now I just dont know what to publish from my ESP to Home assistant that the status of the switch changes on the interface aswell.

Would appreciate any help or a link if that question has been answered already (Didnt find anything using the search)

Greetings

does your esp publish a state message to the broker?

what is the firmware you’re using on it?

- platform: mqtt
name: "EspTest"
command_topic: "cmnd/Test/power"
stat_topic: "stat/Test/POWER"
qos: 0
payload_on: "1"
payload_off: "0"
retain: true
state_on: "1"
state_off: "0"

Got one Esp set up to publish and another one subscribed to that topic
But neihter if i publish to the command_topic, nor when i publish to the state_topic the switch status changes

The Esp subscribed to the topic is indeed showing me, that the messages are published

I am using the PubSubClient library to publish and subscribe to topics on my esps

Take a look at the docs.

For the state:

    state_topic: "home/bedroom/switch1"
    state_on: "ON"
    state_off: "OFF"

I did, but it didnt work with “On” and “OFF” either
Anyways I should be able to choose the value for state_on shouldnt I ?

 state_on: "1" 

shouldnt be a problem aslong as I publish “1” to the topic

Or am I wrong ?

Just an example.
If you configure your switch with state_on: "1" then the ESP should publish "1" to the state_topic when it is on.

It shouldn’t matter what you actually publish to the state topic as long as the topic and payload published are the exactly the same as what HA is expecting. They are case sensitive.

on/off, ON/OFF, On/Off, 1/0 should all work as long as you put those in the config in HA

For clarification

If I set

state_off: "0"
stat_topic: "stat/Test/POWER"

In my config
All I had to do is publish “0” to “stat/Test/POWER” to turn the status of the switch off

I dont have to publish anything else
And I can do this whenver I want to do and not just at the beginning right ?

Just found out that the issue was a typo
state_topic

Now everything is working fine
Sorry for the trouble
Thanks anyway