Arduino RELAY switches over WiFi, controlled via HASS / MQTT, comes with OTA Support

Hey, thank you for sharing this fantastic project. A question, why, after turning on a switch, if I restart home assistant I find the button in the off position? Thank’s

This is great work mate,

I’m on the hunt on instructions to build one.

Unfortunately the wiring photos aren’t loading up. Could you re-upload them when you get a chance?
I’d also like to know what parts you used for the irrigation/sprinkler system, did you buy anything locally?

Regards from Sydney :slight_smile:

I recently purchased a Wemos® Mega + WiFi R3 ATmega2560 + ESP8266 and would like to know if you could help me set it up. I know it’s not the proper forum but if you can sendo some links I would thank you. To set it up should I just upload your Sketch on Arduino?

@RKor,

My apologies for the long silence, was away on holiday and no access to email.
I will check my old pc and will re-upload the images.

With the Solenoid Valves… I went with this mob https://www.valvesdirect.net/product-category/irrigation/solenoid-valves/ rather than Bunnings.

Cheers
Erick

@gabrielmiranda,

Hi, things had changed big time since I created my project. I guess, for the security paranoid people they will stick to the original setup I created (which is OK and I find it very stable given it only holds the bare minimum code needed to make it work, but lacks the flexibility of on the fly reconfiguration).

Anyway, I would suggest following a different path (using TASMOTA by Theo Arends) . https://github.com/arendst/Sonoff-Tasmota

Dr Zzzzz have created a nice video explaining how to use Theos’s code on Wemos mini https://www.youtube.com/watch?v=sVml02kP3DU and you can use this same approach for your Wemos.

Key benefit of TASMOTA, once you have pushed in the code to your *duino module, things will be easier to manage via a Management Portal.

Good luck!

Cheers
Erick

2 Likes

Hi, im still bad at programming and can’t understand how to make a binary sensor instead of a switch…

i have a magnetic sensor for the door

Hi @merccooper,

I’m guessing you are using an IoT device for your magnetic sensor where it will publish the state depending on magnetic on/off position.

have look at this page


It has lots of good example on how to create the sensor.

Otherwise, do post your code for the community to see what is not working,

Cheers
Erick

Hello , would you help me ? I have an Arduino mega with Ethernet shield 5100 connected to an 8 relay module . I want half of the relays to work as On off switches and the other half as pulse switches ( garage opening as an example )

I’ve tried mixing some of your code because I don’t have the esp but I can’t get it to work

Hello, i want to to this but with arduino mega + ethernet shield 5100 + 4 relay board, need help

Have you tried using using TASMOTA for your Arduino Mega?
https://tasmota.github.io/docs/#/installation/

This will make it easy for you to program your arduino’s IO using a graphical user interface rather than via programming approach.

It will also help you achieve your goal on how to utilze the buttons via settings:

Let us know how you go.

Wow, never thought of tasmota with arduino mega, i beleive it depends on having esp8266 as a network device and i have ethernet shield, but i’m looking into it asap, i’m going crazy, ethernet shield connects when it wants to

Oh, you are right… sorry I missed that point, it’s esp8266 centric.

You may need to do it the old fashioned way. (Arduino IDE :slight_smile:)
replacing the ESP lib with Ethernet.h

Then retrofit the following logic

For push button sketch
https://www.arduino.cc/en/tutorial/pushbutton

For a switch Sketch
https://www.arduino.cc/en/tutorial/switch

and MQTT if this what you intent to use to control the interaction.

Unfortunately I had not played around much with this so … am inviting my fellow HA enthusiast to step in and assist.

Cheers!

Thank you very much , I lost the battle , I got it to work but then Arduino shield looses connection when it wants and mqtt will not work so I ordered two esp32 to tasmotize and connect directly to my relay boards and get over with this project , does it happen to any of you guys that this becomes like an addiction to try and automate everything but sometimes stuff stops working and you start investing more time fixing than relaxing ? I love this stuff but sometimes I feel this .

we’re on the same boat :slight_smile: :slight_smile: :slight_smile:

Hello people

I have an automation project with two Mega Arduinos and over 70 relays, all wired. I am implementing the Home Assistant and I am having difficulty making the communication between the two. The two arduinos are connected to my network via LAN. Could someone help me how to do this case. I’m having a hard time and that would be very important for my project. If anyone can help me with a simple project on how to change the status of any Arduino pin from 0 to 1 via the Home Assistant it would be of great help

thankful

