MQTT Setup - Autoscan for device doesn't do anything, NodeMCU v3

Hi,
I’m very sorry if its just me being to dumb to understand, but I just can’t figure out a way to connect my nodeMCU to my Home Assistant. The Assistant is running on a VM in a PVE and the mosquitto Add-on is my Broker. The Node has a config on it, is working correctly, is in the same WiFi, can actually connect and send data to the Broker, but it’s listed nowhere in my Assistant. My sensor in the configuration.yaml: (It’s a dht22)

sensor:
    - platform: mqtt
      name: "client_serverroom51temp"
      state_topic: "home/serverroom51/temperature"
      unit_of_measurement: 'C'
      
    - platform: mqtt
      name: "client_serverroom51hum"
      state_topic: "home/serverroom51/humidity"
      unit_of_measurement: '%'

I already tried and removed it, to see if I can’t find it because it’s already defined, but that’s not it.
my mqtt section:

mqtt:
    discovery: true
    broker: 127.0.0.1
    discovery_prefix: home
    username: myusername
    password: mypassword

Where do I have to look to find scanned devices? I can see in the mosquitto log that the authentication was successful, but no entitiy is shown. The sent topics are exactly how I tried the “state_topic” in the config.

Your indentation is off

sensor:
  - platform: mqtt
    name: "client_serverroom51temp"
    state_topic: "home/serverroom51/temperature"
    unit_of_measurement: 'C'
      
  - platform: mqtt
    name: "client_serverroom51hum"
    state_topic: "home/serverroom51/humidity"
    unit_of_measurement: '%'

My indentation is off? What do you mean?
This isn’t the actual code, I wrote it on kate, so I could copy it in here.
The original only uses Space, no tab

You need only 2 spaces, not 4

1 Like

Try what @francisp mentioned first.

My concern is that you are saying “Autoscan”.

What you have there is not based on MQTT discovery. So you should not expect anything to be “automatic” until there is a published message on either of those channels AFAIK.

You are using MQTT Sensor which is a manual integration.

It doesn’t matter on what operating system or text editor you wrote it in, if you ask for configuration help you really should be copying and pasting, as indentation issues (and human error) will break your sensors/configs!

Sorry, VIM won’t let me cut it, and ssh somehow fails, even if the Add on is installed, I don’t know what i am doing wrong, but this is the format in the config:

sensor:
  - platform: mqtt
    name: "client_serverroom51temp"
    state_topic: "home/serverroom51/temperature"
    unit_of_measurement: 'C'

  - platform: mqtt
    name: "client_serverroom51hum"
    state_topic: "home/serverroom51/humidity"
    unit_of_measurement: '%'

So it won’t scan on it’s own? Then how do i communicate on those Channels?

y"* or y"+ for your system clipboard is something you can try …
Or :! cat % to print the file out so you can use your mouse :man_shrugging:

I’ll apologize as the sensor will be added even without publishing to the topic!

image

*edit do you see this in your HA?

This is my .ino on the Node, if it helps

#include "DHT.h"
#include "ESP8266WiFi.h"
#include "PubSubClient.h"

#define DHTPIN D7
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

// WiFi
const char* ssid = "ssid";
const char* wifi_password = "password";

// MQTT
const char* mqtt_server = "172.24.110.253";
const char* humidity_topic = "home/serverroom51/humidity";
const char* temperature_topic = "home/serverroom51/temperature";
const char* mqtt_username = "mqtt-username";
const char* mqtt_password = "mqtt-password";
const char* clientID = "client_serverroom51";

// Initialise WiFi and MQTT Client
WiFiClient wificlient;
// Connect to Port 1883 on MQTT Broker (Mosquitto)
PubSubClient client(mqtt_server, 1883, wificlient);

void connect_mqtt() {
  Serial.print("Connecting to ");
  Serial.print(ssid);
  
  // Connecting to WiFi
  WiFi.begin(ssid, wifi_password);
  
  // Wait for WiFi auth
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(" . ");
  }
  
  delay(5000);
  
  // Show active Connection
  Serial.print("\n\nWiFi connected!");
  Serial.print("\nIP address: ");
  Serial.print(WiFi.localIP());
  Serial.print("\n");
  
  // Connect to MQTT Broker (Mosquitto)
  // client.connect returns bool to check if connection successfull == true or false
  if (client.connect(clientID, mqtt_username, mqtt_password)) {
    Serial.println("\nConnected to MQTT Broker!\n");
  } else {
    Serial.print("\nConnection to MQTT Broker failed. F\n");
  }
  
}

