simpleHomeSwitch (sHS)
That's Home Automation over Internet
and Local WiFi with a Webbrowser
Mesh Nodes Network with IoT modules

The problem with my previous NewHomeSwitch project
A ESP8266 Wi-Fi Server is limited to maximal four simultaneous connections, and sometimes old connections are still registered. One server with maximal two IoT Slaves and a Web browser Slave is possible. No problem there is a painlessMesh library from BlackEdder ;-) it is perfect to solve the connection problem. But... a ESP8266 Wi-Fi Mesh Network, or actually more an Wireless ad-hoc network, can't connect to a Local Wi-Fi Home Network. So, first log in on a Node with WebSocket and then, only local, communicate through a Web browser. That is still tricky, limited, and not my thing.

My solution
A combination of three different communication protocols (red: the Node ID)

  1. (IoT WS) WebSocket Server <-> Web browser WebSocket Client (browsers WB).
    + SoftwareSerial (115200 baud) HC-05 Serial Bluetooth Master.
    (or: wired SoftwareSerial to IoT 00)
    h
    The WebSocket Server works in Wi-Fi modes with:
     - WLAN HTML5 Browser Client(s).
     - Internet HTML5 Browser Client(s).
    The WebSocket Server must have a static IP.
  2. (IoT 00) SoftwareSerial (115200 baud) HC-05 Serial Bluetooth Slave.
    (or: wired SoftwareSerial to IoT WS)

    + Mesh Wi-Fi ad-hoc Network Node.
  3. (IoT 01-98) Mesh Wi-Fi ad-hoc Network Nodes.

It's looks complicated but is yet simple, very cheap and works fine.
All he Nodes, included WS and 00, can be equipped with your own functions and hardware. Included in the download:
NTP and RTC time - KaKu (CoCo) 433MHz radio transmitter - Sunrise and Sunset - DST/Summertime - DS18B20 temperature - BH1750 light - ADS1115 Hi-Res ADC - Thermistor - Button bridges - ESP8266<->Arduino Nano - Stepper Motor Steps - Stepper Motor Degrees - Sonoff - Publish (replace for (Not)AtHome).
All these options can be activated with compiler directive switches.
Each node may, independently of the other nodes, automatically run commands that are stored in a private Node SPIFF-simpleDatabase.

You can combine two, or more, Fritzing modules to one Node. By example "Sun Screen":
Node01 with RTC_DS3231, Temp_Lux and Button_bridge (change D3-pin to a free D-pin).

Unfortunately
Wi-Fi OTA upload on Mesh Nodes is not possible by the aforementioned reasons.
But... HardwareSerial Bluetooth OTA is a good alternative. With HardwareSerial Bluetooth is it also possible to use a (Arduino or Termite) serial monitor to get OTA (debug) information from the Mesh Nodes.
(HC-05 Serial Bluetooth: Windows and Android only)

Sonoff 4 pins header, ESP8266-nn 8 pins header.           Sonoff Bluetooth OTA debug information.
(as Fritzing included) You can use one Serial Bluetooth HC-05 module for all the Nodes.
Setup "Serial Bluetooth HC-05" is included as helper in the sHS library.

Internet access:
Set Server Port Forwarding in your Router for Internet Browser Clients.
The router must have a static IP, ask your provider.
What is my (yours of course) IP address? Get it from: http://kendziorra.nl/mijnip.php.
Router settings how-to:
- Active: ON
- Service Name : sHS (or ???)
- WAN Interface : ETHWAN (or ???)
- WAN IP : (empty)
- Trigger Start Port : 8080
- End Port : 8080
- Translation Start Port : 8080
- Translation End Port : 8080
- Server IP Address : 192.168.1.110 (the static local station IP of your sHS WebSocket Server)
- Protocol : TCP/UDP

Internet test:
In webbrowser address bar type your-IP:8080.
If Port Forwarding settings are correct then the sHS-Server will reply with:

Possible use of simpleHomeSwitch Nodes
The Nodes action parameters can be set with a WebSocket capable Web browser. The Nodes testing once per minute if actions are needed.
simpleHomeSwitch use a UTC/GMT UNIX Time Stamp. And of course: The Local Time, Sunrise/set and Summertime/DST are based on your location and rules.
Example parameters: Local time and *C or *F. Sunrise/Sunset Time "Offset", for both a positive or negative value.

D and A pins
Web browser and Nodes can
  - set: D-pin LOW/HIGH or pinMode INPUT/OUTPUT/INPUT_PULLUP
  - get: D-pin LOW/HIGH or A-pin values
