What do I need?
- 1 or more Aeotec Minimote(s)
- A Home Center 2
Let’s get started
- Make sure the Minimote has battery and is factory reset (not currently included to another system.) Do this by pressing and holding the “Associate” and “Learn” buttons simultaneously for 10 seconds. The device will flash flash the Blue LED for 2 seconds to indicate it has been successfully reset.
- Press the “Learn” button on the Minimote – the blue LED will start to slowly blink
- On your HC2, go to Devices > Add/Remove Devices and put the HC2 in Learning Mode.
- Once included, go into the device’s settings and make sure parameter 250 is set to “1”. This should be there by default, but if not set the parameter and wake the Minimote up (by pressing and holding the “Learn” button for 3 seconds.)
- Make a note of the Device ID that the system assigns to this device, you’ll need it later.
You can create a device from scratch, or download one here. How you lay the device out is not important, what is important is that it has 8 buttons. You also don’t need to worry about the names on the buttons, feel free to change them to something more meaningful if that helps.
- Create a new Lua Scene
- Copy and paste the following code into that scene
--[[ %% properties 201 sceneActivation %% globals --]] --------- Your Device ID's Here --------- local virtualDevID = 202 --Edit these values!! local minimoteID = 201 ------ Do not edit below this line ------ local buttonPressed = fibaro:getValue(minimoteID, 'sceneActivation') fibaro:call(virtualDevID, 'pressButton', buttonPressed)
You’ll have 3 new items in your system – a Physical Zwave Device, a Lua Scene and a Virtual Device.
The scene takes the button press on the physical device, and presses the corresponding button on the Virtual Device.
Open up the virtual device and go through changing the buttons types to Lua. From here, you just need to add whatever code you want to execute on a given button press.
Single button presses return an odd value:
- Button 1 = 1
- Button 2 = 3
- Button 3 = 5
- Button 4 = 7
Press and hold actions return an even value:
- Button 1 = 2
- Button 2 = 4
- Button 3 = 6
- Button 4 = 8
So, if you want to map an action to turn on a light with a single press of Button 1, and off again with a press and hold of the same button, you would add the “turnOn” command to Button 1, and the “turnOff” command to Button 2.
That’s great, but why?
--[[ %% properties 201 sceneActivation %% globals --]] local ButtonPressed = tonumber(fibaro:getValue(201, 'sceneActivation')) if ButtonPressed == 1 then --do something elseif ButtonPressed == 2 then --do something else elseif ButtonPressed == 3 then --do something else elseif ButtonPressed == 4 then --do something else elseif ButtonPressed == 5 then --do something else elseif ButtonPressed == 6 then --do something else elseif ButtonPressed == 7 then --do something else elseif ButtonPressed == 8 then --do something else else fibaro:debug('Error') end
- It makes it much easier to read and manage. A big stack of “ifelse” statements gets visually confusing, especially once you’ve added complex commands to all of the available button presses. The segregation of code on the Virtual Device is much friendlier.
- You can now push the buttons virtually. So if you don’t have the Minimote to hand, you can virtually push it’s buttons using the Virtual Device (just as the name suggests!)