Hass.io 0.86.2 automations not publishing to mosquitto

For some reason with the latest release of hass.io automations will not talk to the mosquitto addon

My automation

- id: '1548440909572'
  alias: Temperature to Sign
  trigger:
  - hours: ''
    minutes: '/1'
    platform: time_pattern
  action:
    service: mqtt.publish
    data_template:
      topic: 'cmnd/sign/SerialSend'
      payload: 'Driveway Temp:{{ states("sensor.blink_drive_gate_temperature") }} Date:{{ states("sensor.date") }} Time:{{ states("sensor.time") }} Internet Ping: {{ states.binary_sensor.ping_binary_sensor.attributes.round_trip_time_avg }}'

log from the mosquitto server

1548448287: Socket error on client <unknown>, disconnecting.
1548448302: New connection from 192.168.. on port 1883.
1548448302: Socket error on client <unknown>, disconnecting.
1548448317: New connection from 192.168.. on port 1883.
1548448317: Socket error on client <unknown>, disconnecting.
1548448332: New connection from 192.168.. on port 1883.
1548448332: Socket error on client <unknown>, disconnecting.
1548448347: New connection from 192.168... on port 1883.
1548448347: Socket error on client <unknown>, disconnecting.
1548448362: New connection from 192.168... on port 1883.
1548448362: Socket error on client <unknown>, disconnecting.

When I publish from the services page the message is sent to the clients. Mosquitto and Hass.io are on the same pi. Its like the two are not authenticating anymore.

Have you tried restarting the addon?

I have tried restarting the addon. Since I can manually publish I am thinking the issue is the time_pattern trigger in the automation that is the issue.

Does the time pattern_trigger look correct?

Actually no I am back to an issue with home assistant not passing the correct credentials to mqtt for automations. I am going to fully power down and back up and see if that fixes anything.

I have 0.86.1 running in a docker container on my test system. When fed abbreviated versions of all the config files from my production system (abbreviated: homekit and a few entities relying on custom components have been commented out), it starts up just fine and renders the new Lovelace UI (automatic version; no ui-lovelace.yaml is present).

All my lights and sensors are based on MQTT components. The UI shows the correct status of each light and sensor (suggesting it succeeded to login to my existing MQTT Broker) but doesn’t allow me control the lights.

The log reports the following recurring message (repeated every ~3 seconds):

2019-01-25 21:53:40 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server,
2019-01-25 21:53:43 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server,
2019-01-25 21:53:46 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server,
2019-01-25 21:53:49 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server,
2019-01-25 21:53:52 INFO (Thread-2) [homeassistant.components.mqtt] Successfully reconnected to the MQTT server

The message Successfully reconnected to the MQTT server suggests its connection to the MQTT Broker is cycling (connect/disconnect). That’s eerily similar to what @gfetters is experiencing.

I haven’t finished exploring this problem (still need to look at the MQTT Broker’s log) so I’m not quite ready to say that this is a bug or just something improperly configured in my system. I’m jumping from 0.80 to 0.86 so it’s possible my config files are lacking something needed for MQTT (but I doubt it).


EDIT

Checked mosquitto.log and saw the same client connecting/disconnecting from different IP addresses. Doh! Big fat clue! My test system was logging into the MQTT Broker using the same client_id as my production system. Bad idea.

I changed the MQTT client_id on the test system, restarted Home Assistant, and now its log is devoid of re-connection messages. Most importantly, I can control MQTT lights so it’s publishing to topics properly.

I think I may be on to something. Look at the connections from your hass.io instance to the mosquitto server. I turned on anonymous connections and hass.io connects to mqtt but without a user.

example

New client connected from 192.168.. as mqtt_364b50d8.33dbc (c1, k60).   

Notice it doesn’t mention the 3rd variable in the message which should be something like u’youruserid’
So for some reason hass.io is not using the userid setup in integrations.

You’re right. I can confirm that, at least in my case, this 3rd variable (‘u’) is populated.

I’m not sure about the blank hours: ''

If you want to trigger every minute just use this:

  trigger:
  - platform: time_pattern
    minutes: '*'
   

Tom_I was correct it was the /1 for minutes that was the issue. It is now publishing on time and sending the message.

I am still getting the other error repeatedly so perhaps I have another device that is trying to talk to the mqtt server without a password. It just doesn’t give me any info about what device it is or it is something else on my pi that is trying to connect anonymously.

According to the documentation for Time Pattern Trigger, /1 is valid. Here’s the third example from the docs:

automation 3:
  trigger:
    platform: time_pattern
    # You can also match on interval. This will match every 5 minutes
    minutes: '/5'

So maybe the culprit was hours: (with no value set)?

For the MQTT Broker, you could try temporarily setting its logging level to all to have it reveal more information about the connection problem.

Assuming it is mosquitto, here’s a quick guide to changing the logging level: