Shelly 1 (mqtt) always unavailable after HA restart

I am sure I am missing something basic here. I have just moved my Shelly 1 to MQTT and have it working fully. However, every time I restart HA, the Shelly defaults to ‘unavailable’. If I go to the Shelly web interface and reset the device, it becomes available and works as expected.

My HA config:

switch:
  - platform: mqtt
    name: "Bedroom light"
    state_topic: "shellies/shelly1/relay/0"
    command_topic: "shellies/shelly1/relay/0/command"
    availability_topic: "shellies/shelly1/online"
    payload_on: "on"
    payload_off: "off"
    payload_available: "true"
    payload_not_available: "false"
    retain: true

In the Shelly MQTT config, I have ‘clean session’ and ‘retain’ checked, and max QOS set to 0 (default).

What am I missing?

i had the same isue you have to uncomment "availability_topic: “shellies/shelly1/online”

Use tasmota on shelly?

Commenting out the availability topic does indeed work. Not ideal - it would be nice to be able to see when the device is offline, but does solve the problem for now.

Tasmoto is an option (I have lots of sonoffs flashed already) but I actually quite like that the shelly device runs stock firmware with no hassle. Plus it is wired in the ceiling rose above the ceiling and would be a pain to flash (I don’t have neutral to my switches)…

Seems like retain is not working properly. Can you test what the broker sends you when you subscribe to the availability topic?

Have you checked Shelly settings ?
There is a note on the official docs about Will Topic value after upgrade.

Ok…I tried…same issue here… :frowning:

I solved following this…

3 Likes

You can set an automation that sends an empty MQTT message when HA becomes available. That way the shelly report its status back to HA.

Automation

- id: Update_Sonoff_Start
  alias: 'Update Sonoff at Start'
  trigger:
    - platform: homeassistant
      event: start
  action:
  - delay: 00:00:30
  - service: script.turn_on
    entity_id: script.update_sonoff

Script:

update_sonoff:
alias: Update Sonoff at Start
sequence:
  - service: mqtt.publish
    data:
      topic: "cmnd/family/power"
      payload: ""
  - service: mqtt.publish
    data:
      topic: "cmnd/sonoff7/power2"
      payload: ""
2 Likes

I’ll give that a try - thanks!

I have been doing this for a while, works for me.

I can confirm that the following combination of the two suggestions above works:

- id: '00014'
  alias: Shelly sync at HA start
  trigger:
  - platform: homeassistant
    event: start
  action:
  - delay: 00:00:20
  - service: mqtt.publish 
    data: 
      topic: shellies/command 
      payload: announce

Delay works without needing a script.

Thanks all!

5 Likes

Did you use the python script?

No - no script. Just MQTT and the automation above.

Hi @srk23

Where did you get these topics from? I have shelly 1pm what could mine be?

You can find your MQTT topics in the Shelly app, where you configure your MQTT server details etc.

Hi @srk23 all I have is the will topic which is shellies/shelly1pm-60971A/online

Any idea?

So your topics would be:

Availability: shellies/shelly1pm-60971A/relay/0
Command: shellies/shelly1pm-60971A/relay/0/command
Availability: shellies/shelly1pm-60971A/online

So I have those as my topics but I get the same issue as your OP. It says unavailable i have added the automation as well like you suggested a few posts up but no joy.

To be fair when I reboot HA it would work and if I done another reboot it would say unavailable

I think I know the problem

The automation needs to contain initial_state: 'on' so that everytime it HA restarts the automation runs automatically.