Skip to content

03. Programming

Psycho edited this page Jun 22, 2018 · 7 revisions

Programming

We’ll do this in Python… I’m using Jetbrains PyCharm because it has everything at once, no need for Putty/Kitty, it auto uploads, has an ssh client etc etc. There's even a free version (community version)

I’ll assume that if you read and followed up to here, you have a running pi zero, meaning I won’t cover the Raspbian installation.

Make sure to install Snips following the wiki on their repository

And check if it is really running/working using snips-watch -v in your pi console

I will not cover the entire programming part but simply share a basic script that you’ll be able to extend to your needs and explain how it works

  • Go to your snips account and add my published bundle called “Velux” to your assistant and upload it to your raspberry by following this guide if not familiar

  • The bundle has 4 intents:

    • openBlinders
      • Slots
        • place
        • percentage
    • closeBlinders
      • Slots
        • place
        • percentage
    • openVelux
      • Slots
        • place
        • percentage
        • duration
    • closeVelux
      • Slots
        • place
        • when
  • None of the slots are required. If you don’t mention a place, our script will open all the windows / blinders

  • Now we need to program the actions… It’s not hard, don’t be scared!

  • Download the script from my repository

  • Open the velux.py file with your favorite editor and head to line 79. You should find a dictionary called “_COMMANDS”. This is nothing more than a listing of button presses you would make to execute an action using the remote! Say you had a normal remote, if you wanted to fullOpen the selected windows, you'd press 7 twice, rapidly.

  • If you insert strings in the command array, it will set the following button presses delay. By default, between each button press you’ll have a 0.5 second wait time. Override it by using strings. Yes, “select….” commands start with a ‘1.5’. That is because, if you try it yourself, pressing the “Locate” button, using keypad number 3 has a huge lag. We must make sure the remote has time to open the locate display before continuing and setting the delay to ‘0.25’.

  • Let’s look at one example: ‘selectBedroom’: [‘1.25’, 3, ‘0.25’, 5, 1, 1, 5, 5, 1]

    • Set the delay for the next action to 1.25 seconds
    • Press button #3 (Locate) - wait 1.25 seconds
    • Set delay for the next action to 0.25 seconds
    • Press button #5 (Arrow down) – wait 0.25 seconds
    • Press button #1 (Enter) – wait 0.25 seconds
    • Press button #1 (Enter) – wait 0.25 seconds
    • Press button #5 (Arrow down) – wait 0.25 seconds
    • Press button #5 (Arrow down) – wait 0.25 seconds
    • Press button #1 (Enter) – wait 0.25 seconds
  • This example will only work for me! If you happen to have a room in second position with 2 Velux in it and blinders, then it will work for you too. Otherwise, you will need to create your own commands!

    • Create a new key in _COMMANDS
    • The key naming starts with “select”, followed by the room name as declared in the Snips intent slot “place”, followed by either “Windows” or “Blinders.
    • Add a 1.25 seconds delay, a press on button 3 and a 0.25 seconds delay.
    • Add any key combo needed to select the product/s your command should trigger.
    • To make it clear and help understand those of you not really getting it (chambre = room in french, maison = house aka all windows):

This would translate to: ‘selectBedroomWindows’: [‘1.25’, 3, ‘0.25’, 5, 1, 1, 5, 5, 1]

  • If you want to operate your blinders, well, it’s the same! Blinders work just like windows, just add a ‘selectXXXBlinders’ with the needed combo!
  • Once you have added all the commands you need, edit the INTENT variables on lines 75 to 78 to match yours. Snips adds your username followed by a semi colon, match your username!
  • Well, that’s about it! Upload the script to your raspberry, start it by typing “python velux.py”. As soon as the script starts, your controller should turn on and 12 seconds later a message asks you to type a button number. You don’t have to, I added this part for convenience, so that we can use our remote by using our keyboard. If you need to reset the controller, you can type reset and the controller will reboot and reset. Be aware that if you reset, you’ll have to add all your products back (or transfer from another remote, which is way easier).
  • Take a deep breath and ask Snips to open your windows! Something as simple as “Hey Snips, open my windows” should trigger them all to open to 100%
  • Once tested, make sure to change line 64 to True. The reed relays aren't made to keep current for long time. Or start the script using the correct arguments (python velux.py 0 1). Or try the new hardware hack!
Clone this wiki locally