Asking the same question in 8 or more topics won’t help you get an answer quicker. What have you tried already ? Do you have any experience programming arduinos ? Do your arduinos have an ethernet shield attached ? If they have an ethernet shield attached, you could check out the openmqttgateway project

https://docs.openmqttgateway.com/

Hi Mr. Erick

I am new about esp8266
and I’m very happy to see your code, I appreciate it.

sorry to bother you

where to put the sprinkler code ??
I am very grateful with all the help
thank you

Hi Panovano,

The sprinkler code in my case is now a script in homeassistant (a very simple one that calls the Sprinkler switches [ arduino module/4 relay switches ] every 6 am, and running them for at least 3 minutes). Hopefully I understood what you meant.

for the Switches code in Homeassistant, refer to the configuration.yaml in my original post

Ask again if you meant something different.

cheers!

I have been using this sketch (modified to work with ethernet shield) for a few months. Then after a problem with HA that forced me to reinstall HA without a backup, I could no longer read the topics.
Reinstalled mosquitto broker addon.
Same configuration.yaml setting

any suggestions? maybe a mosquitto broker setting?

Hello Guys.

Please I need some help, I tried the code above but is not working and I don’t know way. My home assistant is installed on a docker and I use a ESP8266 NODEMCU

ESP Code:

#include <PubSubClient.h>
#include <ESP8266WiFi.h>
#include <ArduinoOTA.h>

void callback(char* topic, byte* payload, unsigned int length);

//EDIT THESE LINES TO MATCH YOUR SETUP
#define MQTT_SERVER "192.168.100.149"  //you MQTT IP Address
const char* ssid = "Archer";
const char* password = "test";

//EJ: Data PIN Assignment on WEMOS D1 R2 https://www.wemos.cc/product/d1.html
// if you are using Arduino UNO, you will need to change the "D1 ~ D4" with the corresponding UNO DATA pin number 

const int switchPin1 = D3;
const int switchPin2 = D4;
const int switchPin3 = D5;
const int switchPin4 = D6;

//EJ: These are the MQTT Topic that will be used to manage the state of Relays 1 ~ 4
//EJ: Refer to my YAML component entry
//EJ: feel free to replicate the line if you have more relay switch to control, but dont forget to increment the number suffix so as increase switch logics in loop()

char const* switchTopic1 = "/house/switch1/";
char const* switchTopic2 = "/house/switch2/";
char const* switchTopic3 = "/house/switch3/";
char const* switchTopic4 = "/house/switch4/";


WiFiClient wifiClient;
PubSubClient client(MQTT_SERVER, 1883, callback, wifiClient);

void setup() {
  //initialize the switch as an output and set to LOW (off)
  pinMode(switchPin1, OUTPUT); // Relay Switch 1
  digitalWrite(switchPin1, HIGH);

  pinMode(switchPin2, OUTPUT); // Relay Switch 2
  digitalWrite(switchPin2, HIGH);

  pinMode(switchPin3, OUTPUT); // Relay Switch 3
  digitalWrite(switchPin3, LOW);

  pinMode(switchPin4, OUTPUT); // Relay Switch 4
  digitalWrite(switchPin4, LOW);

  ArduinoOTA.setHostname("My Arduino WEMO"); // A name given to your ESP8266 module when discovering it as a port in ARDUINO IDE
  ArduinoOTA.begin(); // OTA initialization

  //start the serial line for debugging
  Serial.begin(115200);
  delay(100);

  //start wifi subsystem
  WiFi.begin(ssid, password);
  //attempt to connect to the WIFI network and then connect to the MQTT server
  reconnect();

  //wait a bit before starting the main loop
      delay(2000);
}


void loop(){

  //reconnect if connection is lost
  if (!client.connected() && WiFi.status() == 3) {reconnect();}

  //maintain MQTT connection
  client.loop();

  //MUST delay to allow ESP8266 WIFI functions to run
  delay(10); 
  ArduinoOTA.handle();
}

