Node Red - Xiaomi Devices

Is someone able to help me understand what i’m meant to be doing with the node-red-contrib-mi-devices addon?

All I’m trying to do is mimic an HA automation whereby i click a xiaomi button and it turns on (or off) a light.

The thing is, i’ve no idea how i’m meant to string a flow together with the mi-devices to do this…

It’s talking to the gateway as it’s showing as online, but i just don’t know how i’m meant to pick up a click from that point onwards…

This is what i have so far but i’ve no idea if i need the click bit…or even the gateway to be honest.

I’m pretty confident i’ve got the light bit set up properly (as i have others working on timers)… so i just need to know how to capture the xiaomi stuff i guess…

Did you ever figure this out? I find myself in the same situation currently

Hi, sorry for only just seeing this… I do have it working now… Do you still need help?

Yes I still need help please. I tried quite a bit to find a tutorial or something to teach me but didn’t find anything really. Glad to hear you’ve figured it out

No Problem, So where have you gotten to? Here is my flow to use a button to turn on a light bulb :

So, the first node is an “All Events” node… which is basically saying to node-red "Listen to absolutely everything Home Assistant does and pass it to the next node.

The next one “Light Switches” is checking the msg.payload.entity_id that the “All Events” node sends, and if it is the entity ID of one of your xiaomi buttons, then it sends it down to the next node (Which one depends on which button is pressed)

image

The Xiaomi buttons have 3 click types… single, long and double… i don’t care how it’s pressed. so i just set all three types to do the same thing as you can see from the first image.

image

the last node is what actually turns the light bulb on and it does this by calling the service.toggle and sending it to the entity_id of the light bulb

image

I hope this makes sense… i tried to explain it how i would of liked it explained to me in the start… If you need more clarification or i’ve skipped a head too far, let me know.

I’ve added the code for the actual flow incase you want to import it and change it to suit :

https://pastebin.com/y0ccVaDc

5 Likes

Thank you danmed for taking the time to write out such easy instructions to follow. I tried adding the All Events node but when I do my Node Red keeps crashing. Sometimes it will work for a while and I will see all events except my Xiaomi Aqara Cube. The Xiaomi motion sensors, door sensors, and humidity sensors all work fine on their own with the “events: state” Home assistant node. I think maybe the cube is the problem. It never registers anything on the debug node like the rest of the xioami devices do.

exact same point here :wink:

Tks a lot Danmed, your tuto is brilliant !

The cube isn’t showing any debug :frowning: and in the mii home app you cant add two actions on the same bulb…

Little bit disapointing. I mean you create 1 automation in the app (flip 90° toggle the bulb) then you cant add another automation (rotate by example to change brightness)…

great post thank you so much!

I woke up this morning to find that all my xiaomi sensors are offline. not sure what is causing this. What are you all using for the sensors to connect to the gateway? I am using the Husbzb-1 stick.

I’m using the Xiaomi Gateway… i am running HA in an LXC container on a machine far too far away from the rest of the devices to be able to use a USB stick… (though i’d love to… the Xiaomi gateway does have a tendancy to occasionally shout at you in Chinese for no reason!)

I moved back to the Xiaomi hub, it seems to retain a better connection to the sensors. I am using a door sensor to turn on the hub’s light when the door is opened, but there seems to be a delay for the signal to get through - 10 second. Are you experiencing this? Any idea how I can resolve this because by the time the hub lights up the door is closed again.

Do you use the xiaomi motion sensor? I am trying to use this to activate a night lamp, the motion sensor does not always catch the motion.

I do use a motion sensor to activate the xiaomi hub’s light, but i’m not doing that through HA, i just do it through the mihome app

ok, I don’t want the Chinese to know that there was motion. I currently have the hubs external access turned off. Do you have the external access enabled?

I found this also when running on a pi 3 it was chewing up all the cycles for sensors and polling there was too much lag for automation. I firstly moved all automation off to a dedicated pi which works really well and happen almost instantly. I had an sd card failure on my main one this week and moved over to a Intel nuc and this is way snappier again. Unless you are using a server with enough resources I would suggest running 2 instances one for sensors polling ui etc and one for automation and brokers.

i first started seeing the lag now it seems to be ok. I am still on one pi. how much did the nuc cost?

You could get away with the celeron version for under $500aus so probably cheaper outside of Australia as we get gouged for everything. I actually went with an i5 version as I installed Ubuntu and use it for facial regonition and machine learning.

Could you make nodes configurations available?

For optimization purposes, I configured the first node this way:

This way I don’t have to check for all events.
Next, I put a switch to find which button was pressed and then which kind of click:

3 Likes

I’ve created a new topic recently about the xiaomi button sending duplicate messages.
Figured I’d ask here too, as those of you using nodered and xiaomi buttons would be here.
Anyone else recently notice duplicate messages being sent for the xiaomi buttons?
Here’s my topic: