home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
71.16k stars 29.83k forks source link

MQTT messages missed on 0.18 #1964

Closed jasonmhite closed 8 years ago

jasonmhite commented 8 years ago

tl;dr Upgrading from 0.16 to 0.18, an automation rule triggered by MQTT stops working.

Home Assistant release (hass --version): Working: 0.16.1 Broken: 0.18.1

Python release (python3 --version): Python 3.4.2 (Debian 8 ARM)

Component/platform: MQTT, maybe also LimitlessLED and Kodi but I think the issue is with MQTT.

Description of problem: I had been using 0.16.1, decided to do an update. I have a several rules that trigger various things on receiving an MQTT message. They work fine in 0.16.1, then stop working in 0.18.1. Reverting versions by checking out the git tag for 0.16.1 and reinstalling makes it work again.

Since I think it might also be relevant the MQTT server I'm using Mosquitto 1.4.8, built by me (to enable Websockets). Platform is a RasPi 2. MQTT clients can connect over both LAN and a private WLAN (HA is connecting via localhost).

Expected: HA acts on the received MQTT message.

Problem-relevant configuration.yaml entries and steps to reproduce:

A specific example, I have a rule to pause Kodi when receiving an MQTT message on a certain topic.

- alias: pause Kodi
  trigger: 
    platform: mqtt
    topic: control/media/kodi0/playpause
  action:
    service: media_player.media_play_pause
    data:
      entity_id: media_player.kodi0

Another one is supposed to toggle a LimitlessLED bulb on and off:

- alias: Toggle bedroom light
  trigger:
    platform: mqtt
    topic: control/light/bedroom0/toggle
  action:
    service: light.toggle
    data:
      entity_id: light.bedroom0

Sending any message to these topics should trigger the appropriate rule (I usually send an empty message, but I've tried adding stuff to see if it was just a weird matching bug).

Again, these work fine before then after upgrade they stop.

I think I also tried one of the 0.17 releases and it was also broken, but I don't remember for sure. I can if it would be helpful.

Traceback (if applicable): I don't get any error messages. When I enable logging and look through the log:

This is what makes me think it's something with the MQTT client failing silently. I saw issues #846 and #843, but they were fixed already right?

The only error message I get when starting HA is for a config file validation error in a different (unrelated) block in my config for automations. I didn't save that output, but I can go reinstall 0.18 again and grab it if needed.

Thanks as always, HA is one of my favorite projects!

balloob commented 8 years ago

Any config validation in automation will stop automation component from initializing

On Mon, May 2, 2016, 08:42 Jason Hite notifications@github.com wrote:

tl;dr Upgrading from 0.16 to 0.18, an automation rule triggered by MQTT stops working.

Home Assistant release (hass --version): Working: 0.16.1 Broken: 0.18.1

Python release (python3 --version): Python 3.4.2 (Debian 8 ARM)

Component/platform: MQTT, maybe also LimitlessLED and Kodi but I think the issue is with MQTT.

Description of problem: I had been using 0.16.1, decided to do an update. I have a several rules that trigger various things on receiving an MQTT message. They work fine in 0.16.1, then stop working in 0.18.1. Reverting versions by checking out the git tag for 0.16.1 and reinstalling makes it work again.

Since I think it might also be relevant the MQTT server I'm using Mosquitto 1.4.8, built by me (to enable Websockets). Platform is a RasPi 2. MQTT clients can connect over both LAN and a private WLAN (HA is connecting via localhost).

Expected: HA acts on the received MQTT message.

Problem-relevant configuration.yaml entries and steps to reproduce:

A specific example, I have a rule to pause Kodi when receiving an MQTT message on a certain topic.

  • alias: pause Kodi trigger: platform: mqtt topic: control/media/kodi0/playpause action: service: media_player.media_play_pause data: entity_id: media_player.kodi0

Another one is supposed to toggle a LimitlessLED bulb on and off:

  • alias: Toggle bedroom light trigger: platform: mqtt topic: control/light/bedroom0/toggle action: service: light.toggle data: entity_id: light.bedroom0

Sending any message to these topics should trigger the appropriate rule (I usually send an empty message, but I've tried adding stuff to see if it was just a weird matching bug).

Again, these work fine before then after upgrade they stop.

I think I also tried one of the 0.17 releases and it was also broken, but I don't remember for sure. I can if it would be helpful.

Traceback (if applicable): I don't get any error messages. When I enable logging and look through the log:

  • 0.16.1 -> When a message is sent to the appropriate topic, I get an output in the log saying the message was received
  • 0.18.1-> No mention whatsoever of any message received.

This is what makes me think it's something with the MQTT client failing silently. I saw issues #846 https://github.com/home-assistant/home-assistant/issues/846 and #843 https://github.com/home-assistant/home-assistant/pull/843, but they were fixed already right?

The only error message I get when starting HA is for a config file validation error in a different (unrelated) block in my config for automations. I didn't save that output, but I can go reinstall 0.18 again and grab it if needed.

Thanks as always, HA is one of my favorite projects!

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/home-assistant/home-assistant/issues/1964

jasonmhite commented 8 years ago

Ok then, well that certainly is the cause and now I've fixed the original issue, but there is still a bug/regression here I think. The error message:

16-05-02 12:01:29 homeassistant.bootstrap: Invalid platform config for [automation]: expected str for dictionary value @ data['trigger'][0]['to']. OrderedDict([('alias', 'Kodi brighten on pause or stop'), ('trigger', OrderedDict([('platform', 'state'), ('entity_id', 'media_player.kodi'), ('from', ['playing', 'paused']), ('to', ['idle'])])), ('condition', [OrderedDict([('platform', 'state'), ('entity_id', 'light.bedroom'), ('state', 'on')])]), ('action', OrderedDict([('service', 'light.turn_on'), ('data', OrderedDict([('entity_id', 'light.bedroom'), ('brightness', 255)]))]))])

I had ignored that message before because I wasn't quite sure what the error was. However, looking at it, it seems that the to: and from: blocks in a state trigger don't accept lists anymore. Previously, I had a rule to brighten my lamp a bit if Kodi is paused or stopped, which looked like:

- alias: Kodi brighten on pause or stop
  trigger:
    platform: state
    entity_id: media_player.kodi0
    from:
      - "playing"
      - "paused"
    to: "idle"
  condition:
    - platform: state
      entity_id: light.bedroom0
      state: "on"
  action:
    service: light.turn_on
    data:
      entity_id: light.bedroom0
      brightness: 255

Before (v. 0.16) this rule worked fine, but now it fails to validate. If I split this into two separate rules for each of the from: states, everything works again. I didn't realize that a validation failure for a particular item meant the whole component failed to load, I guess I just didn't notice the other automation rules weren't working either.

That said, this is still a regression on not being able to pass a list to to: and from:, right?

fabaff commented 8 years ago

everything works again

The issue seems to be solved. Please re-open as needed.