add oil tank sensor
This commit is contained in:
parent
2ef559969c
commit
d822e3438c
@ -69,15 +69,20 @@ namespace Ha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
virtual void buildUniqueId(char* uniqueId) = 0;
|
virtual void buildUniqueId(char* uniqueId) = 0;
|
||||||
|
|
||||||
virtual void buildConfig(JsonDocument& jsonDoc) {
|
virtual void buildConfigTopic() {
|
||||||
if (String{"diagnostic"}.equals(entityCategory)) {
|
if (String{"diagnostic"}.equals(entityCategory) && deviceClass) {
|
||||||
sprintf(configTopic, "homeassistant/%s/%s/%s_%s/config", type, MAIN_DEVICE_ID, deviceClass, id);
|
sprintf(configTopic, "homeassistant/%s/%s/%s_%s/config", type, MAIN_DEVICE_ID, deviceClass, id);
|
||||||
} else {
|
} else {
|
||||||
sprintf(configTopic, "homeassistant/%s/%s/%s/config", type, MAIN_DEVICE_ID, id);
|
sprintf(configTopic, "homeassistant/%s/%s/%s/config", type, MAIN_DEVICE_ID, id);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void buildConfig(JsonDocument& jsonDoc) {
|
||||||
|
buildConfigTopic();
|
||||||
if (mainDevice) mainDevice->buildConfig(jsonDoc);
|
if (mainDevice) mainDevice->buildConfig(jsonDoc);
|
||||||
if (entityCategory) jsonDoc["entity_category"] = entityCategory;
|
if (entityCategory) jsonDoc["entity_category"] = entityCategory;
|
||||||
|
if (deviceClass) jsonDoc["device_class"] = deviceClass;
|
||||||
jsonDoc["name"] = name;
|
jsonDoc["name"] = name;
|
||||||
char uniqueId[50];
|
char uniqueId[50];
|
||||||
buildUniqueId(uniqueId);
|
buildUniqueId(uniqueId);
|
||||||
@ -184,9 +189,7 @@ namespace Ha {
|
|||||||
|
|
||||||
void buildConfig(JsonDocument& jsonDoc) override {
|
void buildConfig(JsonDocument& jsonDoc) override {
|
||||||
EntityConfig::buildConfig(jsonDoc);
|
EntityConfig::buildConfig(jsonDoc);
|
||||||
if (entityCategory) jsonDoc["entity_category"] = entityCategory;
|
if (unitMeasure) jsonDoc["unit_of_measurement"] = unitMeasure;
|
||||||
jsonDoc["device_class"] = deviceClass;
|
|
||||||
jsonDoc["unit_of_measurement"] = unitMeasure;
|
|
||||||
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
if (valueTemplate) jsonDoc["value_template"] = valueTemplate;
|
||||||
jsonDoc["state_topic"] = stateTopic;
|
jsonDoc["state_topic"] = stateTopic;
|
||||||
jsonDoc["suggested_display_precision"] = 2;
|
jsonDoc["suggested_display_precision"] = 2;
|
||||||
@ -241,12 +244,4 @@ namespace Ha {
|
|||||||
valueTemplate = "{{ value_json.sensor.pressure }}";
|
valueTemplate = "{{ value_json.sensor.pressure }}";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// struct AltitudeSensor : Sensor {
|
|
||||||
// AltitudeSensor(const char* name, const char* id) : Sensor(name, id) {
|
|
||||||
// deviceClass = "distance";
|
|
||||||
// unitMeasure = "m";
|
|
||||||
// valueTemplate = "{{ value_json.sensor.altitude }}";
|
|
||||||
// }
|
|
||||||
// };
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -13,7 +13,6 @@ namespace Mqtt {
|
|||||||
AsyncMqttClient client;
|
AsyncMqttClient client;
|
||||||
|
|
||||||
void publishInit();
|
void publishInit();
|
||||||
void publishBme280();
|
|
||||||
void disconnect();
|
void disconnect();
|
||||||
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []() {
|
Task tReConnect(5 * TASK_MINUTE, TASK_FOREVER, []() {
|
||||||
Serial.println("Connecting to MQTT...");
|
Serial.println("Connecting to MQTT...");
|
||||||
@ -50,11 +49,8 @@ namespace Mqtt {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Ha::Sensor* sensors[] = {
|
Ha::Sensor* sensors[] = {
|
||||||
SensorBuilder::withVoltage((new Ha::TemperatureSensor{"4"})->copyFromDevice(atTinyDevice)->withDeviceName("Oil tank room")->withArea("Basement"))
|
SensorBuilder::withVoltage((new Ha::TemperatureSensor{"4"})->copyFromDevice(atTinyDevice)->withDeviceName("Oil tank room")->withArea("Basement")),
|
||||||
// new Ha::TemperatureSensor{"Temperature", "temperature"},
|
OilSensorBuilder::build("7")
|
||||||
// new Ha::HumiditySensor{"Humidity", "humidity"},
|
|
||||||
// new Ha::PressureSensor{"Pressure", "pressure"},
|
|
||||||
// new Ha::AltitudeSensor{"Altitude", "altitude"}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void publishComponentConfig(Ha::Component& component) {
|
void publishComponentConfig(Ha::Component& component) {
|
||||||
@ -81,17 +77,6 @@ namespace Mqtt {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishBme280() {
|
|
||||||
// StaticJsonDocument<255> jsonDoc;
|
|
||||||
// jsonDoc["temperature"] = Bme::data.temp;
|
|
||||||
// jsonDoc["humidity"] = Bme::data.humidity;
|
|
||||||
// jsonDoc["pressure"] = Bme::data.pressure;
|
|
||||||
// jsonDoc["altitude"] = Bme::data.altitude;
|
|
||||||
// char message[255];
|
|
||||||
// serializeJson(jsonDoc, message);
|
|
||||||
// publish(Ha::Sensor::stateTopic, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
void onMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
void onMessage(char* topic, char* payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total) {
|
||||||
char msg[len + 1];
|
char msg[len + 1];
|
||||||
memcpy(msg, payload, len);
|
memcpy(msg, payload, len);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user