Core: MQTT Light not read availability_topic on boot of HA

Created on 13 Feb 2019  路  17Comments  路  Source: home-assistant/core

Home Assistant release with the issue:
0.87.1

Last working Home Assistant release (if known):
0.86.x

Operating environment (Hass.io/Docker/Windows/etc.):
Hass.io on RPi 3B

Component/platform:
MQTT Light

Description of problem:
availability_topic message not read on boot of HA, the mqtt light device show as unavaiable.
If I manually reboot these devices or re-send the availability message via MQTT everything works fine.

It is the same problem described in this old post: https://github.com/home-assistant/home-assistant/issues/12485

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

- platform: mqtt
  name: "Terrazzo Salotto"
  state_topic: "shellies/shelly1-55EED9/relay/0"
  command_topic: "shellies/shelly1-55EED9/relay/0/command"
  availability_topic: "shellies/shelly1-55EED9/online"
  qos: 0
  payload_on: "on"
  payload_off: "off"
  payload_available: "true"
  payload_not_available: "false"
  optimistic: false
  retain: false

Traceback (if applicable):


Additional information:

Most helpful comment

I solved with this automation:

- alias: 'Shellies Announce' trigger: - platform: homeassistant event: start action: service: mqtt.publish data: topic: shellies/command payload: announce

at the start of home assistant shelly devices publish an announcement, where the availability message is also present.

Thank you for support

All 17 comments

I can't reproduce your issue.

Can you confirm if you're using the embedded MQTT broker or an external one?

Also, please triple check the availability topic is retained:
mosquitto_sub -h <your_mqtt_host_here> -v -t shellies/shelly1-55EED9/online

i'm using Mosquitto Broker Addon.
mosquitto_sub returns the error: Connection Refused: not authorised.

availability topic works correctly during use, only at start of HA is not read.
If i reboot device, or send mqtt publish with payload true, the entity mqtt light come back available.

Same problem described in post https://github.com/home-assistant/home-assistant/issues/12485.
The problem had been solved, but with 0.87 it's back ..

sorry for my english
thanks

If you're using the addon, please report an issue here instead: https://github.com/hassio-addons/addon-mqtt/issues

There seems to be something wrong with the plugin, https://github.com/hassio-addons/addon-mqtt/issues/25, so I'm closing this for now.

Same problem described in post #12485.

The problem in #12485 was that Hass didn't handle retained messages correctly.
In this case, you should make sure there is a retained message to begin with.

mosquitto_sub returns the error: Connection Refused: not authorised.

Then do like this:
mosquitto_sub -h -u -P -v -t shellies/shelly1-55EED9/online

ok, but before 0.87 no problems at startup .. however I opened an issue on the addon page

there is a misunderstanding, I am using the official addon "Mosquitto Broker', not addon from community.
Please support and re-open thread

OK.
Can you please make sure the availability topic is in fact retained:
mosquitto_sub -h <your_mqtt_host_here> -u <mqtt_username> -P <mqtt_password> -v -t shellies/shelly1-55EED9/online

I'm trying
mosquitto_sub -h 192.168.0.104 -u "mqtt_user" -P xxxxxx -v -t shellies/shelly1-55EED9/online

Even with the user & password the command returns me: Connection Refused: not authorised.

In the broker's log I find:
[WARN] Not found mqtt_user on local database
1550157643: Socket error on client , disconnecting.

"mqtt_user" is the configured user in Mosquitto broker

How can your Shelly and HA connect to the server if it doesn't work from command line? Maybe double check username and password. Any strange characters in the password being mangled by the shell?

Yes! I had the character "$" in the password.
now it connects to the broker, but I have to change the password in the shelly configuration.

now I'm connected remotely and I can't do it, tonight I edit and update the thread.
Thanks

during startup of HA mosquitto_sub does not send anything on video, if i reboot device, or save configuration, i can see:

shellies/shelly1-55EED9/online false
shellies/shelly1-55EED9/online true
shellies/shelly1-55EED9/online false
shellies/shelly1-55EED9/online true

Maybe the problem is that at startup does not detect the state?

When you start mosquitto_sub, do you immediately see this line:
shellies/shelly1-55EED9/online true, or does it only appear after you restart your shelly device?

only appear after restart of shelly, or when save mqtt configuration of shelly.

@maxalbani OK, it means the server doesn't send a retained message when you connect.
Normal MQTT messages will only be sent to clients who are connected when they are sent. Retained messages are stored on the MQTT broker and will be resent when a client subscribes to that topic.

Maybe you're also hit by this bug: https://github.com/home-assistant/home-assistant/issues/21040#issuecomment-463793892 which breaks retained messages.

Or shellies don't publish their online message retained, can you please check that in their support forum?

I tried to do execute workaround described in comment, but it still does not work

I solved with this automation:

- alias: 'Shellies Announce' trigger: - platform: homeassistant event: start action: service: mqtt.publish data: topic: shellies/command payload: announce

at the start of home assistant shelly devices publish an announcement, where the availability message is also present.

Thank you for support

@maxalbani Thanks for reporting back, I'll close this issue since your problem is solved.

Was this page helpful?
0 / 5 - 0 ratings