Is your feature request related to a problem? Please describe
When Zigbee2MQTT restarts, all paired devices republish their current state to Home Assistant. These republished state changes are indistinguishable from genuine physical user actions. In Home Assistant, automations that use context filtering (trigger.to_state.context) to detect physical switch presses versus system-triggered state changes cannot differentiate a Z2M restart republish from a real human toggle — both arrive with parent_id: null, user_id: null, and a non-null id. This causes false positives in occupancy logic, presence detection, manual override detection, and any other automation relying on context to identify physical user intent.
Describe the solution you'd like
Add a z2m_source field to state messages published during a restart republish. For example, a normal device event would publish:
json{"state": "ON"}
While a restart republish would publish:
json{"state": "ON", "z2m_source": "restart_republish"}
Normal device-triggered state changes would omit this field entirely. Home Assistant automations can then include a condition checking that trigger.to_state.attributes.z2m_source is not restart_republish to reliably distinguish system-initiated republishes from genuine physical user actions. This requires no changes to HA core — it is purely a Z2M payload addition that integrators can optionally consume.
Describe alternatives you've considered
On the Home Assistant side, we fire custom zigbee_restart_started and zigbee_restart_complete events from a Z2M recovery automation and use a suppression window in AppDaemon to ignore all Zigbee signals during reconnect. This works but requires custom infrastructure, adds complexity, and does not protect native HA automations that use context filtering directly in YAML — those still have no reliable way to detect restart republishes without the proposed payload field.
Additional context
This affects any Home Assistant automation that uses trigger.to_state.context to detect physical user actions — a common and recommended pattern in HA for distinguishing manual switch presses from automation-triggered state changes. The three context fields checked are parent_id, user_id, and id. A Z2M restart republish passes all three checks identically to a genuine physical toggle, making suppression impossible at the HA context level alone. The proposed z2m_source field would be the cleanest solution as it requires no coordination between Z2M and HA core, is backward compatible (field absence means normal behavior), and gives integrators a reliable signal to filter on.
Is your feature request related to a problem? Please describe
When Zigbee2MQTT restarts, all paired devices republish their current state to Home Assistant. These republished state changes are indistinguishable from genuine physical user actions. In Home Assistant, automations that use context filtering (trigger.to_state.context) to detect physical switch presses versus system-triggered state changes cannot differentiate a Z2M restart republish from a real human toggle — both arrive with parent_id: null, user_id: null, and a non-null id. This causes false positives in occupancy logic, presence detection, manual override detection, and any other automation relying on context to identify physical user intent.
Describe the solution you'd like
Add a z2m_source field to state messages published during a restart republish. For example, a normal device event would publish:
json{"state": "ON"}While a restart republish would publish:
json{"state": "ON", "z2m_source": "restart_republish"}Normal device-triggered state changes would omit this field entirely. Home Assistant automations can then include a condition checking that trigger.to_state.attributes.z2m_source is not restart_republish to reliably distinguish system-initiated republishes from genuine physical user actions. This requires no changes to HA core — it is purely a Z2M payload addition that integrators can optionally consume.
Describe alternatives you've considered
On the Home Assistant side, we fire custom zigbee_restart_started and zigbee_restart_complete events from a Z2M recovery automation and use a suppression window in AppDaemon to ignore all Zigbee signals during reconnect. This works but requires custom infrastructure, adds complexity, and does not protect native HA automations that use context filtering directly in YAML — those still have no reliable way to detect restart republishes without the proposed payload field.
Additional context
This affects any Home Assistant automation that uses trigger.to_state.context to detect physical user actions — a common and recommended pattern in HA for distinguishing manual switch presses from automation-triggered state changes. The three context fields checked are parent_id, user_id, and id. A Z2M restart republish passes all three checks identically to a genuine physical toggle, making suppression impossible at the HA context level alone. The proposed z2m_source field would be the cleanest solution as it requires no coordination between Z2M and HA core, is backward compatible (field absence means normal behavior), and gives integrators a reliable signal to filter on.