Hi, my hassio worked fine untill update. Maybe someone can help me?
configuration.yaml
mqtt:
broker: 192.168.1.109
client_id: RaspberryPi3
switch:
- platform: mqtt
name: "Relay 99"
state_topic: "ha/Relay_99"
command_topic: "ha/Relay_99"
qos: 0
payload_on: "ON"
payload_off: "OFF"
optimistic: false
retain: true
ino file
#include <ESP8266WiFi.h>
#include <PubSubClient.h>
const char* ssid = "RIGHT_WIFI_SSID";
const char* password = "RIGHT_PASSWORD";
const char* mqtt_server = "192.168.1.109";
WiFiClient espClient;
PubSubClient client(espClient);
int RelayPin = 16;
String switch1;
String strTopic;
String strPayload;
void setup_wifi() {
delay(10);
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");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length)
{
payload[length] = '\0';
strTopic = String((char*)topic);
Serial.println(strTopic);
Serial.println((char*)payload);
if(strTopic == "ha/Relay_99")
{
switch1 = String((char*)payload);
if(switch1 == "ON")
{
Serial.println("Relay_99 ON");
digitalWrite(RelayPin, LOW);
}
else
{
Serial.println("Relay_99 OFF");
digitalWrite(RelayPin, HIGH);
}
}
}
void reconnect()
{
while (!client.connected())
{
Serial.print("Attempting MQTT connection...");
if (client.connect("NodeMCU"))
{
Serial.println("connected");
client.subscribe("ha/#");
}
else
{
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}
void setup()
{
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
pinMode(RelayPin, OUTPUT);
digitalWrite(RelayPin, HIGH);
}
void loop()
{
if (!client.connected())
{reconnect();}
client.loop();
}
AND Serial monitor
Connecting to RIGHT_WIFI_SSID
...........................
WiFi connected
IP address:
192.168.1.120
Attempting MQTT connection...connected
but switch doesn’t work
in switch status shows
September 27, 2020
11:41:05 PM
turned off
11:40:57 PM
changed to unavailable
Im try to find solution like one week, but i have no ideo and i decide to ask help
thanks