void setup() {
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  connect_mqtt();
  Serial.setTimeout(2000);
  
  float hum = dht.readHumidity();
  float temp = dht.readTemperature();
  
  // print the sensor stats every 5 sec
  Serial.print("\nHumidity: ");
  Serial.print(hum);
  Serial.print(" %\n");
  Serial.print("Temperature: ");
  Serial.print(temp);
  Serial.print(" °C\n");
  
  // MQTT only capable to transmit Strings
  String hums="Hum: "+String((float)hum)+" % ";
  String temps="Temp: "+String((float)temp)+" % ";
  
  // Publish data (Only Strings) to Broker
  // Temperature
  if (client.publish(temperature_topic, String(temp).c_str())) {
    Serial.print("\nTemperature sent...\n");
  } else {
    Serial.print("\nCouldn't send Temperature, try reconnecting and sending again...\n");
    client.connect(clientID, mqtt_username, mqtt_password);
    delay(10);
    client.publish(temperature_topic, String(temp).c_str());
  }
  
  // Humidity
  if (client.publish(humidity_topic, String(hum).c_str())) {
    Serial.print("\nHumidity sent...\n");
  } else {
    Serial.print("\nCouldn't send Humidity, try reconnecting and sending again...\n");
    client.connect(clientID, mqtt_username, mqtt_password);
    delay(10);
    client.publish(humidity_topic, String(hum).c_str());
  }
  
  //client.disconnect();
  delay(1000*60);
}

Make sure you have only one

sensor:

in your configuration.yaml.

If you are on 0.115.x, go to configuration -> server controls, and hit reload mqtt entities. If you are on a version before 0.115.0, restart HA.

image
This is all I have, no new entities

Jep, only one sensor:
And my version: 0.115.2

I think @francisp is on to something.

You must have something wrong with your configuration for the sensor to not be rendered.

Do you have any errors in your log?

Which one? Mosquitto is fine, is just tells me:

[INFO] found mqtt on Home Assistant
1600956243: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956266: Client client_serverroom51 has exceeded timeout, disconnecting.
1600956317: New connection from 172.24.109.72 on port 1883.
1600956317: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956339: Client client_serverroom51 has exceeded timeout, disconnecting.
1600956390: New connection from 172.24.109.72 on port 1883.
1600956390: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956412: Client client_serverroom51 has exceeded timeout, disconnecting.
1600956463: New connection from 172.24.109.72 on port 1883.
1600956463: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956486: Client client_serverroom51 has exceeded timeout, disconnecting.
1600956537: New connection from 172.24.109.72 on port 1883.
1600956537: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956559: Client client_serverroom51 has exceeded timeout, disconnecting.
1600956610: New connection from 172.24.109.72 on port 1883.
[INFO] found mqtt on Home Assistant
1600956611: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956633: Client client_serverroom51 has exceeded timeout, disconnecting.
1600956684: New connection from 172.24.109.72 on port 1883.
1600956684: New client connected from 172.24.109.72 as client_serverroom51 (p2, c1, k15, u'mqtt').
1600956707: Client client_serverroom51 has exceeded timeout, disconnecting.

The HA log:

