Zigbee2MQTT correct automation syntax

I’ve got a Xiaomi Honeywell Smoke Detector added to my home assistant.

I’ve made an automation from the UI which looks like this:

- id: '1635939813744'
  alias: Fire Detected
  description: Send alarm to phone when Fire is detected
  trigger:
  - platform: state
    entity_id: binary_sensor.smoke_detector_1_smoke
    from: 'false'
    to: 'true'
  action:
  - event: Smoke detected notify phone
    event_data:
      service: notify.mobile_app_sm_g988b
      data:
        message: Fire detected
        title: Fire Alarm
        data:
          ttl: 0
          priority: high
          channel: alarm_stream_max
  mode: single

And it works.

But… On the zigbee2mqtt home page it recommends using the MQTT device trigger. Is there any benefits of using the MQTT device trigger? If so, what would an automation for this smoke detector look like?

That’s surprising because a binary_sensor’s states are on/off not true/false.

Go to Developer Tools > States, find binary_sensor.smoke_detector_1_smoke and check what is shown as its current state value.

Here is a picture:

I guess you can see it as clearly as I can; its state value is currently off not false.

That’s why I said I was surprised when you stated this State Trigger works (because it uses true/false values but the binary_sensor produces on/off):

  - platform: state
    entity_id: binary_sensor.smoke_detector_1_smoke
    from: 'false'
    to: 'true'

You tested this automation by making the smoke detector actually activate?

Or did you test it by manually triggering it using Run Actions or the automation.trigger service?

I tested with actual smoke :slight_smile: I made this automation from the UI, where it gave me the choice of true or false, if I remember correctly.

Anyway, my actual question is if I should make a new automation based on the MQTT device trigger? And if so, why should I use that instead of the one I have? Any benefits?

Bare in mind I’m a complete noob here :crazy_face:

The Automation Editor doesn’t give true/false choices for a State Trigger.

The to and from fields are text fields not dropdown lists offering choices.

It’s not necessary. If you say this version works, keep using it.

Ok, thanks. I’ll just ignore the MQTT automation then and continue with the one I have.

Thanks Taras

BTW, here’s another way to test your automation’s trigger.

  1. Go to Developer Tools > States and select binary_sensor.smoke_detector_1_smoke.
  2. It should appear like the screenshot you posted above.
  3. Change off to on in the State field.
  4. Click the Set State button.
  5. If it triggers your automation then it’s working properly.
  6. If it fails to trigger the automation, you will need to reconsider how the automation’s trigger is configured.

Great! Thanks for the tip​:+1::grinning: Keeps me from starting a fire everytime I want to test it :grin:

So did changing the binary_sensor’s state value from off to on trigger automation.fire_detected?

No it didn’t work… But I can see that for the Smoke state it seems to be true or false. And I guess that is the state which is triggering my automation?

Hi again,

I installed the MQTT explorer and set the smoke value to true, and the automation did not work. The state went from off to on, so I think you are right. I need to change my automation :slight_smile: Thank you again for your support Taras.

You’re welcome!

Being alerted due to the presence of smoke is important and I wanted you to be certain that the automation’s trigger worked properly.

Please consider marking my post above with the Solution tag. It will automatically place a check-mark next to the topic’s title which signals to other users that this topic has been resolved. This helps users find answers to similar questions. For more information, refer to guideline 21 in the FAQ.