This project is aimed to control home lights.
It consists of tree major parts:
- A custom-made circuit board with switches (based on Triacs). The board description can be found here.
- Arduino Mega board which controls the switches. Find Arduino sketch in the ArduinoLightSwitcher file.
- Raspberry PI with an HTTP server (a .NET Core app written on C# running on Kestrel) to contol Arduino.
Arduino Mega controls the optocouplers by setting LOW or HIGH signal to the corresponding pins. Raspberry PI sends simple byte commands via serial connection to Arduino. Arduino reads the commands, interprets them to turns on or off a particular switch.
Raspberry PI is connected to home wifi network and exposes a web API and a single html page with UI, which should be accessible from the local network by any device.
The lightswitcher is not accessible from the Internet, though one can expose a public IP trough their router and setup ports mapping. However, there is no security layer or any authentication other than the wifi network password, so some authentication should be added.
Nevertheless, the light at home can be controlled from the Internet indirectly. A service app on Raspberry PI can read commands from some resource by polling it periodically. Options are:
- Pub/sub with some cloud based service (not implemented)
- There is a simple nodejs API for Yandex Alice Station to process voice commands. Yandex can only send requests to publicly available Webhooks. So that nodejs API for Yandex Station can be deployed as a Google Cloud function, which then updates a command file in the Cloud Storage. CloudCommandReader reads the blob every second to get a command.
- Alternatively, there is a php API for Alice station, which does the same, but can be deployed to a cheaper shared hosting service.
On the Raspberry PI server side there is a background service app running, which constantly pulls a Cloud Storage file for the new command. Furthermore, there is only one instance of a listener. It turned out, that simple php script running on a local virtual hosting provider is even cheaper. There should be other simple options to publish a command online like telegram bot or something else.
Todo: make an authenticated dialog for Alice station.