How to invert a binary sensor in Zigbee2MQTT

Disclosure: This post contains affiliate links. If you click through and make a purchase, I will earn a commission, at no additional cost to you. Read my full disclosure here.

An abstract, digital illustration of two inverted wine glasses.

Imagine this: you've proudly built your very own chair occupancy sensor, but alas, it's playing a game of musical chairs with your Home Assistant occupancy groups. Fear not, dear reader, for I shall be your guide in this thrilling adventure of inverting binary sensors in Zigbee2MQTT.


Access the Inner Sanctum: configuration.yaml

To rectify this perplexing inversion issue, you must first venture into the heart of Zigbee2MQTT: the configuration.yaml file. Although Zigbee2MQTT's dashboard is a veritable treasure trove of options, it is no help when it comes to this particular task.

Before embarking on this digital odyssey, make a brief stop at the dashboard to identify the type of sensor you're wrestling with. In our case, it's a contact sensor, as evidenced by the accompanying screenshot.

A contact sensor, which isn't inverted, being displayed in the Zigbee2MQTT dashboard.

The Art of Inversion

With the sensor type in hand, it's time to dive into the depths of configuration.yaml. If you haven't already, consider assigning a friendly name to your sensor via the Zigbee2MQTT dashboard. Doing so will make finding your sensor as easy as spotting a bright red apple in a sea of green.

Once you've located your sensor, add these lines to the file, taking care to replace contact with the appropriate sensor type:

    friendly_name: office/sensor/chair_occupancy
        payload_on: true
        payload_off: false
A screenshot of Home Assistant's settings for an inverted binary sensor.

Victory: Inverted Sensor Achieved

Congratulations, intrepid explorer! You've successfully inverted your binary sensor in Zigbee2MQTT. But before you celebrate, remember to restart the application to ensure your changes take effect.

As a final precaution, return to Home Assistant and confirm that your sensor is indeed reporting accurately. Now you can sit back (literally) and enjoy the fruits of your labour, knowing that your chair occupancy sensor is working in perfect harmony with Home Assistant.

A portrait photo oif Liam Alexander Colman, the author, creator, and owner of Home Assistant Guide wearing a suit.

About Liam Alexander Colman

is an experienced Home Assistant user who has been utilizing the platform for a variety of projects over an extended period. His journey began with a Raspberry Pi, which quickly grew to three Raspberry Pis and eventually a full-fledged server. Liam's current operating system of choice is Unraid, with Home Assistant comfortably running in a Docker container.
With a deep understanding of the intricacies of Home Assistant, Liam has an impressive setup, consisting of various Zigbee devices, and seamless integrations with existing products such as his Android TV box. For those interested in learning more about Liam's experience with Home Assistant, he shares his insights on how he first started using the platform and his subsequent journey.

Leave a comment

Share to...