Your best option for battery power would probably be zwave. but that’ll probably take more time than you want to spend. I know you said you wanted to ovoid esp8266 but Its probably your cheapest option. because its wifi it wont last long on battery so it would have to b plugged in. But you said you didnt want esp8266 because you would probably never get around to it. The following sketch is built for cloudMQTT and turns pin D1 on a nodemcu board on and off, but could easily modified for a normal esp8266 board.
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* ssid = “YOUR SSID”;
const char* password = “YOUR PASSWORD”;
const char* mqttServer = “YOUR MQTT ADDRESS”;
const int mqttPort = 18339;
const char* mqttUser = “esp8266”;
const char* mqttPassword = “esp8266”;
WiFiClient espClient;
PubSubClient client(espClient);
void setup() {
pinMode(D1, OUTPUT); // Initialize the BUILTIN_LED pin as an output
pinMode(BUILTIN_LED, OUTPUT);
Serial.begin(115200);
digitalWrite(BUILTIN_LED, LOW); // Turn the LED on (Note that LOW is the voltage level
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(“Connecting to WiFi…”);
}
Serial.println(“Connected to the WiFi network”);
client.setServer(mqttServer, mqttPort);
client.setCallback(callback);
while (!client.connected()) {
Serial.println(“Connecting to MQTT…”);
if (client.connect("ESP8266Client", mqttUser, mqttPassword )) {
Serial.println("connected");
} else {
Serial.print("failed with state ");
Serial.print(client.state());
delay(2000);
}
}
client.publish(“esp/desklight”, “Desklight is Online”);
client.subscribe(“esp/desklight”);
}
void callback(char* topic, byte* payload, unsigned int length) {
Serial.print("Message arrived in topic: ");
Serial.println(topic);
Serial.print(“Message:”);
for (int i = 0; i < length; i++) {
Serial.print((char)payload[i]);
}
Serial.println();
Serial.println("-----------------------");
if ((char)payload[0] == ‘1’) {
digitalWrite(D1, LOW); // Turn the LED off (Note that LOW is the voltage level
} else if ((char)payload[0] == ‘2’) {
digitalWrite(D1, HIGH); // Turn the LED on by making the voltage HIGH
}
}
void reconnect() {
// Loop until we’re reconnected
while (!client.connected()) {
Serial.print(“Attempting MQTT connection…”);
// Attempt to connect
if (client.connect(“ESP8266Client”, mqttUser, mqttPassword )) {
Serial.println(“connected”);
// Once connected, publish an announcement…
client.publish(“esp/desklight”, “Connected”);
// … and resubscribe
client.subscribe(“esp/desklight”);
} else {
Serial.print(“failed, rc=”);
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
}
I hope this helps, I use it for diy relay control but just attaching a LED to it should work just fine. Its probably the easiest and fastest way to do this