[Workarounded] Python script automation is not fired by mqtt trigger in .90.1

Hi,
I have a following automation:

- id: '1534873898210'
  alias: Přepočet tlaku na úroveň moře
  trigger:
  - platform: mqtt
    topic: ha/test/run
  - platform: mqtt
    topic: node/outdoor_1/barometer/0:0/pressure
  condition:
  - condition: template
    value_template: '{{ states(''sensor.tlak'') != ''unknown'' }}'
  - condition: template
    value_template: '{{ states(''sensor.teplota_venku'') != ''unknown'' }}'
  action:
  - service: python_script.recalculate_pressure_value
    data:
      height: 311
      pressureSensor: sensor.tlak
      temperatureSensor: sensor.teplota_venku
      topic: ha/converted/pressure/outside

It supposed to be run each time, when mqtt topic is received, recalculates a pressure to sea level pressure and publish the result via mqtt. It worked well in 0.88.

Yesterday I’ve upgraded to .90.1 and today I’ve found, that this automation does not work.

I can run the automation manually via Developer tools, so script is accessible and correct, but triggering via mqtt does not work. Also time_pattern trigger does not work.

But I have other animations, like below, that works fine with time_patter or mqtt triggers. Only difference is, that they does not call a python script.

- id: '1999473448189'
  alias: Republish moon state
  trigger:
  - entity_id: sensor.moon
    platform: state
  - platform: mqtt
    topic: ha/test
  condition: []
  action:
  - data:
      payload_template: '{{ states(''sensor.moon'') }}'
      topic: ha/moon/state
    service: mqtt.publish

There is nothing in the log and I don’t know how to debug it :frowning:

The Release Notes tell of breaking changes.

  • MQTT - Pass Message object to MQTT message callbacks instead of topic , message and qos . Users of custom components please take note, these values are now available on the passed in message object: msg.topic , msg.message , msg.qos . The old method will continue to work for now but will print warnings. (@emontnemery - #21959) (mqtt docs)

But automation work when is called via Service developer tool.

I’ve enabled debug mode.

This is when is automation started via service menu:

2019-03-26 20:04:28 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2910878512] Received {'type': 'call_service', 'domain': 'automation', 'service': 'trigger', 'service_data': {'entity_id': 'automation.prepocet_tlaku_na_uroven_more'}, 'id': 21}
2019-03-26 20:04:28 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=automation, service=trigger, service_data=entity_id=automation.prepocet_tlaku_na_uroven_more>
2019-03-26 20:04:28 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=Prepocet tlaku na uroven more, entity_id=automation.prepocet_tlaku_na_uroven_more>
2019-03-26 20:04:28 INFO (MainThread) [homeassistant.components.automation] Executing Prepocet tlaku na uroven more
2019-03-26 20:04:28 INFO (MainThread) [homeassistant.helpers.script] Script Prepocet tlaku na uroven more: Running script
2019-03-26 20:04:28 INFO (MainThread) [homeassistant.helpers.script] Script Prepocet tlaku na uroven more: Executing step call service
2019-03-26 20:04:28 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=python_script, service=recalculate_pressure_value, service_data=height=311, pressureSensor=sensor.tlak, temperatureSensor=sensor.teplota_venku, topic=ha/converted/pressure/outside>
2019-03-26 20:04:29 INFO (SyncWorker_0) [homeassistant.components.python_script] Executing recalculate_pressure_value.py: {'height': 311, 'pressureSensor': 'sensor.tlak', 'temperatureSensor': 'sensor.teplota_venku', 'topic': 'ha/converted/pressure/outside'}
2019-03-26 20:04:29 INFO (SyncWorker_0) [homeassistant.components.python_script.recalculate_pressure_value.py] Data: pressure: 98519.5, temperature: 5.5, height: 311.0
2019-03-26 20:04:29 INFO (SyncWorker_0) [homeassistant.components.python_script.recalculate_pressure_value.py] Data: pressure: 98519.5, temperature: 5.5, height: 311.0
2019-03-26 20:04:29 INFO (SyncWorker_0) [homeassistant.components.python_script.recalculate_pressure_value.py] Converted pressure 1023.62
2019-03-26 20:04:29 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=payload=1023.62, topic=ha/converted/pressure/outside>
2019-03-26 20:04:29 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on ha/converted/pressure/outside: 1023.62
2019-03-26 20:04:29 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on ha/converted/pressure/outside: b'1023.62'
2019-03-26 20:04:29 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.tlak_more, old_state=<state sensor.tlak_more=unknown; unit_of_measurement=hPa, friendly_name=Tlak (přepočtený), icon=mdi:arrow-top-right @ 2019-03-26T19:57:24.645982+01:00>, new_state=<state sensor.tlak_more=1023.62; unit_of_measurement=hPa, friendly_name=Tlak (přepočtený), icon=mdi:arrow-top-right @ 2019-03-26T20:04:29.065383+01:00>>

