Reverse Door sensor's open/close state

I am certain there has to be a simple solution for this one.

So I use Zigbee2MQTT and Xiaomi Aqara MCCGQ11LM Door/Window sensors.

They work perfectly, and I just want to invert their on/off state, because no contact should mean off and contact should mean on - how would I do that?

I tried to do this, but it didn’t work: https://github.com/Koenkk/zigbee2mqtt/issues/3569 (or I did it wrong - they mean adding it to the /share/zigbee2mqtt/devices.yaml, right?!)

Also, not sure if this is more a Zigbee2MQTT, or a Home Assistant issue - I’m sure it could be solved either way.

Anyone know what the easiest solution is?

Make a template sensor for each:

binary_sensor:
  - platform: template
    sensors:
      front_door_inverted:
        value_template: "{{ is_state('binary_sensor.xiaomi_whatever', 'off') }}"
1 Like

Thanks - that’s definitely one way to do it.

I actually found the probably most elegant solution - pretty much do what they said in my link:

go to /share/zigbee2mqtt/devices.yaml and add

  homeassistant:
    contact:
      payload_on: true
      payload_off: false

like this:

'0x00xxxxxxxxxxxxb4':
  friendly_name: contact_07
  retain: true
  homeassistant:
    contact:
      payload_on: true
      payload_off: false

Then, don’t try to restart Home Assistant a million times, like I did … go to Settings, Devices, search for the device you want to change (contact_07 in my case) and delete it. Now restart Zigbee2MQTT. That’s all there is to it after all xD

9 Likes

Hello.
To reverse do the opposite:

‘0x00xxxxxxxxxxxxb4’:
friendly_name: contact_07
retain: true
homeassistant:
contact:
payload_on: false
payload_off: true

at least on my end.

Thanks.

Hi,

sorry to enter this thread, but I would like to ask if you know how to make this possbile with ZHA?

BR,
Senbei

sorry, but I exclusively use Zigbee2Mqtt - no Idea if there is a native way to do it in ZHA

However, you could just make template sensors within Home Assistant.

It would look something like that:

sensor:
  - platform: template
    sensors:
      inverted_sensor:
        friendly_name: "Door or whatever"
        value_template: >-
          {% if is_state('sensor.actual_sensor', 'on') %}
            off
          {% elif is_state('sensor.actual_sensor', 'off') %}
            on
          {% elif is_state('sensor.actual_sensor', 'unavailable') %}
            unavailable
          {% else %}
            error
          {% endif %}

DON’T quote me on that - I always struggle phrasing stuff like that right

3 Likes

Thanks, that works for me as a workaround.

nice! thanks for sharing

Nice solution. It avoid to design a new sensor and overload HA Configuration…

Thanks¡¡

Related to this, please vote if you agree: Option to invert icon_state coloring

I hope I can use this solution also, but I can’t find the devices yaml file.
In the folder share I there is only a check_config file. Where can I find the right folder?

This worked out great for me, thanks!

@Farnsworth How did you get the device to show back up after you deleted it and restarted ziggbee2mqtt

update if I remove the text from the example above and restart ziggbe2mqtt it will reload the device.