/ESPlights

Multi channel WiFi mains voltage controller software & hardware based on the ESP8266.

Primary LanguageC++GNU General Public License v3.0GPL-3.0

ESPlights

Software for the 16(8 or 4) channel mains controller provided by 3DStar.ro

Features

  • secure MQTT connection possible, Let's Ecrypt CA cetificate already loaded
  • topic structure for multiple buildings (locations) control: location/device_type/device_name/
  • lights status saved and recovered on restart from MQTT server
  • on / off / toggle commands for each light channel, simple channel and timed channel
  • shutter/blinds control with up/stop/down/stop commands and max timeout per shutter
  • current shutter status topic based on timeout for end of travel determination
  • timed channels for bathroom ventilators, door access control, gates control, etc. with max timeout per channel (timeout freely adjustable from milliseconds to days)
  • simple channels, they work like lights channels but status is lost on restart
  • separate status topic for each channel to show current channel state
  • main and backup WiFi connections
  • secured, no access point is presented in case both WiFi connections are unavailable
  • web interface for setup, can be disabled
  • extra information on device status topic: type, ID, supply voltage, AP SSID, AP RSSI, AP mac, etc.
  • ESP-Now bridge functionality, to relay JSON ESP-Now messages to MQTT (a second ESP8266 with ESP-Now gateway firmware is needed)

Hardware

Roll your own or get one from 3DStar shop in PCB, kit (PCB + components), SMD kit (PCB with soldered SMD components + bags of through hole components) or fully assembled form.

The ESP-01 / ESP-01S from AI Thinker is used to control a IO expander. Different types of IO expanders are supported: MCP23017 for 16 channels, PCA9557 for 8 channels and PCA9536 for 4 channels. On each channel there are 1 optotriac and 1 triac to control mains powered lights or other low powered devices. Each channel can switch up to around 300W without any special cooling.

The controller must be placed after a 10A circuit breaker so total power should not exceed 2300W in Europe. Channels up to 300W can be controlled if maximum total power draw is respected. These informations are general guidelines, please conform to your local regulations! If all channels are used equally, this corresponds to about 137W per channel, enough for 9 x 15W LED bulbs per each channel or a total of 144 15W LED bulbs. The controller should cover most houses and apartments without problems, leaving a few extra channels for shutters/blinds, doors/gates, irrigation or other controls. The number of boards you can use is unlimited so you can controll all your mains powered small devices.

Box

In the hardware folder are STL files for printing a DIN rail box. For 16 channels and 8 channels version print:

  • 1 x box.stl
  • 1 x cover.stl (EN & RO versions)
  • 3 x DIN mount.stl

For the 4 channel version just 2 x DIN mount are needed.

The holes are for 2x10 mm wood screws. 6 are needed for the DIN rail mounts, 4 for the PCB and 4 for the cover. Cover screws can be longer than 10mm. ABS is recommended as printing material. Check your local regulations.

Build & upload

  • there are 2 methods:
    • clone, build & upload (PlatformIO is recommended for automatic library management)
    • download bin file, flash to ESP

Setup

On the first powerup a WiFi access point is presented. If using the default configuration, it is called "ESPlights_XXXXXX". Default password is abcd1234. Connect to it and you should arrive at the configuration page. If you are not automagically redirected (it's called a sign in page) then you can point your browser to http://192.168.10.1/

  • [Device] menu will allow you to change LOC, TIP, NAME variables (these make up the MQTT topic), update URL (if you want to set up your own server for updates), MQTT heartbeat on/off and period and if the webserver should be started.
  • [WIFI] menu will let you scan for WiFi networks and set up credentials for both networks. The second one is recommended to be set to your phone's hotspot in case you change the main Wifi network credentials.
  • [MQTT] menu is used to set up your MQTT connection
  • [Light channels] - menu to configure the channels used for lights. Their status is saved and retreived on startup from the MQTT broker.
  • [Normal channels] - same as light channels but their status is not saved.
  • [Shutter channels] - if you want to control shutters, here you can define them. Two device channels are needed for each shutter channel. Timeout is needed to kill power after a certain time but also to indicate the end of travel. If timeout is reached the shutter channel will indicate the last direction. If timeout is not reached the shutter channel will indicate a 0 value.
  • [Timed channels] - these channels will have a timeout assiged to them after activation. Good for lights under motion sensor control but also manual control. Each channel has its own timer ranging from 1ms to a few days. Because of this large selection these channels can also be used for door access control, gate opening, bathroom ventilators, etc. A light or normal command on these channels will stop the timer and give control to light or normal channel.
  • [Update firmware] - self explanatory, you can use your own server (defined under Device menu) or the official release channel as defined in the firmware.
  • [Erase settings] menu will delete all configuration files stored on the ESP but will not restart the device. Menus will still show the current settings from active memory. Use this trick to save at least the Wifi settings then restart. If you restart without saving WiFi credentials then it will behave like a new device.
  • [Restart] - reboots the device
  • [System information] - shows some infos about the device

Usage

  • MQTT topic: LOC/TIP/NAME where LOC, TIP & NAME are user defined. What follows are possible suffixes and they will be added after the mqtt topic.

  • command topic: /cmnd/...

    • /update: perform OTA update

    • /reset: restart ESP device

    • /all: with a '0' payload will deactivate all channels. With a '1' or greater payload will activate all channels IF all channels are lights (simple and timed can coexist) and there are no shutters defined.

    • /cmnd/lX: lights control. X is the light channel number. Payload can be 0 = off, 1 = on, 2 = toggle

    • /cmnd/nX: simple/normal control. X is the number. Payload can be 0 = off, 1 = on, 2 = toggle

    • /cmnd/sX: shutter control. X is the shutter number. Payload can be 0 = stop, 1 = up, 2 = down. Repeating UP/DOWN also stops the shutters.

    • /cmnd/tX: timed channel control. X is the timed channel number. Payload can be 0 = off, 1 = on, 2 = toggle. Light, simple, shutter and timed channel numbers are different from device channel numbers. For example if you set up 6 light channels, you can assign them to device channels 6, 8, 10, 12, 14 and 16. Shutters take up 2 device channels each (1 for up movement and 1 for down movement).

    • /cmnd/saved: saves the current lights status

  • channel status topic: /channel/X where X is the device channel number. Payload will be 0 for OFF and 1 for ON. It is updated by the ESP after processing commands, statuses are sent with retain flag.

  • shutter status topic: /shutter/X where X is the shutter number. It holds the current shutter positions. Payload will be 0 for unknown/partly open, 1 for DOWN, 2 for UP.

  • ESP bridge topic: /espnow will be used to relay the received ESP-Now messages. Messages must be in JSON format as the software looks for opening and closing brackets to relay a full message.

  • status topic: /stat where the ESP sends periodic updates (heartbeats) with useful information.

  • will topic: /will Payload is 1 when device is ON and 0 when powered OFF

Libraries

PCB example