Script is started, recalculated value published.

And now when I sent a special mqtt message:

2019-03-26 20:08:12 DEBUG (MainThread) [homeassistant.components.mqtt] Received message on ha/test: b''
2019-03-26 20:08:12 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event automation_triggered[L]: name=Republish moon state test, entity_id=automation.republish_moon_state_test>
2019-03-26 20:08:12 INFO (MainThread) [homeassistant.components.automation] Executing Republish moon state test
2019-03-26 20:08:12 INFO (MainThread) [homeassistant.helpers.script] Script Republish moon state test: Running script
2019-03-26 20:08:12 INFO (MainThread) [homeassistant.helpers.script] Script Republish moon state test: Executing step call service
2019-03-26 20:08:12 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event call_service[L]: domain=mqtt, service=publish, service_data=payload_template={{ states('sensor.moon') }}, topic=ha/moon/state>
2019-03-26 20:08:12 DEBUG (MainThread) [homeassistant.components.mqtt] Transmitting message on ha/moon/state: waning_gibbous
2019-03-26 20:08:12 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=automation.republish_moon_state_test, old_state=<state automation.republish_moon_state_test=on; last_triggered=2019-03-26T20:03:29.830560+01:00, id=1999473448189, friendly_name=Republish moon state test @ 2019-03-26T20:02:06.949286+01:00>, new_state=<state automation.republish_moon_state_test=on; last_triggered=2019-03-26T20:08:12.957059+01:00, id=1999473448189, friendly_name=Republish moon state test @ 2019-03-26T20:02:06.949286+01:00>>
2019-03-26 20:08:12 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.2910878512] Sending {'id': 2, 'type': 'event', 'event': <Event state_changed[L]: entity_id=automation.republish_moon_state_test, old_state=<state automation.republish_moon_state_test=on; last_triggered=2019-03-26T20:03:29.830560+01:00, id=1999473448189, friendly_name=Republish moon state test @ 2019-03-26T20:02:06.949286+01:00>, new_state=<state automation.republish_moon_state_test=on; last_triggered=2019-03-26T20:08:12.957059+01:00, id=1999473448189, friendly_name=Republish moon state test @ 2019-03-26T20:02:06.949286+01:00>>}
2019-03-26 20:08:14 DEBUG (MainThread) [homeassistant.core] Bus:Handling <Event state_changed[L]: entity_id=sensor.memory_free, old_state=<state sensor.memory_free=1307.8; unit_of_measurement=MiB, friendly_name=Volná paměť, icon=mdi:memory @ 2019-03-26T20:07:43.102106+01:00>, new_state=<state sensor.memory_free=1307.6; unit_of_measurement=MiB, friendly_name=Volná paměť, icon=mdi:memory @ 2019-03-26T20:08:14.094124+01:00>>

Only a second test entity, not using python script is called. No more messages in log :frowning:

Just a note. It still does not work on 0.91, don’t know why. I’ve “solved” this by converting the calculation from python script into template.