void callback(char* topic, byte* payload, unsigned int length) {

  //convert topic to string to make it easier to work with
  String topicStr = topic; 
  //EJ: Note:  the "topic" value gets overwritten everytime it receives confirmation (callback) message from MQTT

  //Print out some debugging info
  Serial.println("Callback update.");
  Serial.print("Topic: ");
  Serial.println(topicStr);

   if (topicStr == "/house/switch1/") 
    {

     //turn the switch on if the payload is '1' and publish to the MQTT server a confirmation message
     if(payload[0] == '1'){
       digitalWrite(switchPin1, HIGH);
       client.publish("/house/switchConfirm1/", "1");
       }

      //turn the switch off if the payload is '0' and publish to the MQTT server a confirmation message
     else if (payload[0] == '0'){
       digitalWrite(switchPin1, LOW);
       client.publish("/house/switchConfirm1/", "0");
       }
     }

     // EJ: copy and paste this whole else-if block, should you need to control more switches
     else if (topicStr == "/house/switch2/") 
     {
     //turn the switch on if the payload is '1' and publish to the MQTT server a confirmation message
     if(payload[0] == '1'){
       digitalWrite(switchPin2, HIGH);
       client.publish("/house/switchConfirm2/", "1");
       }

      //turn the switch off if the payload is '0' and publish to the MQTT server a confirmation message
     else if (payload[0] == '0'){
       digitalWrite(switchPin2, LOW);
       client.publish("/house/switchConfirm2/", "0");
       }
     }
     else if (topicStr == "/house/switch3/") 
     {
     //turn the switch on if the payload is '1' and publish to the MQTT server a confirmation message
     if(payload[0] == '1'){
       digitalWrite(switchPin3, HIGH);
       client.publish("/house/switchConfirm3/", "1");
       }

      //turn the switch off if the payload is '0' and publish to the MQTT server a confirmation message
     else if (payload[0] == '0'){
       digitalWrite(switchPin3, LOW);
       client.publish("/house/switchConfirm3/", "0");
       }
     }
     else if (topicStr == "/house/switch4/") 
     {
     //turn the switch on if the payload is '1' and publish to the MQTT server a confirmation message
     if(payload[0] == '1'){
       digitalWrite(switchPin4, HIGH);
       client.publish("/house/switchConfirm4/", "1");
       }

      //turn the switch off if the payload is '0' and publish to the MQTT server a confirmation message
     else if (payload[0] == '0'){
       digitalWrite(switchPin4, LOW);
       client.publish("/house/switchConfirm4/", "0");
       }
     }
}


void reconnect() {

  //attempt to connect to the wifi if connection is lost
  if(WiFi.status() != WL_CONNECTED){
    //debug printing
    Serial.print("Connecting to ");
    Serial.println(ssid);

    //loop while we wait for connection
    while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
    }

    //print out some more debug once connected
    Serial.println("");
    Serial.println("WiFi connected");  
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  }

  //make sure we are connected to WIFI before attemping to reconnect to MQTT
  if(WiFi.status() == WL_CONNECTED){
  // Loop until we're reconnected to the MQTT server
    while (!client.connected()) {
      Serial.print("Attempting MQTT connection...");

      // Generate client name based on MAC address and last 8 bits of microsecond counter
      String clientName;
      clientName += "esp8266-";
      uint8_t mac[6];
      WiFi.macAddress(mac);
      clientName += macToStr(mac);

      //if connected, subscribe to the topic(s) we want to be notified about
      //EJ: Delete "mqtt_username", and "mqtt_password" here if you are not using any 
      if (client.connect((char*) clientName.c_str())) {  //EJ: Update accordingly with your MQTT account 
        Serial.print("\tMQTT Connected");
        client.subscribe(switchTopic1);
        client.subscribe(switchTopic2);
        client.subscribe(switchTopic3);
        client.subscribe(switchTopic4);
        //EJ: Do not forget to replicate the above line if you will have more than the above number of relay switches
      }

      //otherwise print failed for debugging
      else{Serial.println("\tFailed."); abort();}
    }
  }
}

//generate unique name from MAC addr
String macToStr(const uint8_t* mac){

  String result;

  for (int i = 0; i < 6; ++i) {
    result += String(mac[i], 16);

    if (i < 5){
      result += ':';
    }
  }

  return result;
}

Serial output:

.................
WiFi connected
IP address: 
192.168.100.151
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Callback update.
Topic: /house/switch1/
Callback update.
Topic: /house/switch2/
Callback update.
Topic: /house/switch3/
Callback update.
Topic: /house/switch4/
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected
Attempting MQTT connection...	MQTT Connected

Yaml:

default_config:

# Light
switch 1:
  - platform: mqtt
    name: "MQTT Switch 1"
    state_topic: "/house/switchConfirm1/"
    command_topic: "/house/switch1/"
    payload_on: "1"
    payload_off: "0"
    qos: 0
    retain: true    
  
switch 2:
  - platform: mqtt
    name: "MQTT Switch 2"
    state_topic: "/house/switchConfirm2/"
    command_topic: "/house/switch2/"
    payload_on: "1"
    payload_off: "0"
    qos: 0
    retain: true    

