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?
Troon
(Troon)
July 9, 2020, 5:05pm
2
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
zerui
(ZR)
October 1, 2020, 7:46am
4
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.
Senbei
(Tristan's Smartes Heim)
December 28, 2020, 4:38pm
5
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
Senbei
(Tristan's Smartes Heim)
December 30, 2020, 12:13pm
7
Thanks, that works for me as a workaround.
neo2154
(Dave)
February 20, 2022, 11:51am
9
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
arjan21
(Arjan)
October 20, 2022, 9:06am
11
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?
Eric-boop
(Eric Boop)
January 6, 2023, 3:29am
12
This worked out great for me, thanks!
Bionic4
(Nate)
November 16, 2023, 9:10pm
13
@Farnsworth How did you get the device to show back up after you deleted it and restarted ziggbee2mqtt
Bionic4
(Nate)
November 16, 2023, 9:47pm
14
update if I remove the text from the example above and restart ziggbe2mqtt it will reload the device.