Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 114 additions & 7 deletions docs/en/zigbee/ep_binary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ About

The ``ZigbeeBinary`` class provides an endpoint for binary input/output sensors in Zigbee networks. This endpoint implements the Zigbee Home Automation (HA) standard for binary sensors, supporting various application types for HVAC, security, and general binary sensing.
Binary Input (BI) is meant to be used for sensors that provide a binary signal, such as door/window sensors, motion detectors, etc. to be sent to the network.

.. note::

Binary Output (BO) is not supported yet.
Binary Output (BO) is used for controlling binary devices such as relays, switches, or actuators that can be turned on/off remotely.

API Reference
-------------
Expand Down Expand Up @@ -63,6 +60,33 @@ Security Application Types
#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_HEAT_DETECTION 0x01000008
#define BINARY_INPUT_APPLICATION_TYPE_SECURITY_OTHER 0x0100FFFF

Binary Output Application Types
*******************************

HVAC Application Types
^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: arduino

#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_BOILER 0x00000003
#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_CHILLER 0x0000000D
#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_FAN 0x00000022
#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_HEATING_VALVE 0x0000002C
#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_HUMIDIFIER 0x00000033
#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_PREHEAT 0x00000034
#define BINARY_OUTPUT_APPLICATION_TYPE_HVAC_OTHER 0x0000FFFF

Security Application Types
^^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block:: arduino

#define BINARY_OUTPUT_APPLICATION_TYPE_SECURITY_ARM_DISARM_COMMAND 0x01000000
#define BINARY_OUTPUT_APPLICATION_TYPE_SECURITY_OCCUPANCY_CONTROL 0x01000001
#define BINARY_OUTPUT_APPLICATION_TYPE_SECURITY_ENABLE_CONTROL 0x01000002
#define BINARY_OUTPUT_APPLICATION_TYPE_SECURITY_ACCESS_CONTROL 0x01000003
#define BINARY_OUTPUT_APPLICATION_TYPE_SECURITY_OTHER 0x0100FFFF

API Methods
***********

Expand Down Expand Up @@ -127,11 +151,94 @@ Manually reports the current binary input value.

This function will return ``true`` if successful, ``false`` otherwise.

addBinaryOutput
^^^^^^^^^^^^^^^

Adds a binary output cluster to the endpoint.

.. code-block:: arduino

bool addBinaryOutput();

This function will return ``true`` if successful, ``false`` otherwise.

setBinaryOutputApplication
^^^^^^^^^^^^^^^^^^^^^^^^^^

Sets the application type for the binary output.

.. code-block:: arduino

bool setBinaryOutputApplication(uint32_t application_type);

* ``application_type`` - Application type constant (see Binary Output Application Types above)

This function will return ``true`` if successful, ``false`` otherwise.

setBinaryOutputDescription
^^^^^^^^^^^^^^^^^^^^^^^^^^

Sets a custom description for the binary output.

.. code-block:: arduino

bool setBinaryOutputDescription(const char *description);

* ``description`` - Description string

This function will return ``true`` if successful, ``false`` otherwise.

onBinaryOutputChange
^^^^^^^^^^^^^^^^^^^^^

Sets a callback function to be called when the binary output value changes.

.. code-block:: arduino

void onBinaryOutputChange(void (*callback)(bool binary_output));

* ``callback`` - Function pointer to callback that receives the new binary output value

setBinaryOutput
^^^^^^^^^^^^^^^

Sets the binary output value.

.. code-block:: arduino

bool setBinaryOutput(bool output);

* ``output`` - Binary value (true/false)

This function will return ``true`` if successful, ``false`` otherwise.

getBinaryOutput
^^^^^^^^^^^^^^^

Gets the current binary output value.

.. code-block:: arduino

bool getBinaryOutput();

This function returns the current binary output state.

reportBinaryOutput
^^^^^^^^^^^^^^^^^^

Manually reports the current binary output value.

.. code-block:: arduino

bool reportBinaryOutput();

This function will return ``true`` if successful, ``false`` otherwise.

Example
-------

Binary Input Implementation
****************************
Binary Input and Output Implementation
**************************************

.. literalinclude:: ../../../libraries/Zigbee/examples/Zigbee_Binary_Input/Zigbee_Binary_Input.ino
.. literalinclude:: ../../../libraries/Zigbee/examples/Zigbee_Binary_Input_Output/Zigbee_Binary_Input_Output.ino
:language: arduino
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Arduino-ESP32 Zigbee Binary Input Example
# Arduino-ESP32 Zigbee Binary Input Output Example

This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) binary input device with two different applications: HVAC fan status and security zone armed status.
This example shows how to configure the Zigbee end device and use it as a Home Automation (HA) binary input/output device with multiple applications: HVAC fan status/control, security zone armed status, and HVAC humidifier control.

# Supported Targets

Expand All @@ -9,12 +9,17 @@ Currently, this example supports the following targets.
| Supported Targets | ESP32-C6 | ESP32-H2 |
| ----------------- | -------- | -------- |

## Binary Input Functions

* The example implements two binary inputs:
- HVAC Fan Status: Reports the current state of a fan
- Security Zone Armed: Reports the armed state of a security zone
* By clicking the button (BOOT) on this board, it will toggle both binary inputs and immediately send a report of their states to the network.
## Binary Input/Output Functions

* The example implements three binary devices:
- **Binary Fan Device (Endpoint 1)**:
- Binary Input: HVAC Fan Status - Reports the current state of a fan
- Binary Output: HVAC Fan - Controls the fan switch with callback function
- **Binary Zone Device (Endpoint 2)**:
- Binary Input: Security Zone Armed - Reports the armed state of a security zone
- **Binary Humidifier Device (Endpoint 3)**:
- Binary Output: HVAC Humidifier - Controls the humidifier switch with callback function
* By clicking the button (BOOT) on this board, it will toggle all binary inputs/outputs and immediately send a report of their states to the network.
* Holding the button for more than 3 seconds will trigger a factory reset of the Zigbee device.

## Hardware Required
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
// limitations under the License.

/**
* @brief This example demonstrates Zigbee binary input device.
* @brief This example demonstrates Zigbee binary input/output device.
*
* The example demonstrates how to use Zigbee library to create an end device binary sensor device.
* The example demonstrates how to use Zigbee library to create an end device binary sensor/switch device.
*
* Proper Zigbee mode must be selected in Tools->Zigbee mode
* and also the correct partition scheme must be selected in Tools->Partition Scheme.
Expand All @@ -34,13 +34,24 @@
/* Zigbee binary sensor device configuration */
#define BINARY_DEVICE_ENDPOINT_NUMBER 1

uint8_t binaryPin = A0;
uint8_t button = BOOT_PIN;

ZigbeeBinary zbBinaryFan = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER);
ZigbeeBinary zbBinaryZone = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER + 1);
ZigbeeBinary zbBinaryHumidifier = ZigbeeBinary(BINARY_DEVICE_ENDPOINT_NUMBER + 2);

bool binaryStatus = false;
bool zoneStatus = false;

void fanSwitch(bool state) {
Serial.println("Fan switch changed to: " + String(state));
// Switch Fan status input signalling the fan status has changed
zbBinaryFan.setBinaryInput(state);
zbBinaryFan.reportBinaryInput();
}

void humidifierSwitch(bool state) {
Serial.println("Humidifier switch changed to: " + String(state));
}

void setup() {
Serial.begin(115200);
Expand All @@ -55,19 +66,33 @@ void setup() {
// Optional: set Zigbee device name and model
zbBinaryFan.setManufacturerAndModel("Espressif", "ZigbeeBinarySensor");

// Set up binary fan status input (HVAC)
// Set up binary fan status input + switch output (HVAC)
zbBinaryFan.addBinaryInput();
zbBinaryFan.setBinaryInputApplication(BINARY_INPUT_APPLICATION_TYPE_HVAC_FAN_STATUS);
zbBinaryFan.setBinaryInputDescription("Fan Status");

zbBinaryFan.addBinaryOutput();
zbBinaryFan.setBinaryOutputApplication(BINARY_OUTPUT_APPLICATION_TYPE_HVAC_FAN);
zbBinaryFan.setBinaryOutputDescription("Fan Switch");

zbBinaryFan.onBinaryOutputChange(fanSwitch);

// Set up binary zone armed input (Security)
zbBinaryZone.addBinaryInput();
zbBinaryZone.setBinaryInputApplication(BINARY_INPUT_APPLICATION_TYPE_SECURITY_ZONE_ARMED);
zbBinaryZone.setBinaryInputDescription("Zone Armed");

// Set up binary humidifier output (HVAC)
zbBinaryHumidifier.addBinaryOutput();
zbBinaryHumidifier.setBinaryOutputApplication(BINARY_OUTPUT_APPLICATION_TYPE_HVAC_HUMIDIFIER);
zbBinaryHumidifier.setBinaryOutputDescription("Humidifier Switch");

zbBinaryHumidifier.onBinaryOutputChange(humidifierSwitch);

// Add endpoints to Zigbee Core
Zigbee.addEndpoint(&zbBinaryFan);
Zigbee.addEndpoint(&zbBinaryZone);
Zigbee.addEndpoint(&zbBinaryHumidifier);

Serial.println("Starting Zigbee...");
// When all EPs are registered, start Zigbee in End Device mode
Expand Down Expand Up @@ -101,12 +126,19 @@ void loop() {
Zigbee.factoryReset();
}
}
// Toggle binary input
binaryStatus = !binaryStatus;
zbBinaryFan.setBinaryInput(binaryStatus);
zbBinaryZone.setBinaryInput(binaryStatus);
zbBinaryFan.reportBinaryInput();

// Toggle fan
zbBinaryFan.setBinaryOutput(!zbBinaryFan.getBinaryOutput());
zbBinaryFan.reportBinaryOutput();

// Toggle zone
zoneStatus = !zoneStatus;
zbBinaryZone.setBinaryInput(zoneStatus);
zbBinaryZone.reportBinaryInput();

// Toggle humidifier
zbBinaryHumidifier.setBinaryOutput(!zbBinaryHumidifier.getBinaryOutput());
zbBinaryHumidifier.reportBinaryOutput();
}
delay(100);
}
Loading
Loading