Xiaomi smart home

normally fixed, replace with the last file:

https://github.com/fooxy/homeassistant-aqara/tree/master/custom_components/switch

Only one line is required in the configuration.yaml:

aqara:

let me know if it works. Thank you

Thanks a bunch @fooxy… Loaded the module with switch and was originally getting _STATE errors. I added a line “self._state = False” into the INIT function and it started working :wink: Not sure if that’s the best place for it though… Apparently on load up it has no state.

You’re right, I added the line with a minor modification : self._state = False. Thanks.

@fooxy is there a possibility to add support for the wall power plug (zigbee version)?

It would be cool if you could use the speaker of the Xiaomi hub as a media_player, e.g. together with the new text-to-speech component for audible notifications.

1 Like

Hi everybody,

I’m living in China and I bought two xiaomi sets already, I think they’re working well and great value for money but the management software is very basic, cannot do much.

So googling I arrived here and it seems the right place to extend the function of this set
I’ll keep watching this thread and community with great interest :slight_smile:

I played a little with the wireless switch… listening with tcpdump i find the long press possibilities…

When i take the button pressed for 2 seconds it fire the event long_click_press and when i release it the event long_click_release event

So i modified the switch/aquara.py to integrate the long press in this way

Line 13 from
SWITCH_TYPES = [‘ONE_CLICK’, ‘DOUBLE_CLICK’]

To
SWITCH_TYPES = [‘ONE_CLICK’, ‘DOUBLE_CLICK’, ‘LONG_CLICK’]

Then in the line 91 before
super().update_ha_state()

I inserted this

    elif self.deviceVariable == 'LONG_CLICK':
        if status == 'long_click_press' and self._state == False:
            self._state = True
        else:
            self._state = False

Now in the home assistant i have this 3 elements

The long click became on when i long press the button and suddenly off when i released it… but i think is ok to fire an event

:slight_smile:

2 Likes

Thanks to the great update by fooxy, i managed to extract the token from the heatbeat. And after several nights working on it, i managed to figure out how the encryption works and by encrypting the token with the hub Key, i succeeds in turning on and off the plug :slight_smile: That’s done, so what’s left is writing the code for the switch. I’m still learning python but it is quite similar to Javascript/C# which i’m used to. So using the same method, i can also now control Xiaomi hub from a ASP.net web server.

But too bad there’s no API to control the hub’s light and radio.

Btw, you can also check my thread here in case you’re working with SmartThings, xiaomi devices can be paired to ST. But one of the reason i switch partially to HA is because i like local processing. ST cloud is way too slow

1 Like

great progress on that. Were you able to control the hub itself (e.g. arm/disarm, sound)?

This would complete my dreams. Will be some beer money involved for someone who manages to get the alarm working :slight_smile:

No, i don’t see the API for that unfortunately. Right now, the only devices that’s controllable are the Zigbee devices connected to the hub. But I’ll look around after i got everything else working. My ideal goal is to have it works with multiple hub.

Another way to activate it’s alarm is to hack the Zigbee button and control it using esp8266 or RF receiver from HA. I have been experimenting to attach a smoke sensor to the button/door sensor so that it activates and trigger the alarm using xiaomi automation

Hi @fooxy thanks for great work. I’ve tested all sensors and switch and they work great!

@rave could you share your code for managing outlets? It would be great to have complete management of Aqara devices.

Right now, i hardcoded the sid and send the message manually to the hub and confirm the data and the key works. So once i wrote the plug and switch subcomponent code, i’ll share.

But since i’m not using fooxy aqara component (i rewrote the entire thing to learn python :slight_smile:) what you may need is to take some of my code and make it works on fooxy’s hub’s code.

Update: Time to sleep now

Working with the wall switch as well

1 Like

will this work with the wifi socket/plug as well (non-zigbee)?

No, it’s only for the Zigbee plug

@rave one doubt, if a use this switch:

i only can turn on or off the XIAOMI bulbs right? If i want to control my common bulbs, i cant right?

Yeah… Unless you changed the wall switch into aqara wall switch or other switch that HA support. That’s what i did, i changed the wall switch instead of the bulb.

Can you show me the switches you use?

Strange, i couldn’t find it from its official website anymore. Anyway, here’s another link. There’s 2 version. One with relay is installed into existing wall and one is just a zigbee switch

http://xiaomi-mi.com/mi-smart-home/xiaomi-aqara-smart-light-control-set/