zigbee2mqtt icon indicating copy to clipboard operation
zigbee2mqtt copied to clipboard

Switch listed in HA as sensor (should be binary_sensor)

Open avolmensky opened this issue 8 years ago • 5 comments

I have a Xiaomi WXKG01LM Smart Switch, when I pair it to zigbee2mqtt it comes up in Home Assistant as a sensor, while the door switch and motion sensors appear as binary_sensor. The value of that sensor is whatever the last press of that button was (eg, single, double)

The problem I have is whenever I make a change in the home assistant web interface (eg, renaming a sensors name/entity_id) HA fires out the value of the sensor and will trigger an automation to just say toggle a light.

Is there any way to get this device to act like a binary_sensor? This button is a little different than just say a door sensor as you can double tap it. @ciotlosm is this the problem that https://github.com/home-assistant/home-assistant/pull/14957 is trying to fix?

avolmensky avatar Oct 12 '18 01:10 avolmensky

I'm also losing my mind with this same switch... being detected as a sensor, I can't make any automation work...

mario-g0 avatar Oct 18 '18 15:10 mario-g0

Use the message as a trigger

  - alias: single_p
    trigger:
      platform: mqtt
      topic: 'zigbee2mqtt/xiaomibutton_p'
    condition:
      condition: template
      value_template: "{{ 'single' == trigger.payload_json.click }}"
    action:
    - service: scene.turn_on
      entity_id: scene.vr_hell ```

Underknowledge avatar Oct 18 '18 20:10 Underknowledge

@WagnerBeccard The problem with using the message as a trigger, is when you make certain changes in Home Assistant (eg Changing the entity_id/name on any other sensor/binary_sensor from the web interface) home assistant will transmit that same message again (even though the button wasn't pushed) and trigger the action again. I get a lot of false button presses when using the button as a sensor

avolmensky avatar Oct 19 '18 01:10 avolmensky

The homeassistant sensor shouldn't be used to respond to button clicks. You should instead rely on the MQTT messages (as @WagnerBeccard mentions and which is also described on the wiki: https://github.com/Koenkk/zigbee2mqtt/wiki/Integrating-with-Home-Assistant).

The binary sensor cannot be used because buttons can have multiple values (e.g. single, double, triple, etc.), and even if it could, it won't solve anything.

Koenkk avatar Oct 19 '18 20:10 Koenkk

No worries. Sorry missed the part of using the MQTT message as a trigger, not the sensor value.

avolmensky avatar Oct 20 '18 00:10 avolmensky