Shelly Dimmer 2 + MQTT: state unavailable after hass restart until subsequent restart of shelly

So I have configured a Shelly2 Dimmer to use MQTT:

binary_sensor:
    - platform: mqtt
      name: "Shelly Dimmer Kitchen ext. Switch 1 (MQTT)"
      state_topic: "shellies/shellydimmer2/outdoor/kitchen/input/0"
      payload_on: "1"
      payload_off: "0"
      availability: 
        payload_available: 'true'
        payload_not_available: 'false'
        topic: 'shellies/shellydimmer2/outdoor/kitchen/online'
      qos: 1

and the configuration of the Shelly device is:

Enable action execution via MQTT
username = “” # not set yet
password = “” # not set
Server: <MQTT_broker_IP>:1833
Use custom MQTT prefix: shellydimmer2/outdoor/kitchen
Min reconnect timeout: 2
Max reconnect timeout: 60
KeepAlive: 10
Clean Session
Retain
Max QoS: 0

My problem is, when I restart home assistant, the entities are shown with state “unavailable” in Developer Tools. And they stay that way until I restart the shelly 2 dimmer via its webinterface.

Is anyone else aware of this issue? Are my settings somehow bogus?

Thanks in advance!

I’m having the same problem with all of my shellies. What is your home assistant version? I don’t think I used to have this problem. Since I upgraded to 0.115 this started.

There’s a new Shelly integration now, have you tried that ?

No, because I tried coAP in the past, and MQTT was a lot faster. So I would prefer MQTT. Did you try it?

Yes all working great here, only have 2 dimmers though, the rest I’ve flashed with esphome

Looks like this topic is in the wrong place :slight_smile:

I’m currently running on 0.114 and this is the version were I got my first Shelly Dimmer2. My other Shelly’s are running ESPHome, but this AFAIK not yet possible for the Dimmer2.

I found two workarounds for this. One is “rather elegant” but only works for 2/3 of my Shelly Dimmer2, the other one is a little crude :slight_smile: …but works

The basic idea is to use an automation that triggers when Home Assistant has started. The elegant way is to publish a command to the Shellys to have them update their status.

 # automation:
  #   id: a6a6d721-b57f-405e-8287-db9de7f792e6
  #   alias: revive MQTT communication with Shelly dimmers on HASS startup
  #   trigger:
  #     platform: homeassistant
  #     event: start
  #   action:
  #     - service: mqtt.publish
  #       data:
  #         topic: 'shellies/shellydimmer2/outdoor/living_room/command'
  #         payload: update
  #     - service: mqtt.publish
  #       data:
  #         topic: 'shellies/shellydimmer2/outdoor/kitchen/command'
  #         payload: update
  #     - service: mqtt.publish
  #       data:
  #         topic: 'shellies/shellydimmer2/outdoor/garage/command'
  #         payload: update

(I have this commented out in my .yaml but you’ll get the idea)

The crude one works since the values are also updated in Home Assistant when you set a value via the REST API. So I change a value and change it back again:

automation:
    id: ceeb326a-b7f8-4780-b61f-35b28bf4505c
    alias: revive MQTT communication with Shelly dimmers on HASS startup
    trigger:
      platform: homeassistant
      event: start
    action:
      - service: switch.toggle
        entity_id: switch.helper_revive_shelly_outdoor_kitchen
      - delay: 00:00:02
      - service: switch.toggle
        entity_id: switch.helper_revive_shelly_outdoor_kitchen

      - service: switch.toggle
        entity_id: switch.helper_revive_shelly_outdoor_garage
      - delay: 00:00:02
      - service: switch.toggle
        entity_id: switch.helper_revive_shelly_outdoor_garage

      - service: switch.toggle
        entity_id: switch.helper_revive_shelly_outdoor_livingroom
      - delay: 00:00:02
      - service: switch.toggle
        entity_id: switch.helper_revive_shelly_outdoor_livingroom


        




  switch:
    platform: command_line
    switches:
      helper_revive_shelly_outdoor_livingroom:
        command_on: "curl http://192.168.c.d/settings/?mqtt_update_period=20"
        command_off: "curl http://192.168.c.d/settings/?mqtt_update_period=10" 

      helper_revive_shelly_outdoor_kitchen:
        command_on: "curl http://192.168.a.b/settings/?mqtt_update_period=20"
        command_off: "curl http://192.168.a.b/settings/?mqtt_update_period=10"

      helper_revive_shelly_outdoor_garage:
        command_on: "curl http://192.168.x.y/settings/?mqtt_update_period=20"
        command_off: "curl http://192.168.x.y/settings/?mqtt_update_period=10"  

hope this helps :slight_smile:

I know :confused:

At least the Tags “Mobile Apps” and “Home Assistant Companion for Android” are wrong. I was about to ask a question about that, but it turned out, the Android tablet itself was the problem. I didn’t realize this when I posted this question.

How can I rectify this? :thinking:

I put it under configuration