Smart Home (part 1)

Kategoria: Smart-Home

Autor: admin@ignaszewski.pl | Opublikowany: 27 czerwca 2019

Few years ago I saw for the first time on Facebook page "Inteligentny dom za 500zł" (in English: Inteligent house for 500zł). It was very interesting for me, how make my house inteligent, how can I manage it? What can I connect to? And what I need to do that?

Because of many things to do, I didnt have time to make my dream come true, but I don't forget about it. Three months ago I found on the internet SonOff devices. They have a lot of different devices which can be connected to some cloud and you can manage them via your mobile device with proper application. It looks very promising, so I bought one SonOff device - double light switch.

When it comes to me, I installed it and connected via my mobile app to some cloud server. It was working. I was able to turn on/off my light using my home network or even being outside home I could check and change status of my light. In that moment I asked my self "Is it safe?". Hmm... I don't know.

I started digging in the internet if there is any possibility to connect such device to some local server. I found something like simple-sonoff-server. In few steps I was able to run it and connect my device to it, but unfortunetlly communication between device and server does not work correctly. I have to change the code of the server and after few hours I was able to turn on/off my light. Awesome! It worked, but there were few problems. Server does not have any frontend application. It has only some API, which was written in JS and there was no possibility to improve it or add new functionalities.

That time I fought that I could write my own apllication using Angular and Nest. After few weeks I wrote server and frontend application. Today I upload it to github. It is not final version, but 100% stable. I have run in on my Raspberry Pi B over one month ago and it still works.

Main features:

  • run on Raspberry Pi (needs: netstat, mysql, nodejs, self-sign certificate)
  • allow to turn on/off device
  • update switches status when someone use light switches directly
  • allow to turn on/off all device switches in one time
  • allow to rename device

But how it works. Everything is described in README, but the general concept is that:

  • first connect mobile to your light switch device
  • send to this device via Postman informations about your local network SSID, Password, IP and Port of your local server (this cause that device will conncet to local network and the server using websocket)
  • communication between server and device is using websocket
  • frontend application (written in Angular) use server API to make chanages on devices, but use also websockets to be notified when status of some device is changed

That's all. It is very simple.

I have a lot of ideas for this project, some of the planed features is below:

  • rename switch device name
  • create scheduler for turn on/off light (anti-thief mode - turn on/off light when you are on holidays)
  • create rooms
  • turn on/off all lights
  • implements other type of devices

All of that features require time, when it will be done? I don't know, but I'm happy that it is possible.

If you have any questions, do not hesitate to contact me. I will answer as soon as possible.