sonoff: Keyboard key reuse

Today I decided to make a sonoff project to fix a silly problem I was having on my positive notebook. It uses 3 extra keys to open netflix, youtube or create a custom command.

However I had never found a function for the custom command until today when I decided to create a function for it. So I decided to turn the sonoff switch on this key so that every time I press it, it turns the room light on or off.

This will come in handy when entering a meeting and having to turn the light off or on to help the camera. Soon I won't need to get up and I don't even need to have a cell phone in hand, just press the key and it turns on or off.

Starting the Sonoff Button Project

Before anything else to start the project I started looking for classes or libraries that connect with the sonoff platform I found some classes in python that didn't work as it should. In this sense I found this class in a project that was a sonoff ui on linux and best of all it worked.

Seeing the code of the class I noticed that the base of the system is websocket this makes me wonder if in the future I can receive notifications about status changes on the computer. It would be interesting since the program also put a notification to let me know what action was sent.

In summary, the project is very simple, in addition to the sonofff class, there is the main file that turns the light on and off.

Image shows the project notification;
project notification

Configuring sonoff project on key

To configure I created a folder with the executable file, and the project icon which is a light bulb, executable that I use to trigger the command to sonoff when I press the target key. Remembering that this file will be executed every time the target button is pressed

Image shows the project folder with the executable file and icon.
Image of the folder containing the executable file

For Windows to recognize the executable as a program, I added a folder to the system PATH environment variable. However, this step is important because the path of all Windows programs needs to be in this variable.

Image shows the paths of the PATH variable folders.
Environment variable with project path

Then I created an executable shortcut in the programs folder of the start menu so you can create the keyboard shortcut.

C:\ProgramData\Microsoft\Windows\Start Menu\Programs

Image shows the properties of the sonoff button project executable.
Project and key shortcut properties

The image above doesn't show but in the shortcut key this is the target key which is a key that does not appear because it is a special key.

Creation Challenges

Amazingly, I didn't have many challenges in creating the executable, it was very simple to find the libraries and create the project. The hard part was working with Windows because I had some difficulties that I overcame with a lot of patience and research.

The first one was with the positive program I removed the program that was running when I pressed the target key. However, removing this program was not all because the program kept being called giving an error since it had removed the program.

It was then after some time searching the internet I found the process of the program that was listening to the target key, it was then that I stopped that program and removed it from the computer. After I solved this problem I researched how to create a keyboard shortcut, a process that I mentioned earlier.

However the code is very simple, the level of difficulty to make this project was low, it took me longer to publish this text than to do the project.

Upcoming Challenge

Now I'm creating a new version of the project that works as a service like the positive program that was installed. Then this service will be running in the background listening for the target key, to execute the function.

I'm currently having a problem with the service it's not running and when it runs it doesn't hear this is the problem I'm having.

Technologies Used

Video Explanation

Video shows the execution of the project

Test the Sonoff Project

The project is available on github, feel free to download, test and contribute, follow the links below.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.