My ESP device is no longer available in HA

I setup a ESP8266 NODEMCU in HA the other day and as long as it was powered it would show current status and allow me to control. I uploaded a new sketch to it with a few new lines(NOT) touching the wifi logic and now in HA it doesnt show available. BUT i can access it directly via the IP and control the LED light on the board from the webpage to it…

Here is my current sketch, the ONLY new lines i added for testing are the photocell lines, ive made them bold in the lines below.

Is there any way to refresh, so that is finds it? I found some mentions online about adding a dashboard ping, but cant figure out where that would be setup / inserted.

#include <ESP8266WiFi.h>
 
const char* ssid = "ssid";
const char* password = "pass";
 
int ledPin = 16; // GPIO16
WiFiServer server(80);

**int photocellPin = 0;     // the cell and 10K pulldown are connected to a0**
**int photocellReading;     // the analog reading from the sensor divider**
 
void setup() {
  Serial.begin(115200);
  delay(10);
 
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW);
 
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
 
  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");
 
}
 
void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
 
  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
 
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();
 
  // Match the request
 
  int value = LOW;
  if (request.indexOf("/LED=OFF") != -1)  {
    digitalWrite(ledPin, HIGH);
    value = HIGH;
  }
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(ledPin, LOW);
    value = LOW;
  }

  **photocellReading = analogRead(photocellPin);  **
**  Serial.print("Analog reading = ");**
**  Serial.println(photocellReading);     // the raw analog reading**
 
  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("<html>");
 
  client.print("Led pin is now: ");
 
  if(value == HIGH) {
    client.print("Off");
  } else {
    client.print("On");
  }
  client.println("<br><br>");
  client.println("<a href=\"/LED=ON\"\"><button>Turn On </button></a>");
  client.println("<a href=\"/LED=OFF\"\"><button>Turn Off </button></a><br />");  
  client.println("</html>");
 
  delay(1);
}

Seems nothing to do with esphome.

1 Like

Why wouldnt it be? I just need to know how to refresh HA/ESPHOME so it can find the device again.
Even if i remove the few lines i added, it still doesnt work. The IP is set so it never changes, its on the network and accessible thru all other means except esphome/ha.

Because you aren’t using esphome.

1 Like

The device is setup in esphome /HA and up until today i have been able to control it from the HA dashboard. And you are correct, im not using esphome because it stopped working, im trying to get it to work again in esphome…

Well then why did you show us a .h file?

Flash it with esphome via USB.

My apologies, i posted that, because that is what was flashed to the board during my initial testing before esphome was involved… and forgot that its all yaml based in order to get it in HA.

I reflashed it from the easyflash utility and its recognized again.

So on to the next question which ill post new…

Sorry for the confusion, appreciate the help.

2 Likes