EnigmaIOT  0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
haBinarySensor.h
Go to the documentation of this file.
1 
9 #ifndef _BINARY_SENSOR_h
10 #define _BINARY_SENSOR_h
11 
12 #include "haEntity.h"
13 
14 #if SUPPORT_HA_DISCOVERY
15 
16 
85 class HABinarySensor : public HAEntity {
86 public:
91  capacity = JSON_OBJECT_SIZE (10) + 250;
92  entityConfig = new DynamicJsonDocument (capacity);
94  (*entityConfig)[ha_device_type] = deviceType;
95  };
96 
101  void setDeviceClass (haBinarySensorClass_t devClass);
102 
108  void setPayloadOn (const char* payload);
109 
115  void setPayloadOff (const char* payload);
116 
122  void setPayloadOn (int payload);
123 
129  void setPayloadOff (int payload);
130 
138  void setValueField (const char* payload);
139 
145  void setValueTemplate (const char* payload);
146 
152  void setOffDelay (uint payload);
153 
154 
164  static size_t getDiscoveryJson (char* buffer, size_t buflen, const char* nodeName, const char* networkName, DynamicJsonDocument* inputJSON);
165 
171  static String deviceClassStr (haBinarySensorClass_t sensorClass);
172 
178  void addExpiration (uint seconds) {
179  if (seconds > 0) {
180  (*entityConfig)[ha_expiration] = seconds;
181  }
182  }
183 
184 
185 };
186 #endif // SUPPORT_HA_DISCOVERY
187 
188 #endif // _BINARY_SENSOR_h
BINARY_SENSOR
@ BINARY_SENSOR
Definition: haEntity.h:56
HAEntity::entityConfig
DynamicJsonDocument * entityConfig
JSON object to be sent to gateway.
Definition: haEntity.h:138
haBinarySensorClass_t
haBinarySensorClass_t
Definition: haEntity.h:73
haEntity.h
Defines an entity for Home Assistant autodiscovery.
HABinarySensor::deviceClassStr
static String deviceClassStr(haBinarySensorClass_t sensorClass)
Gets binary sensor class name from haBinarySensorClass_t https://www.home-assistant....
Definition: haBinarySensor.cpp:142
HAEntity::capacity
size_t capacity
JSON object memory reservation length.
Definition: haEntity.h:134
HABinarySensor::setValueField
void setValueField(const char *payload)
Defines a template that returns a string to be compared to payload_on/payload_off or an empty string,...
Definition: haBinarySensor.cpp:40
HABinarySensor::setValueTemplate
void setValueTemplate(const char *payload)
Defines a template that defines binary sensor value. When setting this you should not call setValueFi...
Definition: haBinarySensor.cpp:46
ha_expiration
constexpr auto ha_expiration
Definition: haEntity.h:29
HABinarySensor
Definition: haBinarySensor.h:85
HABinarySensor::getDiscoveryJson
static size_t getDiscoveryJson(char *buffer, size_t buflen, const char *nodeName, const char *networkName, DynamicJsonDocument *inputJSON)
Allows Gateway to get Home Assistant discovery message using Binary Sensor template.
Definition: haBinarySensor.cpp:78
HABinarySensor::setPayloadOff
void setPayloadOff(const char *payload)
Defines the string that represents the off state. It will be compared to the message in the state_top...
Definition: haBinarySensor.cpp:26
ha_device_type
constexpr auto ha_device_type
Definition: haEntity.h:23
HABinarySensor::addExpiration
void addExpiration(uint seconds)
Defines the number of seconds after the sensor’s state expires, if it’s not updated....
Definition: haBinarySensor.h:178
HAEntity::deviceType
haDeviceType_t deviceType
HomeAssistant entity device type.
Definition: haEntity.h:135
HABinarySensor::setPayloadOn
void setPayloadOn(const char *payload)
Defines the string that represents the on state. It will be compared to the message in the state_topi...
Definition: haBinarySensor.cpp:20
HABinarySensor::setOffDelay
void setOffDelay(uint payload)
For sensors that only send on state updates (like PIRs), this sets a delay in seconds after which the...
Definition: haBinarySensor.cpp:52
HABinarySensor::HABinarySensor
HABinarySensor()
Binary sensor constructor.
Definition: haBinarySensor.h:90
HABinarySensor::setDeviceClass
void setDeviceClass(haBinarySensorClass_t devClass)
Define binary sensor class as haBinarySensorClass_t
Definition: haBinarySensor.cpp:13
HAEntity
Definition: haEntity.h:132