MQTT Status unreliable

Hi,
I have a few Shelly devices in my house and they mostly work fine. However every so often Home Assistant is not able to control them and also reports the incorrect status on the dashboard. For example Home Assistant shows the light as being on when it is off, toggling the switch in Home Assistant makes it go to off but them back to on without the light changing state (to on). When this occurs if I control the light via either HomeKit or Alexa (both use Home Assistant integrations) it works perfectly but Home Assistant does not correct itself until I restart the MQTT add-on.

Do other people have this problem, I am hoping it is just be doing something wrong.

My config for one of the lights is below, all the others are exactly the same.

- platform: mqtt
    name: "Back Garden Lights"
    command_topic: "shellies/shellyswitch25-98F4ABF2C15D/relay/1/command"
    state_topic: "shellies/shellyswitch25-98F4ABF2C15D/relay/1"
    qos: 2
    optimistic: false
    payload_on: "on"
    payload_off: "off"

I am running the below versions for Home Assistant:-

HassOS 4.15
Home Assistant 0.117.1

Thanks

Same / similar issue.
6 Shellys on same network with Home Assistant. All working perfectly 90% of the time, just occasionally but often enough one or more wont be communicating via mqtt.

Which results in a light or switch not being switched on (either detached light switch via shelly or automation / motion sensor).

The shelly http://ip/status page shows the shelly as being connected via mqtt.

Fixed by Either restarting the mqtt Mosquitto broker (or whole HA / OS) or restarting the single shelly (if only one effected at the time) or even just changing the mqtt IP on the shelly and changing it back again.

version 0.117.1
host_os HassOS 4.15
os_version 5.4.72
Mosquitto broker 5.1

All shelly’s use the same mqtt username/password.

I’ve yet to find a way to monitor for these disconnections / stuck communication sessions.

example

 - platform: mqtt 
    name: "Front Room Light" 
    state_topic: "shellies/shelly1pm-76AE06/relay/0" 
    command_topic: "shellies/shelly1pm-76AE06/relay/0/command" 
    payload_on: "on"
    payload_off: "off"
    retain: false

is it started after installing HA 0.117.x ?

For me it has been for the last few months not a new thing unfortunately.

For as long as I can remember, maybe 6months.

Normally it’s a single device with an issue, but often turns into another at the same time.

Most of mine are wired behind light switches and use Shelly’s detached switch mode.
So the physical switch only does mqtt commands and no longer power (hue bulbs).

This means that the normal looking light switch is then useless.
Some are detached and do a node red automation trigger instead (no hue bulb).

Can you guys check logs on your wifi APs/routers?

You should add to shelly config a line for checking its online state

  - platform: mqtt
    name: "Dining room 1"
    command_topic: "shellies/shelly1-dining1/relay/0/command"
    state_topic: "shellies/shelly1-dining1/relay/0"
    availability_topic: "shellies/shelly1-dining1/online"
    qos: 1
    retain: false
    payload_on: "on"
    payload_off: "off"
    payload_available: "true"
    payload_not_available: "false"
    optimistic: falsfe

It will give you a clue if device becomes unavailable (you can set timeout too)

Hi,
I have added this to one as a test, I did have to reboot the Shelly though for it to become available, is there a normal process that does that?

I have not checked my router/wireless as when it does not work from Home Assistant it does still work from HomeKit and Alexa both of which go via Home Assistant.

Thanks

you don’t need to reboot shelly. Rather reload mqtt config in ha. Then send announce to this device (or to all devices using shellies topic).

Thanks, I have added this automation to my Automations.yaml file and it seems to keep them online following a server restart.

- id: '1582566286510'
  alias: Shelly MQTT Restart Fix
  description: ''
  trigger:
  - event: start
    platform: homeassistant
  condition: []
  action:
  - data:
      payload: announce
      topic: shellies/command
    service: mqtt.publish

Hi,
One of my switches did the same thing yesterday. It was not greyed out on the dashboard so HA thought it was still online. However the light was showing as off but was in fact on. Restarting the MQTT integration solved the problem. Also controlling the light from my HomeKit (goes via HA) worked as expected but the status in HA did not change.