MQTT Device does not notice when you switch it on manually

Hello community.
Beginner needs help again: MQTT Device does not notice when you switch it on manually.
If I switch on my mqtt socket manually, the sensor/entity is correctly set to ON shortly afterwards, but the device itself (switch) does not notice this. In the dashboard, my switch remains switched off, but the state of the entity changes.

Does it make sense to create a rule that switches the switch on or off depending on the state of the sensor? Or is something configured incorrectly.

My Config:

- switch:
      name: "MQTT sonoff-s20-1"
      command_topic: "sonoff-s20-1/cmnd/POWER"
      icon: "mdi:power-socket-eu"
      unique_id: "mqtt_switch_s201"

  - sensor:
      name: "Sonoff-s20-1 State"
      state_topic: "sonoff-s20-1/tele/STATE"
      value_template: "{{ value_json.POWER }}"
      unique_id: "mqtt_switch_s201_state"
      json_attributes_topic: "sonoff-s20-1/tele/STATE"
      json_attributes_template: '{{ value_json | tojson }}'

Everything works so far.
I can also switch the switch via the dashboard and see the correct status via the sensor.
Only the dashboard with the switch cannot be updated when the switch is operated manually.

Any suggestions?
Thx in advance.

Your switch only has a command topic and lacks a state topic

Thank you.
the state is hidden with many other values in “sonoff-s20-1/tele/STATE” with the Key POWER:

{
  "Time": "2025-07-16T18:57:54",
  "Uptime": "0T21:45:28",
  "Heap": 15,
  "SleepMode": "Dynamic",
  "Sleep": 50,
  "LoadAvg": 19,
  "POWER": "ON",
  "Wifi": {
    "AP": 1,
    "SSId": "xxxxxx",
    "BSSId": "xx:xx:xx:xx:xx:xx",
    "Channel": x,
    "RSSI": x,
    "LinkCount": 1,
    "Downtime": "0T00:00:07"
  }
}

It’s possible to query it with the switch?
A simple state topic is not available.

Yes, you can do that with the value_template option along with state_topic. Add this to your switch config:

state_topic: 'sonoff-s20-1/tele/STATE'
value_template: "{{ value_json['POWER'] }}"
1 Like

Thank you. That’s it.
Unfortunately a little delayed, but it arrives correctly in the dashboard

Assuming this is a Tasmota device (which it appears to be but must be old since the topic format is reversed), you’ll want to send SetOption59 1 in the tasmota console to enable sending a payload to the tele topic immediately with every power change.

1 Like

sensational. i’m thrilled.
great forum here.
Many, many thanks.

1 Like