Xiaomi switch not registering single press

I have a Xiaomi gateway and a bunch of the sensors to go with it, a few of which are the round push buttons.
All seems to work fine, but I’ve noticed that under HA the single press of the buttons doesn’t register…

I’ve enabled debug log for the Xiaomi component and can see it hears the press fine:
2018-04-01 14:32:49 DEBUG (MainThread) [homeassistant.components.xiaomi_aq
ra] PUSH >> : {‘status’: ‘click’}

But in the HA front-end it doesn’t show as pressed.
Long press however shows up fine!

This is fine. You cannot see events at the UI. Just create an automation and check the documentation for examples.

Thanks @syssi,

I’m using Node RED with HA for my automations, and when I attach a debug node to the “state_changed” node for Home Assistant, I cannot see any event fire for single or double press.
I can see long press sends a msg.payload of on, then off however…

I noticed that all press events show up using the “all events” node, but there isn’t any filtering on that - but hopefully I can do something with it…

1 Like

Hi @swifty - I’m experiencing exactly this issue, did you ever get this figured out? Any help would be much appreciated! Thanks

Nevermind, @swifty, after reading around a little more it seems that this is a known limitation with the Xiaomi switches and you have to monitor for the click events, rather than a change in button state.

I found more information on this thread and was able to toggle lights on and off with a single click using the following code in automations.yaml

  alias: Xiaomi Switch 1click
  trigger:
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_xxxxxxxx
      click_type: single ## it can be: 'single', 'double' or 'long_click_press'
  action:
    service: light.toggle
    entity_id: light.office_lamp

I’ve now found how to detect single / double / long clicks within node-red, rather than using the HomeAssistant automations.yaml file(s).

I found the answer over on this thread, but for simplicity, here’s a workflow that’ll detect a single xiaomi click event and toggle a smartbulb on/off:

You can easily recreate this flow in node-red by copying the below code and using Menu > Import > Clipboard within node-red:

[{"id":"fff42ae9.58e918","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"4b2b46c8.9a9c28","type":"switch","z":"fff42ae9.58e918","name":"Xiaomi Button","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"binary_sensor.switch_158d000231fcc2","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":480,"y":200,"wires":[["e1aae596.8fe628"]]},{"id":"e1aae596.8fe628","type":"switch","z":"fff42ae9.58e918","name":"Button Click Type","property":"payload.event.click_type","propertyType":"msg","rules":[{"t":"eq","v":"single","vt":"str"},{"t":"eq","v":"double","vt":"str"},{"t":"eq","v":"long_click_press","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":707,"y":186,"wires":[["29d77911.472e96"],[],[]]},{"id":"cde4c62d.b0fb48","type":"server-events","z":"fff42ae9.58e918","name":"All HASS Events","server":"2366c39f.5e922c","x":200,"y":200,"wires":[["4b2b46c8.9a9c28"]]},{"id":"29d77911.472e96","type":"api-call-service","z":"fff42ae9.58e918","name":"Turn On Office Light","server":"2366c39f.5e922c","service_domain":"homeassistant","service":"toggle","data":"{\"entity_id\": \"light.office_lamp\"}","mergecontext":"","x":920,"y":160,"wires":[[]]},{"id":"2366c39f.5e922c","type":"server","z":"","name":"Home Assistant","url":"http://hassio/homeassistant","pass":"26fa4f45158b4a1391c988abdb08d507"}]

Hope this helps someone out there.

1 Like

I found that this node used to isolate for Xiaomi switch events results in quite an egregious memory drain, especially if you use them in a few different flows. Running pretty steady at 280 MiB with none of those nodes active. As soon as I add one it gradually rises to about 4-500 MiB over the course of a single day, and then “resets”. Prior to starting my whole setup from scratch (before I actually isolated the problem), I had a few flows using these nodes which resulted in a more rapid memory drain, a few “resets” during the course of a single day (perhaps once every 2-3 hours), and much more erratic behavior of my system (unresponsiveness, lag, etc.) Anybody else experiencing this (or figured out a workaround)?

FYI @frenck