Why and how to avoid device_ids in automations and scripts

In version 2.0, the Z2M project has aligned itself with the Home Assistant project’s preference for modeling a remote-control.

Instead of using a sensor entity to report button events, the preference is to model the remote-control as a device, so that the device’s button events are self-documented and can be referenced directly by an MQTT Device Trigger.

In addition, the button events can be optionally modeled as event entities (which also document all available button events). Z2M also supports event entities and they can be used in a State Trigger. Here’s an extensive explanation of how to use event entities.

Lastly, one can use an MQTT Trigger to subscribe directly to a button’s MQTT topic. However, one loses some of the additional functionality provided by MQTT Device Trigger and event entities (for example, the button’s previous event).

4 Likes