mirror of
https://github.com/randybb/esphome-configs.git
synced 2026-01-02 11:37:28 +01:00
45 lines
878 B
C++
45 lines
878 B
C++
#include "esphome.h"
|
|
using namespace esphome;
|
|
|
|
class SonoffOut1 : public Component, public switch_::Switch {
|
|
public:
|
|
void setup() override {
|
|
// This will be called by App.setup()
|
|
}
|
|
|
|
void write_state(bool state) override {
|
|
Serial.write(0xA0);
|
|
Serial.write(0x04);
|
|
if (state)
|
|
Serial.write(0x05);
|
|
else
|
|
Serial.write(0x00);
|
|
Serial.write(0xA1);
|
|
Serial.write('\n');
|
|
Serial.flush();
|
|
publish_state(state);
|
|
}
|
|
};
|
|
|
|
class SonoffOut2 : public Component, public switch_::Switch {
|
|
public:
|
|
void setup() override {
|
|
// This will be called by App.setup()
|
|
}
|
|
|
|
void write_state(bool state) override {
|
|
Serial.write(0xA0);
|
|
Serial.write(0x04);
|
|
if (state)
|
|
Serial.write(0x06);
|
|
else
|
|
Serial.write(0x00);
|
|
Serial.write(0xA1);
|
|
Serial.write('\n');
|
|
Serial.flush();
|
|
|
|
publish_state(state);
|
|
|
|
}
|
|
};
|