
Practically in every discussion of the next implementation of home automation, the following question arises - “I want one button, so that when I go home I press it and everything turns off / turns into power saving mode”.
Well, as one famous character said, the challenge is accepted.
As I told you, I use RS485 and MODBUS. The button can be made both by master and slave. And each solution has its drawbacks. If the button acts as a master, then two master devices are obtained in the instrument network; if it is a slave, the delay between pressing and starting the execution of commands will be about a minute (the frequency of polling the controllers with the server part). I was not satisfied with both solutions, so a third one was found - the button will work through the server part. This option is also not without flaws, for example, in the absence of communication with the server, it simply will not work, but since this Big Red Button performs an auxiliary function (the light can be turned off with ordinary switches), it was decided to put up with it. Also decided instead of one button to make 4, or rather from one to four. If you can turn off everything - then why not be able to turn everything on?
So, the hardware
We take the pushbutton post, the transparent buttons and throw out all unnecessary.
')

From the transparent buttons we remove the native switches and glue the others. Why this farm? In order to be able to add the backlight LEDs (initially, the buttons without the backlight, although they have a transparent pressure part), and for another simple reason, they did not fit the height of this case.

Used Wi-Fi module ESP8266-03 and PIC12F1840. Since simultaneous pressing of several buttons is not planned - they are connected through a resistor divider to the input of the ADC, which made it possible to get by with one output of the MC. The LEDs are connected by two to one output - with a high level, one is lit, with a low - the second, when switching the output to the input - both are turned off. Diode bridge, stabilizer and jumpers - for different power options, reverse, constant or batteries.
We breed, we poison, we collect. Do not forget to add jumpers to hold the MC in reset and transfer the ESP8266 to the firmware mode, since it is inconvenient to solder it. 11-pin connector - power, buttons and LEDs, five-pin - ICSP and UART in combination for firmware and viewing exchange logs.

How it works
When turned on, the device is registered in the home Wi-Fi network, when the button is pressed, the simplest GET request is sent to the server, during processing of which the server script selects the list of controller addresses from the database and writes the required values to the registers. Since the button is also a full-fledged controller with its MODBUS address, the first command in it clears the button pressing flag, and the last sets the end flag of the execution of the command sequence, which is indicated by the LEDs in the buttons. They pressed the button - the LED came on, the first command from the series came on - blinked, the last one came - went out.

Settings console
There can be several devices in the network, the number of buttons in each device varies from one to four, the number of commands is adjustable and, in principle, unlimited. Also in the web interface there is a widget for group operations with the same functionality.
A few words about the ESP8266 themselves. for prototyping I used ESP-01, in the final version - ESP-03. I stitched the latest firmware in them, 01 was working normally, 03 was working when it was first turned on, and later cursing for the dead firmware. As it turned out, a different amount of memory was installed on them, on 01 - 8 Mbit, on 03 - 4 Mbit. But no warnings software for the firmware did not give out, everything was sewed and almost worked. Cured by older firmware from one known site. Also, it is highly desirable to start resetting ESP and AFTER the reset, send a command to disconnect from the access point, and only then do a normal initialization. Sometimes when turned on, the module considered itself already connected to an access point, and even had an IP of 104.111.109. * But of course it did not have access to the network. Also, when reconfiguring the UART for a speed other than the default 115200 - from time to time it would forget these settings.
Links to previous parts: