mirror of
https://github.com/alexhopeoconnor/arduino-home-assistant.git
synced 2026-10-04 02:48:13 +10:00
* hide onMqttConnected and onMqttMessage methods in BaseDeviceType class * bump up version * replace HAComponentName with initialization inside constructor * add missing documentation to begin() method * add support for availability in BaseDeviceType * add support for availability in HABinarySensor, HASensor and HASwitch * move serialization to separate class * wip: DeviceTypeSerializer * update device types * refactored all devices types to use common serializer * update examples * update availability example README.md * bugs fixes * fix build for NodeMCU * cleanup
Home Assistant availability example
This example shows how to use "availability" feature of the Home Assistant. It's supported only by following device types:
- Binary sensor
- Sensor
- Switch
Initialization and usage
Availability feature is turned off by default. In order to turn it on for the specific
sensor/switch you need to set initial state of the unit by calling setAvailability method.
Example:
...
HABinarySensor sensor("input", "door", true, mqtt);
void setup() {
// ...
// method must be called before `mqtt.begin(...)`
sensor.setAvailability(false); // offline
mqtt.begin(BROKER_ADDR);
}
...
After availability is set for the very first time you can call setAvailability in any time.
Each time the method is called, the device will publish MQTT message to the broker.