#pragma once #define SENSOR_ID "bme280" #include "ha.h" #include "esp.h" #include "display.h" using namespace Ha; namespace Devices { auto espClockDevice = &DeviceConfig::create(MAIN_DEVICE_ID) .withName("ESP Clock") .withManufacturer("Espressif") .withModel("Esp8266 D1 Mini") .withArea("Living room"); Sensor* sensor = Builder::instance(SENSOR_ID) .withValueTemplate("{{ value_json.temperature }}") .withPrecision(1) .asDevice(&DeviceConfig::create("esp-clock-living-room") .withName("Living room") .withModel("BPE280") .withArea("Living room") .withParent(espClockDevice) ) .addSecondary(Builder::instance(SENSOR_ID).withValueTemplate("{{ value_json.humidity }}").withPrecision(1).build()) .addSecondary(Builder::instance(SENSOR_ID).withValueTemplate("{{ value_json.pressure }}").withPrecision(1).build()) .build(); auto ledMqtt = Builder::instance(new Light{ "Led", "led", [](const char* msg) { turnLed(strcmp("ON", msg) == 0); } }).withStateTopic().restoreFromState().build(); auto brightnessMqtt = Builder::instance(new Number{ "Brightness", "brightness", [](const char* msg) { Display::Brightness::set(String{ msg }.toInt()); } }).withMin(BRIGHTNESS_MIN).withMax(BRIGHTNESS_MAX).withStep(BRIGHTNESS_STEP).withStateTopic().restoreFromState().build(); auto hourFormatMqtt = Builder::instance(new Switch{ "Format 24h", "format_24h", [](const char* msg) { strcmp("ON", msg) == 0 ? Display::changeHourFormat24(true) : Display::changeHourFormat24(false); } }).withStateTopic().restoreFromState().build(); auto button = Builder