Mqtt Temperature and humidity problem onHome assistant

Hi there,

I have configured a nodemcu with DHT22 and an oled ssd1306. I’m testing my server mqtt and i received those valor (in a loop):

/sensor1/tem: 31.3
/sensor1/hum: 46.3

I don’t know what’s the configuration.yaml to show those data, the data not show on my dashnoard (dismiss), here my last entry in configuration.yaml:

temperature:

  • platform: mqtt
    name: “Soggiorno”
    state_topic: “/sensor1/tem”
    value_template: “{{value_json.tem}}”

Thank you so much, forany help

Hi there.

Try the following:

sensor:
  - platform: mqtt
    name: "Soggiorno T"
    state_topic: "/sensor1/tem"
    unit_of_measurement: '°C'

  - platform: mqtt
    name: "Soggiorno H"
    state_topic: "/sensor1/hum"
    unit_of_measurement: '%'

Let us know how it goes.

Thank you for your reply.

Now i see the two icon on my dashboard but the data inside is null (image):
Sensor

My server mqtt receive the data in this format (image):

My configuration.yaml:

sensor:

  • platform: mqtt
    name: “Soggiorno T”
    state_topic: “/sensor1/tem”
    unit_of_measurement: ‘°C’

  • platform: mqtt
    name: “Soggiorno H”
    state_topic: “/sensor1/hum”
    unit_of_measurement: ‘%’

I’m asking, how HA know what is the part of data, (from data that sent my sensor) ?

Thank you so much, those forum is amazing!!!

Hello.

Have you configured already the mqtt platform in your configuration.yaml?

Here you have how to do it. In my case, my Mosquitto server is running in the same machine as HASS and configuration I have is:

mqtt:
  broker: !secret hass_ip
  port: 1883
  client_id: home-assistant-1
  keepalive: 60
  username: !secret mqtt_username
  password: !secret mqtt_password
  protocol: 3.1

This is how HASS knows where to pick up the MQTT data (from the topic where the data is published - which should be OK already).

First, thank you for your reply.

My mqtt work because i have sonoff switch connect with it. My problem is the data from sensor that i make:
Esp8266
Ssd1306
Dht22

I think that the problem is how my code publish the topic…

Ok, it ok now, the problem was that the topic it’s not correctly formatted, now the variable is TOPIC2 = “sensor1/hum”

Thank you for all your support!

B.r.

Hi mahnonsaprei,

Could you please post exactly how you formatted the configuration.yaml file, as I have same problem, and I do not quite understand you solution.

Dear,

here my yaml configuration:

  • platform: mqtt #Sensore temperatura nodemcu
    name: “Soggiorno Tem”
    state_topic: “sensor1/tem”
    unit_of_measurement: ‘°C’

  • platform: mqtt #Sensore umidità node mcu
    name: “Soggiorno Hum”
    state_topic: “sensor1/hum”
    unit_of_measurement: ‘%’