EnigmaIOT
0.9.8
Secure sensor and gateway platform based on ESP8266 and ESP32
|
#include <haSensor.h>
Public Member Functions | |
HASensor () | |
Sensor constructor. More... | |
void | setDeviceClass (haSensorClass_t devClass) |
Define sensor class as haSensorClass_t https://www.home-assistant.io/integrations/sensor.mqtt/#device_class. More... | |
void | setExpireTime (uint payload) |
Defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes unavailable. https://www.home-assistant.io/integrations/sensor.mqtt/#expire_after. More... | |
void | setUnitOfMeasurement (const char *payload) |
Set unit of measure https://www.home-assistant.io/integrations/sensor.mqtt/#unit_of_measurement. More... | |
void | setValueField (const char *payload) |
Defines a json key that defines sensor value. When setting this, setValueTemplate () should not be called https://www.home-assistant.io/integrations/sensor.mqtt/#value_template. More... | |
void | setValueTemplate (const char *payload) |
Defines a template that defines sensor value. When setting this you should not call setValueField () https://www.home-assistant.io/integrations/sensor.mqtt/#value_template. More... | |
Public Member Functions inherited from HAEntity | |
size_t | getAnounceMessage (int bufferlen, uint8_t *buffer) |
Gets entity anounce message to be sent over EnigmaIOT message. More... | |
void | setNameSufix (const char *payload) |
Sets name suffix. Used for multi entity nodes. More... | |
void | allowSendAttributes () |
Enables registering entity attributes as a json object. More... | |
size_t | measureMessage () |
Gets needed buffer size for discovery message. More... | |
Static Public Member Functions | |
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 Sensor template. More... | |
static String | deviceClassStr (haSensorClass_t sensorClass) |
Gets sensor class name from haSensorClass_t https://www.home-assistant.io/integrations/sensor.mqtt/#device_class. More... | |
Static Public Member Functions inherited from HAEntity | |
static String | deviceTypeStr (haDeviceType_t entityType) |
Gets entity type string from haDeviceType_t value https://www.home-assistant.io/docs/mqtt/discovery/. More... | |
static String | getDiscoveryTopic (const char *hassPrefix, const char *nodeName, haDeviceType_t entityType, const char *nameSuffix=NULL) |
Allows Gateway to get discovery message MQTT topic. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from HAEntity | |
HAEntity () | |
Default constructor. Needed for inheritance. More... | |
Protected Attributes inherited from HAEntity | |
size_t | capacity |
JSON object memory reservation length. More... | |
haDeviceType_t | deviceType = UNDEFINED |
HomeAssistant entity device type. More... | |
DynamicJsonDocument * | entityConfig |
JSON object to be sent to gateway. More... | |
This mqtt sensor platform uses the MQTT message payload as the sensor value. If messages in this state_topic are published with RETAIN flag, the sensor will receive an instant update with last known value. Otherwise, the initial state will be undefined.
https://www.home-assistant.io/integrations/sensor.mqtt/
An example of sensor discovery message may be like this:
Topic: homeassistant/sensor/mains_power/config
Payload:
{ "name":"mains_power", // string (optional, default: MQTT Sensor). The name of the MQTT sensor "unique_id":"mains_power", // string (optional) An ID that uniquely identifies this sensor. If two sensors have the same unique ID, // Home Assistant will raise an exception "device_class":"power", // device_class (optional, default: None). The type/class of the sensor to set the icon in the frontend // https://www.home-assistant.io/integrations/sensor/#device-class "expire_after":300, // integer (optional, default: 0) Defines the number of seconds after the sensor’s state expires, // if it’s not updated. After expiry, the sensor’s state becomes unavailable "json_attributes_template":"{{value_json | tojson}}", // template (optional) Defines a template to extract the JSON dictionary // from messages received on the json_attributes_topic "json_attributes_topic":"EnigmaIOT/mains/data", // string (optional) The MQTT topic subscribed to receive a JSON dictionary // payload and then set as sensor attributes. Implies force_update of the // current sensor state when a message is received on this topic "state_topic":"EnigmaIOT/mains/data", // string REQUIRED. The MQTT topic subscribed to receive sensor values "unit_of_measurement":"W"", // string (optional). Defines the units of measurement of the sensor, if any "value_template":"{{value_json.pow}}" // template (optional). Defines a template to extract the value }
Template message for sensor is this
Topic: homeassistant/sensor/<node_name>_<name_suffix>/config
Payload
Message to gateway is like following
Definition at line 81 of file haSensor.h.
|
inline |
Sensor constructor.
Definition at line 87 of file haSensor.h.
|
static |
Gets sensor class name from haSensorClass_t
https://www.home-assistant.io/integrations/sensor.mqtt/#device_class.
sensorClass | Binary sensor class code |
Definition at line 123 of file haSensor.cpp.
|
static |
Allows Gateway to get Home Assistant discovery message using Sensor template.
buffer | Buffer to hold message string |
buflen | Buffer size |
nodeName | Originating node name |
networkName | EnigmaIOT network name |
inputJSON | JSON object sent by node with needed data to fill template in |
msgPack || !len
Definition at line 65 of file haSensor.cpp.
void HASensor::setDeviceClass | ( | haSensorClass_t | devClass | ) |
Define sensor class as haSensorClass_t
https://www.home-assistant.io/integrations/sensor.mqtt/#device_class.
devClass | Device class |
Definition at line 13 of file haSensor.cpp.
void HASensor::setExpireTime | ( | uint | payload | ) |
Defines the number of seconds after the sensor’s state expires, if it’s not updated. After expiry, the sensor’s state becomes unavailable. https://www.home-assistant.io/integrations/sensor.mqtt/#expire_after.
payload | Expiration value in seconds |
Definition at line 20 of file haSensor.cpp.
void HASensor::setUnitOfMeasurement | ( | const char * | payload | ) |
Set unit of measure https://www.home-assistant.io/integrations/sensor.mqtt/#unit_of_measurement.
payload | Measure unit |
Definition at line 26 of file haSensor.cpp.
void HASensor::setValueField | ( | const char * | payload | ) |
Defines a json key that defines sensor value. When setting this, setValueTemplate ()
should not be called https://www.home-assistant.io/integrations/sensor.mqtt/#value_template.
payload | json key |
Definition at line 32 of file haSensor.cpp.
void HASensor::setValueTemplate | ( | const char * | payload | ) |
Defines a template that defines sensor value. When setting this you should not call setValueField ()
https://www.home-assistant.io/integrations/sensor.mqtt/#value_template.
payload | Value template definition |
Definition at line 38 of file haSensor.cpp.