There is more than one way to skin the cat. There are at least five ways to use Aqara cube in your home automation. Some of them more creative than others, some of them just plain useful. In case you are not into the Insult-o-tron 9000 idea I have a couple of more uses for you.
Insult-o-tron 9000
The number of negative comments and messages I get (don’t treat this as a challenge) is probably bigger than 1 but smaller than 3 a year. Fortunately, social media take care of this for me, and for the most part, the notenoughtech across all the media channels is mostly family friendly! This makes the Insult-o-tron 9000 not that useful, but incredibly evil idea.
Wouldn’t be nice to shake your fist at someone then let the computer figure out the appropriate way to respond to the online bully while remaining classy as f*ck? (PG12 just went through the window)
Insult-o-tron 9000 is here to give you that quirky superpower! Shake your fist in anger at insults hurled at you – and respond in poetic, creative and incredibly mean style. Shakespeare all the way!
To make it happen, you have to know how to use MiHome Gateway and Aqara Cube in NodeRED. Thankfully, that’s already covered by me. I used the “air_shake” command to generate the insult and send it over to a PC or mobile (You can use it with Tasker).
First, I have to generate an insult. I have 3 arrays (my Shakespearean insults have 3 words) which store 35 phrases in each. I generate three seed numbers that are used to determine the words used in the insult. The insult is then pushed as a Join Message and stored in the computer’s clipboard.
Once the message has been set, I push the command to EventGhost to trigger the Ctrl+V macro to paste the selected insult into a text box! Simple and effective!
But if you want to use it for something useful…
Jokes aside, the Aqara Cube can be used for PC controls. In my examples, I’ve set up volume & desktop controls, but you could use it to automate a music or movie playback if you use a PC play the content (shake to play a random song, or double tap to pause the movie playback).
Volume
Aqara Cube rotation is used to turn the volume up or down. I’m grabbing the rotation info from the cube and based on the rotation angle, I turn the volume up or down by 10%. The info from the cube looks like this [-10:500] and it’s available as a string. I can split it into 2 parts using “:” and use the first value (converted to int) to drive two IF conditions.
An AutoRemote message is sent to EventGhost which will increase/decrease the volume accordingly. If you want to know more about AutoRemote in NodeRED – check this tutorial out.
Desktop switch
When I push the Aqara Cube, my PC changes the active desktop (Win+Ctrl+Left/Right). First, I have to keep track of which desktop is currently enabled. I used HTTP requests to update the NodeRED each time I change the desktop. I’m doing this so the NodeRED would know what is the active desktop (stored as flow variable) and send the correct instructions when the Cube is pushed.
Most of the “magic” happens on the EventGhost’s side. The AutoRemote message triggers the opposite key macro and feeds back the changes to NodeRED via HTTP posts. You can read more about the HTTP requests in NodeRED here.
import requests
username = getattr(eg.globals, "HTTP_user")
password = getattr(eg.globals, "HTTP_pass")
path = "/desktop/"
url = getattr(eg.globals, "HTTP_request") + path
data = {"desktop":"L"}
resp = requests.post(url, data, auth=(username, password),verify=False)
For some reason, the Win+Ctrl+Left/Right macro is being blocked by EventGhost if monitored, so I set up an additional macro to play this combination so I could also change the desktops using the keyboard.
Desktop extend
I use the double tap action to extend the screens. This is just to show you basic mouse controls in EventGhost. The NodeRED side just uses a function node to send a specific command to EventGhost.
To extend the desktop I have to execute Win+P and select the Extend option. I could not scroll down with macro keys for some strange reasons so I settled for the absolute mouse position and a click. Worked just fine in my tests.
Conclusion
The massive advantage of NodeRED in oppose to the native MiHome application is the ability to switch the cube control schemes on the fly. You could can have the cube controlling the movie when the playback is detected and switch to other schemes by enabling and disabling the flows. One cube, plenty of applications. I will keep the Insult-o-tron 9000 just in case 🙂
Project Download
Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.