Skip to content

Intermittent malformed payload for mqtt_trigger #820

@ALERTua

Description

@ALERTua
2026-04-13 12:45:22.569 ERROR (MainThread) [custom_components.pyscript.file.xiaomi_wireless_buttons] 
  File "/config/custom_components/pyscript/decorators/base.py", line 56, in check_expression_vars
    return await self._ast_expression.eval(state_vars)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/pyscript/xiaomi_wireless_buttons.py", line 1, in file.xiaomi_wireless_buttons.button_2_single @mqtt_trigger()
    payload_obj['action'] == 'single'
    ~~~~~~~~~~~^^^^^^^^^^
KeyError: 'action'

triggered for

@mqtt_trigger('zigbee2mqtt_slzb/xiaomi_wireless_button_2', "payload_obj['action'] == 'single'")
def button_2_single(trigger_type=None, var_name=None, value=None, old_value=None, context=None, **kwargs):
    log.debug(f"button_2_single")

I cannot reproduce this 100% of the presses. Maybe the button randomly sends malformed payloads. Disregard until an issue is raised, I guess.
I changed it to payload_obj.get('action', None).

I could not catch the event to get the real contents of the payload, as I don't understand how to do it in the UI of HA. I'm stupid or the events subscription just does not work.

via #818
ping @dmamelin

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions