Hi!
Hope it’s ok to reactivate this old thread, seems like you have a lot of knowledge on this topic and I’m out of options after trying all things found here in the forum.
I’m setting up an Arduino with ArduinoHA and MQTT Mosquitto in Home Assistant. Using a boilerplate for ArduinoHA first try was a success, my device and entity showed up in HA. But after I renamed the device in Arduino nothing happened in Home Assistant. So I deleted the device and entities in HA hoping it would re-add again… After this, it won’t show up again.
My setup:
Arduino side using ArduinoHA lib. Discovery message is built into the HAMqtt:begin
or HAMqtt:loop
command. The stripped version of my code to show MQTT setup:
#include <WiFiNINA.h>
#include <ArduinoHA.h>
#define LED_PIN 2
#define BROKER_ADDR "192.168.0.161"//IPAddress(192,168,0,161)
#define MQTT_USER "ccc"
#define MQTT_PASS "xxx"
#define WIFI_SSID "xxx"
#define WIFI_PASSWORD "zzz"
WiFiClient client;
HADevice device(mac, sizeof(mac));
HAMqtt mqtt(client, device);
HASwitch openPatio("home/patio/open");
/*********************************
** FUNCTION MQTT callback on message
**********************************/
void onMessage(const char* topic, const uint8_t* payload, uint16_t length) {
Serial.print("MQTT message recieved on topic: ");
}
/*********************************
** FUNCTION MQTT callback on connect
**********************************/
void onConnected() {
Serial.println("MQTT connection established.");
openPatio.setAvailability(true);
mqtt.subscribe("home/patio/open");
}
/*********************************
** FUNCTION MQTT switch-callback on command
**********************************/
void onSwitchCommand(bool state, HASwitch* sender)
{
Serial.println("MQTT command recieved.");
}
/*********************************
** SYSTEM SETUP
**********************************/
void setup() {
Serial.begin(9600);
// Declare pins:
pinMode(LED_PIN, OUTPUT);
// Connect to wifi hidden for this purpose
// set device's details (optional)
device.setName("PatioCTRL");
device.setSoftwareVersion("1.0");
// handle switch state
openPatio.onCommand(onSwitchCommand);
openPatio.setName("open_patio");
openPatio.setRetain(true);
//Set up callbacks
mqtt.onMessage(onMessage);
mqtt.onConnected(onConnected);
//Set login credentials
mqtt.begin(BROKER_ADDR, 1883, MQTT_USER, MQTT_PASS);
}
/*********************************
** SYSTEM MAIN LOOP
**********************************/
void loop() {
mqtt.loop();
delay(100);
openPatio.setState(true); //just testing...
delay(1000);
openPatio.setState(false); //just testing...}
The topic is shown in MQTT explorer as expected and toggle its value in aha>ecxxx>home etc. See picture:
But in Home Assistant it is empty in the Mosquitto Broker add-on.
So far, I’ve tested:
- Restarting HA and arduino, of course…
- Deleting and adding topics
- Made sure Arduino sends messages and config message
- Made sure discovery prefix is right
- Made sure auto discovery is enabled in Mosquitto
- Nothing in any logs are showing any leads
- The device/entity is correctly removed from core.entity_registry
- I’ve also tried from HA to activate the device by adding a HA-script to publish a config message:
mqtt_test:
alias: "Test MQTT Discovery"
sequence:
- service: mqtt.publish
data:
topic: homeassistant/switch/ec626081039c/home/patio/open/config
retain: true
payload: >
{
"name": "open_patio",
"device_class": "switch",
"uniq_id": "home/patio/open",
"ic": "mdi:lightbulb",
"ret": true,
"payload_on": "1",
"payload_off": "0",
"dev": {
"ids": "ec626081039c",
"name": "PatioCTRL",
"sw": "1.0"
}
"avty_t": "aha/ec626081039c/home/patio/open/avty_t",
"stat_t": "aha/ec626081039c/home/patio/open/stat_t",
"cmd_t": "aha/ec626081039c/home/patio/open/cmd_t"
}
But it didn’t help either. The message is received in MQTT Explorer and updates the config topic with some small changes compared to the one sent from Arduino.
Does anyone know what I can do to rediscover the device and entity?