Merge branch 'upgrade-ha-mqtt'
This commit is contained in:
commit
43ebc4c2a3
@ -16,7 +16,7 @@ namespace Devices {
|
|||||||
.withModel("Esp8266 D1 Mini")
|
.withModel("Esp8266 D1 Mini")
|
||||||
.withArea("Living room");
|
.withArea("Living room");
|
||||||
|
|
||||||
Sensor* sensor = Builder<TemperatureSensor>::instance(SENSOR_ID)
|
Sensor* sensor = Builder<TemperatureSensor>(SENSOR_ID)
|
||||||
.withValueTemplate("{{ value_json.temperature }}")
|
.withValueTemplate("{{ value_json.temperature }}")
|
||||||
.withPrecision(1)
|
.withPrecision(1)
|
||||||
.asDevice(&DeviceConfig::create("esp-clock-living-room")
|
.asDevice(&DeviceConfig::create("esp-clock-living-room")
|
||||||
@ -25,32 +25,32 @@ namespace Devices {
|
|||||||
.withArea("Living room")
|
.withArea("Living room")
|
||||||
.withParent(espClockDevice)
|
.withParent(espClockDevice)
|
||||||
)
|
)
|
||||||
.addSecondary(Builder<HumiditySensor>::instance(SENSOR_ID).withValueTemplate("{{ value_json.humidity }}").withPrecision(1).build())
|
.addSecondary(Builder<HumiditySensor>(SENSOR_ID).withValueTemplate("{{ value_json.humidity }}").withPrecision(1).build())
|
||||||
.addSecondary(Builder<PressureSensor>::instance(SENSOR_ID).withValueTemplate("{{ value_json.pressure }}").withPrecision(1).build())
|
.addSecondary(Builder<PressureSensor>(SENSOR_ID).withValueTemplate("{{ value_json.pressure }}").withPrecision(1).build())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
auto ledMqtt = Builder<Light>::instance(new Light{ "Led", "led",
|
auto ledMqtt = Builder<Light>(new Light{ "Led", "led",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
turnLed(strcmp("ON", msg) == 0);
|
turnLed(strcmp("ON", msg) == 0);
|
||||||
}
|
}
|
||||||
}).restoreStateFromCommand().build();
|
}).restoreStateFromTopic().build();
|
||||||
|
|
||||||
auto brightnessMqtt = Builder<Number>::instance(new Number{ "Brightness", "brightness",
|
auto brightnessMqtt = Builder<Number>(new Number{ "Brightness", "brightness",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
Display::brightness = String{ msg }.toInt();
|
Display::brightness = String{ msg }.toInt();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.withMin(Display::Brightness::MIN).withMax(Display::Brightness::MAX).withStep(1)
|
.withMin(Display::Brightness::MIN).withMax(Display::Brightness::MAX).withStep(1)
|
||||||
.withIcon("mdi:brightness-7")
|
.withIcon("mdi:brightness-7")
|
||||||
.restoreStateFromCommand()
|
.restoreStateFromTopic()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
auto hourFormatMqtt = Builder<Switch>::instance(new Switch{ "Format 24h", "format_24h",
|
auto hourFormatMqtt = Builder<Switch>(new Switch{ "Format 24h", "format_24h",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
Display::hourFormat24 = (strcmp("ON", msg) == 0);
|
Display::hourFormat24 = (strcmp("ON", msg) == 0);
|
||||||
}
|
}
|
||||||
}).withIcon("mdi:hours-24").restoreStateFromCommand().build();
|
}).withIcon("mdi:hours-24").restoreStateFromTopic().build();
|
||||||
Number* displayTimerMqtt = Builder<Number>::instance(new Number{ "Timer duration", "timer_duration",
|
Number* displayTimerMqtt = Builder<Number>(new Number{ "Timer duration", "timer_duration",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
auto value = String{ msg }.toInt();
|
auto value = String{ msg }.toInt();
|
||||||
timer = value;
|
timer = value;
|
||||||
@ -65,11 +65,11 @@ namespace Devices {
|
|||||||
.withDeviceClass("duration")
|
.withDeviceClass("duration")
|
||||||
.withUnitMeasure("min")
|
.withUnitMeasure("min")
|
||||||
.withIcon("mdi:timer-edit-outline")
|
.withIcon("mdi:timer-edit-outline")
|
||||||
.restoreStateFromCommand()
|
.restoreStateFromTopic()
|
||||||
.build();
|
.build();
|
||||||
Sensor* timerRemainingMqtt = Builder<Sensor>::instance(new Sensor("Timer remaining", "timer_remaining"))
|
Sensor* timerRemainingMqtt = Builder<Sensor>(new Sensor("Timer remaining", "timer_remaining"))
|
||||||
.withUnitMeasure("min").withPrecision(0).withIcon("mdi:timer-sand").build();
|
.withUnitMeasure("min").withPrecision(0).withIcon("mdi:timer-sand").build();
|
||||||
Switch* timerMqtt = Builder<Switch>::instance(new Switch{"Timer", "timer",
|
Switch* timerMqtt = Builder<Switch>(new Switch{"Timer", "timer",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (strcmp("ON", msg) == 0) {
|
if (strcmp("ON", msg) == 0) {
|
||||||
Display::tTimer.restart();
|
Display::tTimer.restart();
|
||||||
@ -79,13 +79,13 @@ namespace Devices {
|
|||||||
timerMqtt->updateState(false);
|
timerMqtt->updateState(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).withIcon("mdi:timer-play-outline").restoreStateFromCommand().build();
|
}).withIcon("mdi:timer-play-outline").restoreStateFromTopic().build();
|
||||||
|
|
||||||
auto button =
|
auto button =
|
||||||
HaESP::restartButton()
|
HaESP::restartButton()
|
||||||
.asDevice(espClockDevice)
|
.asDevice(espClockDevice)
|
||||||
.addSecondary(
|
.addSecondary(
|
||||||
Builder<Button>::instance(new Button{"Display time", "display_time",
|
Builder<Button>(new Button{"Display time", "display_time",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (strcmp("PRESS", msg) == 0) {
|
if (strcmp("PRESS", msg) == 0) {
|
||||||
Display::displayTask.activate(Display::tDisplayTime);
|
Display::displayTask.activate(Display::tDisplayTime);
|
||||||
@ -94,7 +94,7 @@ namespace Devices {
|
|||||||
}).build()
|
}).build()
|
||||||
)
|
)
|
||||||
.addSecondary(
|
.addSecondary(
|
||||||
Builder<Button>::instance(new Button{"Display sensor data", "display_sensor_data",
|
Builder<Button>(new Button{"Display sensor data", "display_sensor_data",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (strcmp("PRESS", msg) == 0) {
|
if (strcmp("PRESS", msg) == 0) {
|
||||||
Bme::data.readAll();
|
Bme::data.readAll();
|
||||||
@ -104,7 +104,7 @@ namespace Devices {
|
|||||||
}).build()
|
}).build()
|
||||||
)
|
)
|
||||||
.addSecondary(
|
.addSecondary(
|
||||||
Builder<Button>::instance(new Button{"Display date", "display_date",
|
Builder<Button>(new Button{"Display date", "display_date",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (strcmp("PRESS", msg) == 0) {
|
if (strcmp("PRESS", msg) == 0) {
|
||||||
Display::displayTask.activate(Display::tDisplayDate);
|
Display::displayTask.activate(Display::tDisplayDate);
|
||||||
@ -113,7 +113,7 @@ namespace Devices {
|
|||||||
}).build()
|
}).build()
|
||||||
)
|
)
|
||||||
.addSecondary(
|
.addSecondary(
|
||||||
Builder<Button>::instance(new Button{"Display remaining timer", "display_remaining_timer",
|
Builder<Button>(new Button{"Display remaining timer", "display_remaining_timer",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (strcmp("PRESS", msg) == 0) {
|
if (strcmp("PRESS", msg) == 0) {
|
||||||
Display::displayTask.activate(Display::tDisplayTimer);
|
Display::displayTask.activate(Display::tDisplayTimer);
|
||||||
@ -122,7 +122,7 @@ namespace Devices {
|
|||||||
}).build()
|
}).build()
|
||||||
)
|
)
|
||||||
.addSecondary(
|
.addSecondary(
|
||||||
Builder<Button>::instance(new Button{"Update time", "update_time",
|
Builder<Button>(new Button{"Update time", "update_time",
|
||||||
[](const char* msg) {
|
[](const char* msg) {
|
||||||
if (strcmp("PRESS", msg) == 0) Ntp::tUpdateTime.restart();
|
if (strcmp("PRESS", msg) == 0) Ntp::tUpdateTime.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -120,23 +120,23 @@ namespace Display {
|
|||||||
} hourFormat24;
|
} hourFormat24;
|
||||||
|
|
||||||
struct Brightness : public CallbackAware<callback_t> {
|
struct Brightness : public CallbackAware<callback_t> {
|
||||||
static constexpr uint8 MIN = 0;
|
static constexpr uint8_t MIN = 0;
|
||||||
static constexpr uint8 MAX = 15;
|
static constexpr uint8_t MAX = 15;
|
||||||
static constexpr uint8 DAY = 11;
|
static constexpr uint8_t DAY = 11;
|
||||||
static constexpr uint8 NIGHT = MIN;
|
static constexpr uint8_t NIGHT = MIN;
|
||||||
|
|
||||||
void operator=(uint8 value) {
|
void operator=(uint8_t value) {
|
||||||
current = value % (MAX + 1);
|
current = value % (MAX + 1);
|
||||||
clockDisplay.setBrightness(current);
|
clockDisplay.setBrightness(current);
|
||||||
if (callback) callback();
|
if (callback) callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
operator uint8() {
|
operator uint8_t() {
|
||||||
return current;
|
return current;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uint8 current = NIGHT;
|
uint8_t current = NIGHT;
|
||||||
} brightness;
|
} brightness;
|
||||||
|
|
||||||
void drawTime() {
|
void drawTime() {
|
||||||
|
|||||||
@ -10,7 +10,7 @@ struct : public CallbackAware<remaining_callback_t> {
|
|||||||
if (callback) callback(remaining);
|
if (callback) callback(remaining);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator int8() {
|
operator int8_t() {
|
||||||
return remaining;
|
return remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19,5 +19,5 @@ struct : public CallbackAware<remaining_callback_t> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int8 remaining = 0;
|
int8_t remaining = 0;
|
||||||
} timer;
|
} timer;
|
||||||
|
|||||||
@ -23,7 +23,7 @@ lib_deps =
|
|||||||
sparkfun/SparkFun BME280@^2.0.9
|
sparkfun/SparkFun BME280@^2.0.9
|
||||||
arkhipenko/TaskScheduler@^3.8.5
|
arkhipenko/TaskScheduler@^3.8.5
|
||||||
https://git.hodos.ro/libraries/wifi.git@^2.0.0
|
https://git.hodos.ro/libraries/wifi.git@^2.0.0
|
||||||
https://git.hodos.ro/libraries/ha-mqtt.git@^1.10.0
|
https://git.hodos.ro/libraries/ha-mqtt.git#2.0.0
|
||||||
build_flags = -D WIFI_ALWAYS_ON=1 -D ADAFRUIT_BME=1
|
build_flags = -D WIFI_ALWAYS_ON=1 -D ADAFRUIT_BME=1
|
||||||
|
|
||||||
[env:laptop_home]
|
[env:laptop_home]
|
||||||
|
|||||||
@ -73,13 +73,14 @@ void setup() {
|
|||||||
[] {turnLed();}
|
[] {turnLed();}
|
||||||
);
|
);
|
||||||
Devices::setup();
|
Devices::setup();
|
||||||
|
WebServer::setup();
|
||||||
|
|
||||||
Wifi::setup(ts,
|
Wifi::setup(ts,
|
||||||
[] {
|
[] {
|
||||||
Ota::tLoop.enable();
|
Ota::tLoop.enable();
|
||||||
Mqtt::tReConnect.enable();
|
Mqtt::tReConnect.enable();
|
||||||
Ntp::tUpdateTime.enable();
|
Ntp::tUpdateTime.enable();
|
||||||
WebServer::setup();
|
WebServer::start();
|
||||||
},
|
},
|
||||||
[] {
|
[] {
|
||||||
Ota::tLoop.disable();
|
Ota::tLoop.disable();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user