Zigbee2mqtt button device trigger resets to Unknown in UI after restart

Hi all,

Problem

I have been using zigbee2mqtt integration with home assistant. After creating some automations with tradfri 5 button remote to control music (simple play/pause/next track), I noticed that upon restart (docker-compose restart/host os restart), in frontend ui, the trigger becomes unknown:

.

– more details below due to new user being limited to posting 1 embedded image and 2 links

Clicking in to see available triggers only shows update/up-to-date/battery level

Despite frontend showing as unavailable, the automation still works when the same button is pressed. and it YAML view, it shows the trigger correctly:

alias: Music button left > Prev song toilet pod itunes
description: ''
trigger:
  - platform: device
    domain: mqtt
    device_id: 5faf221fd0c97b2faa1c2d086dd52503
    type: action
    subtype: arrow_left_click
    discovery_id: 0x84fd27fffe481f44 action_arrow_left_click
condition:
  - condition: state
    entity_id: media_player.toilet_pod_airtunes_speaker
    state: 'on'
action:
  - service: media_player.media_previous_track
    data: {}
    target:
      entity_id: media_player.itunes
mode: single

This is different from a normal restart through settings > restart, where the trigger still retains.

This also causes problem, and a bigger problem, when I use tradfri on/off buttons and expose them to homekit with the guide here

Device Triggers

Devices that support triggers can be added to the bridge by accessing options for the bridge in Settings >> Devices & Services. To use this feature, Advanced Mode must be enabled in your user profile.
Bridged device triggers are represented as a single press button on stateless programmable switches. This allows a HomeKit automation to run when a device trigger fires. Because the Apple Home app currently only shows the number of the button and not the name, users may find it easier to identify the name of the button in the Eve for HomeKit app.

In this case, only triggers that are ‘pressed’ after restart of home assistant, will appear in homekit (in this case, eve, as recommended by the guide above)

screenshot of on/off button in frontend

screenshot of on/off button in homekit/eve

upon a further restart, the triggers will be reset again, only leaving Update, No_Update and Battery_Level in both frontend and homekit/eve

This causes all settings done at homekit side to be lost/corrupted.
Eg
Original behaviour: press on > turn on light scene
After restart, on is no longer a button in homekit. the same scene (turn on light) is rebound to Update, causing it to trigger whenever home assistant is restarted (settings > restart)

Expected behaviour

Across restarts (docker-compose restart/host os restart), the triggers for button presses (on/off) will persist, and not show as Unknown trigger. Also, the triggers/buttons in homekit should also persist.

Setup

Home Assistant 2022.7.7
Frontend 20220707.1 - latest
running in docker with the following docker-compose.yml based on this guide

version: '3'
services:
  homeassistant:
    container_name: homeassistant
    image: "ghcr.io/home-assistant/home-assistant:stable"
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
    restart: unless-stopped
    privileged: true
    network_mode: host

mqtt integration settings:

zigbee2mqtt
Zigbee2MQTT version: 1.25.1 commit: 3f6a137
Frontend version: 0.6.83

any help is appreciated

managed to create intermediary triggers that is controlled by mqtt devices and exposed as binary sensors for home assistant. since the sensors are configured in configuration.yml template, they are persistent even if the actual mqtt devices are unavailable on restart:

template:
  - trigger:
      platform: device
      domain: mqtt
      device_id: 44acf2586b15b25bbbe9baa05d120f9d
      type: action
      subtype: 'on'
      discovery_id: 0x84fd27fffeae5012 action_on
    binary_sensor:
      - name: Button shortcut table single press
        auto_off: 1
        state: true
  - trigger:
      platform: device
      domain: mqtt
      device_id: b82eda7059a7999c19518429368fd6ac
      type: action
      subtype: "on"
      discovery_id: 0x84fd27fffeae5010 action_on
    binary_sensor:
      - name: Button shortcut kitchen single press
        auto_off: 1
        state: true
1 Like

Well i’m having the same problems as you on ikea buttons connected to HA via z2m for a few months now, i’m gonna give your solution a go, but this is surely annoying.

An alternative solution is to set your automation trigger to use “When an MQTT message has been received” instead of trying to use a device trigger.