Zigbee2mqtt switch - HA doesn't read topics if generated from switch

Hi all,
I have a problem with mqtt settings in home assistant for a switch zigbee…

My situation

  • mosquitto running ok
  • home assistant core
  • zigbee2mqtt installed and working
  • other sensors zigbee (aqara and other brands) works perfectly
  • I’m not english, so bear with me if my english is bad :slight_smile:

I configured the switch in zigbee2mqtt, name “riscaldamento”. It works perfectly as soon as I control it from home assistant. HA send the on command, it turns on and also in graphic it appears on. When I switch off, from HA, it goes off both for real and in graphic.
The problem is when I switch it through the button on the device. It change state, it send the topic to zigbee2mqtt so I can see the topic in mosquitto, but HA ignores it… It doesn’t update the status in HA, so in graphic it remains unchanged and not synched with the actual status. Then it re-aligns with the physycal state when I activate it from HA.

It seems that HA read the staut stopic only when it expect to receive it, like a feedback. So after HA sent a command to the switch, it reads the topic and update the status, but if HA did not send the command, it ignores the topic sent by the switch

Example:
switch is off → switch on physycally → switch is on, but is off in HA → switch on in HA → switch does nothing physycally and HA update the status to on

Topic mqtt visible in mosquitto log:

zigbee2mqtt/riscaldamento {"device":"dateCode":"20230505","friendlyName":"riscaldamento","ieeeAddr":"0x84ba20fffee23ef0","manufacturerID":4742,"manufacturerName":"SONOFF","model":"ZBMINIL2","networkAddress":18608,"powerSource":"Mains (single phase)","softwareBuildID":"1.0.14","type":"EndDevice","zclVersion":8},"linkquality":168,"power_on_behavior":"previous","state":"OFF","update":{"installed_version":4110,"latest_version":4110,"state":"idle"}}

Mqtt switch configuration loaded in HA yaml (I have other sensors, I left only the meaningfull part of code lines):

mqtt:
  switch:
    - name: "riscaldamento"
      state_topic: "zigbee2mqtt/riscaldamento/state"
      command_topic: "zigbee2mqtt/riscaldamento/set"
      qos: 1
      value_template: "{% if value == 'on' %} on {% else %} off {% endif %}" 
      payload_on: "on"
      payload_off: "off"
      payload_available: "true"
      payload_not_available: "false"
      optimistic: true
      retain: true

Can you please help me to understand why it is not working as expected?
Thank you!