DIY Smart Light Control System

by scanos in Circuits > Raspberry Pi

407 Views, 0 Favorites, 0 Comments

DIY Smart Light Control System

witty_config4.png

This is a system which controls Tasmota based smart lights, sonoffs, Witty Cloud etc through a single web page. The app sits on a Raspberry Pi on the same LAN as all the sensors which it controls. The app reads the status of all the tasmota devices and permits them to be switched on and off, as a group or individually, from a web page.

This is a very low cost simple installation which requires a minimal equipment set, basically a Raspberry Pi and sonoff devices. No external gateways, sensor or add ons are required. For example, the Sonoff switches were less than 6 pounds, the Witty Cloud devices circa 3 pounds each and the Raspberry Pi less than 20 pounds.

Detailed instructions are provided on https://github.com/scanos/Xmas-Lights-Control-Centre/blob/main/lights_single_Witty/install_README.md

Supplies

1. Raspberry Pi preinstalled

Assumptions That you - Have a Raspberry Pi and you can install on it the latest Jessie image.( Hint, see

https://www.raspberrypi.org/documentation/installa...

- Know how to navigate Linux on your Raspberry pi to make file permission changes. - and Apache 2.

2. Have various Tasmota based lights or switches with lights, and that you know how to flash the devices with Tasmota firmware. (Hint,see https://github.com/tasmota/tasmotizer)

3. LED strips, or individual LEDs (use 1k resistor if latter)

4. LAN environment

5. Small breadboard and Dupont cables to connect LED pins to GPIO pins of Witty or other Tasmota devices.

1. ​Install Bash Scripts and Html Files..1

witty_config.png

The first step is to install jq which parses json data from the Tasmota devices

1. sudo apt-get install jq

2. Next, create a directory - e.g. light under /usr/lib/cgi-bin (the root cgi-bin directory). CD to this directory and clone this repository using git (sudo apt-get install git-core ,if not already installed)

i.e. sudo git clone https://github.com/scanos/Xmas-Lights-Control-Cen...

Next, move the files WITHIN THE SUB DIRECTORY -of the downloaded git repository - Xmas-Lights-Control-Centre/lights_single_Witty/ to your new cgi-bin directory - /usr/lib/cgi-bin/light --

Set the permissions as shown below:

-rwxr-xr-x 1 www-data www-data 2547 Feb 14 14:40 lights.html

-rwxr-xr-x 1 www-data www-data 1830 Feb 14 13:59 lights.sh

-rwxr-xr-x 1 www-data www-data 167 Feb 14 11:13 lights1.html

-rwxr-xr-x 1 www-data www-data 66 Feb 14 13:54 lights_array

-rwxr-xr-x 1 www-data www-data 1063 Feb 14 13:42 lights_change.sh

-rwxr-xr-x 1 www-data www-data 966 Feb 13 12:30 lights_toggle.sh

3. Configure the Witty Cloud

Find the ip addresses and description of your Tasmota devices (You can find this from your router page) and configure the Tasmota GPIO pins as shown in the picture above. When you go to the main menu of the Witty devices, you should see six switches.

You may need to run the command SetOption68 1

See https://tasmota.github.io/docs/Lights

2. ​Install Bash Scripts and Html Files..2

After you've set up the switches replace the following line in lights_array with your specific details. Use nano to edit the file......sudo nano lights_array. Note the format is -

description1 ipaddress1 POWERNUM with a space between each entry, also avoid spaces in the descriptor fields e.g.bell_tower 192.168.1.239 POWER5 small_tower 192.168.1.239 POWER6

Next connect your LEDs to respective pins, by connecting the + wire of the LED to the respective pin on the Witty e.g. GPIO5 is POWER4, and the - wire of the LED to the ground pin of the Witty.

You may need to use a breadboard as an intermediary to connect the - cables. Note that when you toggle POWER4 from the main Witty page it will illuminate the LED connected to GPIO5. Again, for higher voltage / current devices you will need to connect the witty pins to a transistor switch. After this, you should be able to access the application from a web browser. For example, the host name of my Raspberry Pi is http://pi92c5/cgi-bin/lights/lights.sh You should replace pi92c5 with the host name or IP address of your Raspberry Pi.

3. Considerations / Security

This is a prototype system which is for teaching purposes only and not designed for use on the internet.

It should only be used on a secure LAN and you should not use it to control critical systems.

You need to be electrically competent when working even with low voltage.

That said, it gives you an opportunity to learn about Apache, Bash, HTML, CCS/Bootstrap, Javascript and Tasmota etc.

More Security stuff

This instructable is intended to introduce you to Tasmota commands. It should not be used in production areas unless you strength the security around the configuration. The steps to do this include
1. Use a strong web admin password on the Witty / Tasmota device (From the Witty web interface go to the menu Configuration/Configure Other/ then set and enable the Web Admin Password To use the web admin password in your scripts you will need to use the following format curl -X GET --proto-default http "http://192.168.X.XXX/cm?user=admin&password=very_strong_password&cmnd=Rule1%20On%20switch3%20state=OFF%20do%20dimmer%20100%20endon" Obviously you have to remember the password.

2. Do not use on a LAN which has a sensitive data. Consider partitioning the LAN for your IOT devices and use a DMZ.

3. Enable HTTPS on your Tasmota devices.

4. Ensure your scripts are OWASP compliant

5. etc