Understanding MQTT

I need some help with MQTT. I have it working in HA and a Node MCU and DHT22 sensor. When I added another NodeMCU and DHT22 sensor Im not getting the sensor data.
My first piece of code:

#define masterbed_humidity_topic “sensor/masterbed_humidity”
#define masterbed_temperature_topic “sensor/masterbed_temperature”


client.publish(masterbed_temperature_topic, String(temp).c_str(), true);
}

if (checkBound(newHum, hum, diff)) {
  hum = newHum;
  Serial.print("New humidity:");
  Serial.println(String(hum).c_str());
  client.publish(masterbed_humidity_topic, String(hum).c_str(), true);

HA only sees this as the temp & humidity.sensor

My second NodeMCU code is:
#define test_humidity_topic “sensor/test_humidity”
#define test_temperature_topic “sensor/test_temperature”


client.publish(test_temperature_topic, String(temp).c_str(), true);
}

if (checkBound(newHum, hum, diff)) {
  hum = newHum;
  // sensor 2
  Serial.print("New humidity:");
  Serial.println(String(hum).c_str());
  client.publish(test_humidity_topic, String(hum).c_str(), true);

HA does not see this at all.

my yaml file:
mqtt:
broker: 192.168.0.187
password: !secret mqtt
discovery: true
discovery_prefix: homeassistant
port: 1883
client_id: home-assistant-1

TEST BOARD

sensor 1:
platform: mqtt
name: “Temperature”
state_topic: “sensor/test_temperature”
qos: 0
unit_of_measurement: “ºF”

sensor 2:
platform: mqtt
name: “Humidity”
state_topic: “sensor/test_humidity”
qos: 0
unit_of_measurement: “%”

sensor 5:
platform: mqtt
name: “Temperature”
state_topic: “/sensor/masterbed_temperature”
qos: 0
unit_of_measurement: ‘°F’

sensor 6:
platform: mqtt
name: “Humidity”
state_topic: “/sensor/masterbed_humidity”
qos: 0
unit_of_measurement: ‘%’

Please point me in the right direction with MQTT

Off top of head look like u missing the user name for the mqtt

I have added username to mqtt.
nothing changed after restart.

I see the sensors, its just the sensor are always,
sensor.temperature
sensor.humidity
sensor.temperature_1
sensor.humidity_1

I thought that the publish name would be the sensor name. Is this wrong?

I’m not sure about your code but an easier option would be to use ESPhomeyaml. Add an mqtt server and DHT using just a yaml configuration file. e.g.

esphomeyaml:
  name: dining_dht
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: 'YOURSSID'
  password: !secret wifi_pwd  #supports secrets file.
  manual_ip:
    static_ip: 10.1.1.73 # static IP required for OTA updates
    gateway: 10.1.1.1
    subnet: 255.255.255.0

mqtt:
  broker: 10.1.1.100 # you could also try the new HA api.
  username: !secret mqtt_usr
  password: !secret mqtt_pwd

logger:
  # level: WARN # uncomment this after everything is working to reduce mqtt chatter.

ota:
  password: !secret esp_pwd #OTA updates!

binary_sensor:
  - platform: status
    name: "Dining Room DHT Status" # online /offline binary sensor

sensor:
  - platform: wifi_signal
    name: "Dining Room DHT WiFi Signal" #wifi received signal level sensor
    update_interval: 15s
    filters:
      - sliding_window_moving_average:
          window_size: 15
          send_every: 15
          send_first_at: 15

  - platform: dht
    pin: D5
    model: DHT22
    update_interval: 15s
    temperature:
      name: "Dining Room Temperature"
      filters:
        - sliding_window_moving_average: #using 15 sec update interval and this moving average the sensor updates about every 3 minutes.
            window_size: 15
            send_every: 15
            send_first_at: 15
    humidity:
      name: "Dining Room Humidity"
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
            send_first_at: 15


This mqtt config is also has home assistant discovery set by default. So your sensors should just show up in the mqtt integration.

Tom
Thanks for the reply. Im not familiar with the platform you are using.

My plan is to have ten NodeMCU + DHT sensors in the house. I currently have a Adafruit Huzzah ESP8266 outside using mqtt without any problems. But now I’m trying two nodemcu with problems. Its not going well.

When you flashed your NodeMCU devices did you give them each unique client ID’s?

Check out the how to. It’s an incredibly easy way to use just about every ESP board available and a whole bunch of supported sensors through a simple web interface and a yaml configuration file.

I just check all three of my sketches (using arduino) and they did have different client ID names. Just to be sure I changed them and reflashed the esp8266 boards. There is no change in HA.
To be clear. I have 3 boards and 3 sensors running with mqtt. 1 of them has a unique sensor name as flashed. Board 2 was also flashed with another unique sensor name, however HA is showing it as sensor.temperature & sensor.humidity.
Board 3 was to flashed with another unique sensor name, but HA is calling is sensor.temperature_1 & sensor.humidity_1

here is the yaml:
mqtt:
broker: 192.168.0.187
password: !secret mqtt
username: jon
discovery: true
discovery_prefix: homeassistant
port: 1883

TEST BOARD

sensor 1:
platform: mqtt
name: “Temperature”
state_topic: “sensor/test_temperature”
qos: 0
unit_of_measurement: “ºF”

sensor 2:
platform: mqtt
name: “Humidity”
state_topic: “sensor/test_humidity”
qos: 0
unit_of_measurement: “%”

EXTERIOR

sensor 3:
platform: mqtt
name: “Exterior Temperature”
state_topic: “sensor/exterior_temperature”
qos: 0
unit_of_measurement: “ºF”

sensor 4:
platform: mqtt
name: “Exterior Humidity”
state_topic: “sensor/exterior_humidity”
qos: 0
unit_of_measurement: “%”

MASTERBED

sensor 5:
platform: mqtt
name: “Temperature”
state_topic: “/sensor/masterbed_temperature”
qos: 0
unit_of_measurement: ‘°F’

sensor 6:
platform: mqtt
name: “Humidity”
state_topic: “/sensor/masterbed_humidity”
qos: 0
unit_of_measurement: ‘%’

SOLVED
I deleted the old sensor data from my mqtt yaml file.
Then I let HA reboot and force the discovery to run.
This found my missing sensors with the correct sensor names.
I now have 3 esp8266 boards with DHT22 sensors reporting.

Thanks for those who replied. It made me rethink the entire problem.