This ESP8266 device is intended as an implementation example of YAHNC libs
SWECS is an advanced Switch made up 3 Homie Nodes basing on YAHNC lib:
SwitchNode
aka CommandButtonNode
aka External ControlBinarySensorNode
aka External State (optional)
This switch can be controlled remotely thanks to MQTT (SwitchNode
), locally by a physical switch (ButtonNode
) and it can use an optional External State, directly from the device (BinarySensorNode
).
SWECS was designed to control the "wall light" (like Shelly or Sonoff) with a pre-existing system (bulb, switch/button, relay, wires), but can be also used for other devices (eg fans, gate...). The External State should be used when we can't by-pass the device main switch, and we want still use it normally.
tip: In presence of a step relay and/or you are interested to device consumption (ie Ampere/Watt) see SWECS-P
Compile and upload with PlatformIO:
pio run --environment callback --target upload
When EXT_STATE
(build flag) is not set, the device state is manage internally and taken it from the SwitchNode
output, otherwise is taken from the BinarySensorNode
and published under /state/state
topic.
The External Control can be:
- Toggle: switch change => device state change
- Impulsive: button push => device state change
- Follow: switch On (Off) => device state On (Off)
and can be set as HomieSetting
: externalControlMode
External Control have some predefined "macro/gesture".
eg hold button more than 1 second and release, set device timeout proportional to press duration (for more info see func extControlHandler()
)
Very similar to SWECS, add only two features:
- Power meter with the use of an ACS7128 (
ACS7128Node
extendAdcNode
) - Impulsive support for
SwitchNode
(aka Command), useful for step relay
Compile and upload with PlatformIO:
pio run --environment inheritance --target upload
The purpose of SWECS-P is to show a different implementation method, where instead of callback is used inheritance way.
An example is the class AdvSwitchNode that extends SwitchNode
and BinarySensorNode
through a multiple inheritance (and causing a diamond problem). Thanks to this approach we can create a single new HomieNode
with some advantage, for example have a single topic /switch
with a /command
and /state
subtopic.
note: the added features can be also implemented to SWECS by "callback way".