on another Node.
Also useful to operate a node with a (Webbrowser)App.

Helpers and Nodes available in this library
Helpers:

Nodes simpleHomeSwitch template:
Open the template as an Arduino example file and set the compiler directives to the NodeID type "WS", "00" or "01" to max. "98".
A Node must have a unique ID. Nodes "WS" with "00" are the minimum configuration.

There is also a "very basic" HTML UI, ID "WB", with the associated scripts. It is usable for all the Node functions and commands.
Make your own (graphic) UI and use this as a "How To ...".

Each Node can be set by using a Web browser. Input: Node ID, function, command, a unique key and parameters (command list). These settings are stored in the simpleDatabase on the Node. A record has 30 fields and can hold a lot of data for, whether or not automatic, use. There are eleven modes available, one manual and ten automatic on varied data:
    0:Manual, 1:Time, 2:Lux, 3:Temp, 4:sunRise, 5:sunSet, 6:Sun, 7:Day, 8:Night, 9:Timer, 10:TimeTemp.
A record has a unique KEY, fixed on 4 chars, and hold the unit setups, status and time counters. On Node (Re)Start/Reset the unit(s) are set in the right status. Every minute a check on unit automatic mode 1-10 actions. If a action is done then the unit-KEY-record is updated. If a Node has lost the connection than it works standalone and will try to reestablish the connection.
Typical use: Light on/off, curtains close/open, blinds down/up, relays on/off, Publish (this Node send commands to other nodes. Replace for (Not)Athome), steppers turning left/right and find the home/end position, steppers degrees and find home position, and ... all what you want.
A node can ask another node for values such as time, temperature, light intensity, Pin or whatever. So, if no RTC then the node can get and sync the time from a "ask Node(nn) list". There is also a STOP mode, 0: Active, 1: Pause and 04:00am reset, 2: Stop and wait for revoked.

List of all simple... libraries

Al simple... libraries with "How to use" examples. These libraries are also to use in other applications.
The abbreviation "...Ms" stands for UNIX Time Stamp and milliseconds (10 digits long and a 13 digits string).
All the simpleHomeSwitch Nodes can use these simple... libraries.
A Mesh Node without RTC time use the TimeMs library and sync the time, on start and interval delay, by asking another Node.

Hint: Show Analog output (A-pin, ADS1115, Thermistor, ...sensors)
Create a HTML JavaScript web browser App with a chart from Google Charts.
Use function 3, command 3 in a time loop, with NodeID and record Key, and get the required values to update the Chart.

(see my Luxe Sous-vide project and Simple Sous-vide project with a DS18B20 sensor and PID control)

How to create or change a record
Open simpleHomeSwitch.html and click the sHS commands list button.
All the function 1 commands create a new record with default values (simpleDB.ino->void newRecord()).
   A new record is added or, if the key already exists, just overwritten (no warning!).
All the function 2 commands overwrite only the respective default values.

Example set on Node03 a record key to switch pin D3 every day: 080:00 ON and 20:30 OFF.
toID func cmd data1 data2 data3 data4
 03    1   3  pump    D3    -1        set the key and pin D2 (data3: -1? see "Explanation Pin setup")
 03    2   1  pump 08:00 20:30        ON 8:00, OFF 20:30
 03    2   0  pump     1              set auto time 1 action mode TIME
 03    0   0  pump   0/1              manual OFF/ON (Web browser or App)

Example set on NodeWS a record key to switch OLD KaKu (CoCo) every day on sunRISE or sunSET.
toID func cmd data1 data2 data3 data4
 WS    1   0  lamp 118124   322        set the key, KaKu code and KaKu period
 WS    2   1  lamp  06:30 23:00        mode 4: ON time (OFF=sunrise+offset), mode5:(ON=sunSet-offset) OFF time
 WS    2   5  lamp     15    15        mode 4: +offset sunRise, mode5: -offset sunSet
 WS    2   0  lamp 4 or 5              set auto time action, mode 4: sunRISE or mode 5: sunSET
 WS    0   0  lamp    0/1              manual OFF/ON (Web browser or App)

Example set on Node04 a record key to switch a boiler on time and temperature.
By example: Sonoff TH16 WiFi Smart Switch + Sonoff TH Sensor DS18B20
ON:  if TimeON&&TempON
OFF: if TimeOFF||TempOff
toID func cmd data1 data2 data3 data4
 04    1   3  blr1     D6    -1        set the key and (Sonoff)relay pin
 04    2   1  blr1  06:30 23:00        mode 10: ON time, mode10:OFF time
 04    2   4  blr1     58    62        mode 10: ON temp, mode10:OFF temp
 04    2   0  blr1     10              set auto TimeTemp action, mode 10
 04    0   0  blr1    0/1              manual OFF/ON (Web browser or App)