[13:32:58] INFO: Start local supervisor watchdog...
20-09-24 13:32:59 INFO (MainThread) [__main__] Initialize Supervisor setup
20-09-24 13:32:59 INFO (MainThread) [supervisor.bootstrap] Initialize Supervisor Sentry
20-09-24 13:32:59 INFO (MainThread) [supervisor.bootstrap] Setup coresys for machine: qemux86-64
20-09-24 13:32:59 INFO (SyncWorker_0) [supervisor.docker.supervisor] Attach to Supervisor homeassistant/amd64-hassio-supervisor with version 245
20-09-24 13:32:59 INFO (MainThread) [__main__] Setup Supervisor
20-09-24 13:32:59 INFO (MainThread) [supervisor.host.info] Update local host information
20-09-24 13:32:59 INFO (MainThread) [supervisor.host.services] Update service information
20-09-24 13:32:59 INFO (MainThread) [supervisor.host.network] Update local network information
20-09-24 13:32:59 INFO (MainThread) [supervisor.host.sound] Update PulseAudio information
20-09-24 13:32:59 INFO (MainThread) [supervisor.host.apparmor] Load AppArmor Profiles: {'hassio-supervisor'}
20-09-24 13:32:59 INFO (MainThread) [supervisor.host.services] Reload local service hassos-apparmor.service
20-09-24 13:32:59 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/amd64-hassio-dns with version 9
20-09-24 13:32:59 WARNING (MainThread) [supervisor.plugins.dns] Ignore invalid DNS Server: dns://fe80::6238:e0ff:fed7:5a67
20-09-24 13:32:59 INFO (MainThread) [supervisor.plugins.dns] Start CoreDNS plugin
20-09-24 13:33:01 INFO (SyncWorker_0) [supervisor.docker.dns] Start DNS homeassistant/amd64-hassio-dns with version 9 - 172.30.32.3
20-09-24 13:33:01 INFO (MainThread) [supervisor.plugins.dns] Updated /etc/resolv.conf
20-09-24 13:33:01 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/amd64-hassio-audio with version 17
20-09-24 13:33:01 INFO (MainThread) [supervisor.plugins.audio] Start Audio plugin
20-09-24 13:33:03 INFO (SyncWorker_0) [supervisor.docker.audio] Start Audio homeassistant/amd64-hassio-audio with version 17 - 172.30.32.4
20-09-24 13:33:03 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/amd64-hassio-cli with version 26
20-09-24 13:33:03 INFO (MainThread) [supervisor.plugins.cli] Start cli plugin
20-09-24 13:33:05 INFO (SyncWorker_0) [supervisor.docker.cli] Start CLI homeassistant/amd64-hassio-cli with version 26 - 172.30.32.5
20-09-24 13:33:05 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/amd64-hassio-observer with version 3
20-09-24 13:33:05 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/amd64-hassio-multicast with version 3
20-09-24 13:33:05 INFO (MainThread) [supervisor.plugins.multicast] Start Multicast plugin
20-09-24 13:33:06 INFO (SyncWorker_0) [supervisor.docker.multicast] Start Multicast homeassistant/amd64-hassio-multicast with version 3 - Host
20-09-24 13:33:06 INFO (MainThread) [supervisor.updater] Fetch update data from https://version.home-assistant.io/stable.json
20-09-24 13:33:06 INFO (MainThread) [supervisor.homeassistant.secrets] Load Home Assistant secrets: 1
20-09-24 13:33:06 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/qemux86-64-homeassistant with version 0.115.2
20-09-24 13:33:06 INFO (MainThread) [supervisor.hassos] Detect HassOS 4.13 / BootSlot A
20-09-24 13:33:06 INFO (MainThread) [supervisor.store.git] Load add-on /data/addons/core repository
20-09-24 13:33:06 INFO (MainThread) [supervisor.store.git] Load add-on /data/addons/git/a0d7b954 repository
20-09-24 13:33:06 INFO (MainThread) [supervisor.store] Load add-ons from store: 66 all - 66 new - 0 remove
20-09-24 13:33:06 INFO (MainThread) [supervisor.addons] Found 4 installed add-ons
20-09-24 13:33:06 INFO (SyncWorker_1) [supervisor.docker.interface] Attach to esphome/esphome-hassio-amd64 with version 1.15.2
20-09-24 13:33:06 INFO (SyncWorker_2) [supervisor.docker.interface] Attach to homeassistant/amd64-addon-configurator with version 5.1.0
20-09-24 13:33:06 INFO (SyncWorker_0) [supervisor.docker.interface] Attach to homeassistant/amd64-addon-ssh with version 8.9.1
20-09-24 13:33:06 INFO (SyncWorker_3) [supervisor.docker.interface] Attach to homeassistant/amd64-addon-mosquitto with version 5.1
20-09-24 13:33:06 INFO (MainThread) [supervisor.snapshots] Found 0 snapshot files
20-09-24 13:33:06 INFO (MainThread) [supervisor.discovery] Load 1 messages
20-09-24 13:33:06 INFO (MainThread) [supervisor.ingress] Load 8 ingress session
20-09-24 13:33:06 INFO (MainThread) [__main__] Run Supervisor
20-09-24 13:33:06 INFO (MainThread) [supervisor.api] Start API on 172.30.32.2
20-09-24 13:33:06 INFO (MainThread) [supervisor.hassos] Rauc: A - marked slot kernel.0 as good
20-09-24 13:33:06 INFO (MainThread) [supervisor.addons] Phase 'AddonStartup.INITIALIZE' start 0 add-ons
20-09-24 13:33:06 INFO (MainThread) [supervisor.addons] Phase 'AddonStartup.SYSTEM' start 1 add-ons
20-09-24 13:33:08 INFO (SyncWorker_0) [supervisor.docker.addon] Start Docker add-on homeassistant/amd64-addon-mosquitto with version 5.1
20-09-24 13:33:09 INFO (MainThread) [supervisor.services.modules.mqtt] Set core_mosquitto as service provider for mqtt
20-09-24 13:33:13 INFO (MainThread) [supervisor.addons] Phase 'AddonStartup.SERVICES' start 1 add-ons
20-09-24 13:33:15 INFO (SyncWorker_1) [supervisor.docker.addon] Start Docker add-on homeassistant/amd64-addon-ssh with version 8.9.1
20-09-24 13:33:20 INFO (SyncWorker_0) [supervisor.docker.interface] Start homeassistant
20-09-24 13:33:21 INFO (MainThread) [supervisor.homeassistant.core] Wait until Home Assistant is ready
20-09-24 13:33:25 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 13:33:25 INFO (MainThread) [supervisor.auth] Home Assistant not running, check cache
20-09-24 13:33:25 INFO (MainThread) [supervisor.auth] Cache hit for mqtt
20-09-24 13:33:26 INFO (MainThread) [supervisor.homeassistant.api] Updated Home Assistant API token
20-09-24 13:33:26 INFO (MainThread) [supervisor.homeassistant.core] Detect a running Home Assistant instance
20-09-24 13:33:26 INFO (MainThread) [supervisor.addons] Phase 'AddonStartup.APPLICATION' start 2 add-ons
20-09-24 13:33:29 INFO (SyncWorker_2) [supervisor.docker.addon] Start Docker add-on homeassistant/amd64-addon-configurator with version 5.1.0
20-09-24 13:33:30 INFO (SyncWorker_3) [supervisor.docker.addon] Start Docker add-on esphome/esphome-hassio-amd64 with version 1.15.2
20-09-24 13:33:31 INFO (MainThread) [supervisor.api.security] /host/info access from a0d7b954_esphome
20-09-24 13:33:35 INFO (MainThread) [supervisor.misc.tasks] All core tasks are scheduled
20-09-24 13:33:35 INFO (MainThread) [supervisor.misc.hwmon] Started Supervisor hardware monitor
20-09-24 13:33:35 INFO (MainThread) [supervisor.core] Supervisor is up and running
20-09-24 13:33:35 INFO (MainThread) [supervisor.host.info] Update local host information
20-09-24 13:33:35 INFO (MainThread) [supervisor.host.services] Update service information
20-09-24 13:33:35 INFO (MainThread) [supervisor.host.network] Update local network information
20-09-24 13:33:35 INFO (MainThread) [supervisor.host.sound] Update PulseAudio information
20-09-24 13:39:32 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 13:39:32 INFO (MainThread) [supervisor.auth] Success login from mqtt
20-09-24 13:45:40 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 13:45:40 INFO (MainThread) [supervisor.auth] Success login from mqtt
20-09-24 13:51:47 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 13:51:48 INFO (MainThread) [supervisor.auth] Success login from mqtt
20-09-24 13:57:55 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 13:57:55 INFO (MainThread) [supervisor.auth] Success login from mqtt
20-09-24 14:04:03 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 14:04:03 INFO (MainThread) [supervisor.homeassistant.api] Updated Home Assistant API token
20-09-24 14:04:03 INFO (MainThread) [supervisor.auth] Success login from mqtt
20-09-24 14:10:10 INFO (MainThread) [supervisor.auth] Auth request from core_mosquitto for mqtt
20-09-24 14:10:11 INFO (MainThread) [supervisor.auth] Success login from mqtt

I Think your HA configuration.yaml is the issue, not your client NodeMCU

Think so, too. I’ll just get the whole config

1 Like

I don’t think you are supposed to see these :

Go to configuration → integrations → mqtt, click on configure

image

Under ‘Listen to a topic’, enter

home/serverroom51/#

and click 'start listening

What do you get ?

That’ what it gets.
And here (Sorry, like I said, don’t have a real terminal, only the Web Add on and can’t copy from that) is my config. But it should be okay, “Check config” said it’s valid

I think we have a winner!

1 Like

Yup, 2 times sensor: -> the first one gets ignored, the second one is empty.

1 Like

Mate, I dont know how to thank you. After 6 hours of searching, that was simply it.
Really, thank you man

1 Like