switch 3:
  - platform: mqtt
    name: "MQTT Switch 3"
    state_topic: "/house/switchConfirm3/"
    command_topic: "/house/switch3/"
    payload_on: "1"
    payload_off: "0"
    qos: 0
    retain: true    
  
switch 4:
  - platform: mqtt
    name: "MQTT Switch 4"
    state_topic: "/house/switchConfirm4/"
    command_topic: "/house/switch4/"
    payload_on: "1"
    payload_off: "0"
    qos: 0
    retain: true    
# Uncomment this if you are using SSL/TLS, running in Docker container, etc.
# http:
#   base_url: example.duckdns.org:8123
# MQTT broker
mqtt:
  broker: 192.168.100.149
  port: 1883
  client_id: esp8266-2c:f4:32:3c:63:b2
  keepalive: 60
  protocol: 3.1 

# Text to speech
tts:
  - platform: google_translate

group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

If I remove this line from yaml client_id: esp8266-2c:f4:32:3c:63:b2 on the serial I have only this Output:

.................
WiFi connected
IP address: 
192.168.100.151
Attempting MQTT connection...	MQTT Connected

On the Lovelace the switch buttons are grey out and blink.

Annotation 2020-08-05 222604

Mosquitto broker logs:

1596655831: New connection from 192.168.100.151 on port 1883.
1596655831: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655831: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655832: New connection from 172.30.32.1 on port 1883.
1596655832: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655832: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655832: New connection from 192.168.100.151 on port 1883.
1596655832: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655832: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655833: New connection from 172.30.32.1 on port 1883.
1596655833: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655833: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655833: New connection from 192.168.100.151 on port 1883.
1596655833: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655833: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655834: New connection from 172.30.32.1 on port 1883.
1596655834: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655834: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655834: New connection from 192.168.100.151 on port 1883.
1596655834: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655834: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655835: New connection from 172.30.32.1 on port 1883.
1596655835: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655835: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655835: New connection from 192.168.100.151 on port 1883.
1596655835: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655835: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655836: New connection from 172.30.32.1 on port 1883.
1596655836: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655836: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655836: New connection from 192.168.100.151 on port 1883.
1596655836: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655836: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655837: New connection from 172.30.32.1 on port 1883.
1596655837: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655837: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655837: New connection from 192.168.100.151 on port 1883.
1596655837: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655837: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655838: New connection from 172.30.32.1 on port 1883.
1596655838: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655838: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655838: New connection from 192.168.100.151 on port 1883.
1596655838: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655838: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655839: New connection from 172.30.32.1 on port 1883.
1596655839: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655839: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655839: New connection from 192.168.100.151 on port 1883.
1596655839: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655839: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655840: New connection from 172.30.32.1 on port 1883.
1596655840: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655840: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655840: New connection from 192.168.100.151 on port 1883.
1596655840: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655840: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655841: New connection from 172.30.32.1 on port 1883.
1596655841: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655841: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655841: New connection from 192.168.100.151 on port 1883.
1596655841: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655841: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655842: New connection from 172.30.32.1 on port 1883.
1596655842: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655842: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655842: New connection from 192.168.100.151 on port 1883.
1596655842: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655842: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655843: New connection from 172.30.32.1 on port 1883.
[INFO] found homeassistant on local database
1596655844: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655844: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655844: New connection from 192.168.100.151 on port 1883.
1596655844: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655844: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655845: New connection from 172.30.32.1 on port 1883.
1596655845: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655845: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655845: New connection from 192.168.100.151 on port 1883.
1596655845: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655845: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655846: New connection from 172.30.32.1 on port 1883.
1596655846: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655846: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655846: New connection from 192.168.100.151 on port 1883.
1596655846: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655846: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655847: New connection from 172.30.32.1 on port 1883.
1596655847: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655847: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655847: New connection from 192.168.100.151 on port 1883.
1596655847: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655847: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).
1596655848: New connection from 172.30.32.1 on port 1883.
1596655848: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655848: New client connected from 172.30.32.1 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k60, u'homeassistant').
1596655848: New connection from 192.168.100.151 on port 1883.
1596655848: Client esp8266-2c:f4:32:3c:63:b2 already connected, closing old connection.
1596655848: New client connected from 192.168.100.151 as esp8266-2c:f4:32:3c:63:b2 (p2, c1, k15).

I cant find what is wrong.
Thanks.