Example set on Node00 a record key to switch a sun screen on room temperature and luminance with button bridge optocouplers.
DOWN: if Lux>=LuxDOWN && Temp>=TempDOWN && YoYo
UP: if Lux<=BadWeatherLux
UP: if (Lux<LuxUP || Temp<TempUP) && YoYo Bridged remote control buttons from Wireless Tubular Sun Screen Motor. toID func cmd data1 data2 data3 data4 00 1 3 scrn D3 D4 set the key, DOWN D3 and UP D4 optocoupler pins 00 2 3 scrn 380 60 LuxDOWN 380, LuxUP 60 (room luminance) 00 2 4 scrn 21.5 21 TempDOWN 21.5, TempUP 21 (room temperature, default *C or set *F) 00 2 6 scrn 10 delay time 10 minutes to prevent the Yo-Yo effect 00 2 7 scrn 4 500 repetitions 4, delay 500 Millis (two momentary button actions) 00 2 8 scrn 30 BadWeatherLux 30 (quick UP) 00 2 0 scrn 6 set auto sun 6 action mode SUN 00 0 0 scrn 1/0 manual DOWN/UP (Web browser or App)

Explanation Pin setup: function 1, command 3, and function 2, command 7
(LED can have VCC on Anode then: Pin HIGH = OFF, Pin LOW = ON)
One Pin mode, Function 1, command 3
  - data2: Pinn On/Off or Down/Up.
  - data3: must set to -1.
One Pin Momentary mode, function 1, command 3
  - data2: Pinn. Momentary with a even number of delayed repetitions.
  - data3: must set as data2-Pinn, 1-On/Down or 0-Off/Up has the same result.
     Use this Two Pins mode only with a even number of repetitions.
Two Pins Momentary mode, function 1, command 3
  - data2: Pin1n On/Down. Momentary with a even number of delayed repetitions.
  - data3: Pin2n Off/Up. Momentary with a even number of delayed repetitions.
  Use this Two Pins mode only with a even number of repetitions.
  (very useful to bridge remote control buttons with optocouplers)
Repetitions, function 2, command 7
  - data2: number of repetitions
  - data3: delay time in Millis between the repetitions.
  One repetition: HIGH
  Two repetitions: HIGH->Delay->LOW
  Three repetitions: HIGH->Delay->LOW->Delay->HIGH
  Four repetitions: HIGH->Delay->LOW->Delay->HIGH->Delay->LOW (default values: 4 reps and 500ms)
     and so on... So even repetitions ends with LOW and odd repetitions ends with HIGH.
  This is very useful with bridged remote control buttons by Wireless Tubular Motors: Two Pins, Momentary, Repetitions: 4, Duration: 500.

List of used libraries

https://github.com/esp8266/Arduino
  ESP8266WiFi
  WiFiUdp
  SPI
  SD
  FS
  Wire
  SoftwareSerial
https://github.com/milesburton
  DallasTemperature
https://github.com/Links2004
  WebSocketsServer
https://github.com/PaulStoffregen
  OneWire 
  TimeLib
                                                
##### Included in SimpleHomeSwitch library #####
https://gitlab.com/BlackEdder
  painlessMesh          // Do not download!!! It's included in sHS
http://kendziorra.nl
  kaku                  // A simple KaKu (CoCo) 433MHz library
  NtpMs                 // A simple NTP Time library incl. millis timestamp$
  RtcMs                 // A simple DS3231 RTC Time library incl. millis timestamp$
  TimeMs                // A simple Time library, use syncTime from a other Node, incl. millis timestamp$
  simpleDB              // A simple database library
  simpleTimers          // A simple alternative milliseconds timer(s) library
  simpleTempDS18B20     // A simple single DS18B20 Temp library
  simpleLuxBH1750       // A simple BH1750 Lux library
  simpleAdcADS1115      // A simple 0-15 ports ADC library
  simpleThermistor      // A simple Thermistor library
  simpleStepperSteps    // A simple stepper library
  simpleDegreesSteps    // A simple degrees stepper library
  simpleSummerTimeDST   // A simple Summertime/DST library
  simpleSunRiseSet      // A simple SunRise/Set library