publish state of led
This commit is contained in:
parent
f237fba978
commit
e8b8c42959
@ -55,11 +55,17 @@ namespace Mqtt {
|
||||
new Ha::AltitudeSensor{"Living room Altitude", "altitude"}
|
||||
};
|
||||
|
||||
Ha::Command* ledMqtt = (new Ha::Switch{"ESP Clock Led", "led",
|
||||
[](const char* msg) {
|
||||
String{ "ON" }.equals(msg) ? digitalWrite(LED_BUILTIN, LOW) : digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
})->withStateTopic();
|
||||
|
||||
Ha::Command* brightnessMqtt = (new Ha::Brightness{ "ESP Clock Brightness", "brightness",
|
||||
[](const char* msg) {
|
||||
Display::Brightness::set(String{ msg }.toInt());
|
||||
}
|
||||
})->withStateTopic();
|
||||
})->withStateTopic();
|
||||
|
||||
Ha::Command* switches[] = {
|
||||
new Ha::Button{"ESP Clock Restart", "restart",
|
||||
@ -67,11 +73,7 @@ namespace Mqtt {
|
||||
if (String { "PRESS" }.equals(msg)) ESP.restart();
|
||||
}
|
||||
},
|
||||
new Ha::Switch{"ESP Clock Led", "led",
|
||||
[](const char* msg) {
|
||||
String{ "ON" }.equals(msg) ? digitalWrite(LED_BUILTIN, LOW) : digitalWrite(LED_BUILTIN, HIGH);
|
||||
}
|
||||
},
|
||||
ledMqtt,
|
||||
new Ha::Switch{"ESP Clock Format 24h", "format_24h",
|
||||
[](const char* msg) {
|
||||
if (String{ "ON" }.equals(msg)) {
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
void checkWifiCallback();
|
||||
void onWifiConnected();
|
||||
void onButtonPressed();
|
||||
void onLed();
|
||||
void onButtonCallback();
|
||||
|
||||
#include <TaskScheduler.h>
|
||||
@ -20,6 +21,7 @@ Task tButton(TASK_IMMEDIATE, TASK_ONCE, onButtonCallback, &ts);
|
||||
#include "ir.h"
|
||||
|
||||
#define BUTTON D3
|
||||
#define LED D4
|
||||
|
||||
|
||||
void setup() {
|
||||
@ -40,6 +42,7 @@ void setup() {
|
||||
|
||||
pinMode(BUTTON, INPUT_PULLUP);
|
||||
attachInterrupt(digitalPinToInterrupt(BUTTON), onButtonPressed, FALLING);
|
||||
attachInterrupt(digitalPinToInterrupt(LED), onLed, CHANGE);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@ -70,6 +73,10 @@ ICACHE_RAM_ATTR void onButtonPressed() {
|
||||
tButton.restart();
|
||||
}
|
||||
|
||||
ICACHE_RAM_ATTR void onLed() {
|
||||
Mqtt::publish(Mqtt::ledMqtt->stateTopic, digitalRead(LED) ? "OFF" : "ON");
|
||||
}
|
||||
|
||||
void onButtonCallback() {
|
||||
Display::displayTemp(Bmp::data.readTemp());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user