publish altitude
This commit is contained in:
parent
dd99a71b37
commit
e236841345
11
include/ha.h
11
include/ha.h
@ -35,6 +35,17 @@ namespace Ha {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AltitudeConfig : SensorConfig {
|
||||||
|
AltitudeConfig(const char* name, const char* uniqueId, const char* stateTopic) {
|
||||||
|
this->name = name;
|
||||||
|
this->uniqueId = uniqueId;
|
||||||
|
this->stateTopic = stateTopic;
|
||||||
|
this->deviceClass = "distance";
|
||||||
|
this->unitMeasure = "m";
|
||||||
|
this->valueTemplate = "{{ value_json.altitude }}";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void buildDeviceConfig(JsonDocument& jsonDoc) {
|
void buildDeviceConfig(JsonDocument& jsonDoc) {
|
||||||
JsonObject device = jsonDoc.createNestedObject("device");
|
JsonObject device = jsonDoc.createNestedObject("device");
|
||||||
device["name"] = "ESP Clock";
|
device["name"] = "ESP Clock";
|
||||||
|
|||||||
@ -43,9 +43,16 @@ namespace Mqtt {
|
|||||||
client.publish("homeassistant/sensor/esp_clock/pressure/config", 0, true, message);
|
client.publish("homeassistant/sensor/esp_clock/pressure/config", 0, true, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void publishAltitudeConfig() {
|
||||||
|
char message[JSON_SIZE];
|
||||||
|
Ha::buildSensorConfig(message, Ha::AltitudeConfig{"Livingroom Altitude", "livingroom_altitude", bmpTopic});
|
||||||
|
client.publish("homeassistant/sensor/esp_clock/altitude/config", 0, true, message);
|
||||||
|
}
|
||||||
|
|
||||||
void publishConfig() {
|
void publishConfig() {
|
||||||
publishTempConfig();
|
publishTempConfig();
|
||||||
publishPressureConfig();
|
publishPressureConfig();
|
||||||
|
publishAltitudeConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void publishCommand() {
|
void publishCommand() {
|
||||||
@ -65,6 +72,7 @@ namespace Mqtt {
|
|||||||
StaticJsonDocument<255> jsonDoc;
|
StaticJsonDocument<255> jsonDoc;
|
||||||
jsonDoc["temperature"] = Bmp::data.temp;
|
jsonDoc["temperature"] = Bmp::data.temp;
|
||||||
jsonDoc["pressure"] = Bmp::data.pressure;
|
jsonDoc["pressure"] = Bmp::data.pressure;
|
||||||
|
jsonDoc["altitude"] = Bmp::data.altitude;
|
||||||
char message[255];
|
char message[255];
|
||||||
serializeJson(jsonDoc, message);
|
serializeJson(jsonDoc, message);
|
||||||
client.publish(bmpTopic, 0, true, message);
|
client.publish(bmpTopic, 0, true, message);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user