Problem with esphome and mqtt

Hi, i am running home assistant 2025.4.3.
I addedan ESP home device that reads 2 contacts and publish the value via mqtt.
in mqtt explorer i see the values changing. I added a yaml configuration for the 2 values, based on the topics I see in mqtt explorer.

- name: "pondWaterLevelHigh"
  unique_id : pondwaterlevelhigh
  state_topic: "DUMSHOME/PondWaterLevelControler/binary_sensor/levelhigh/state"
   
- name: "pondWaterLevelLow"
  unique_id : pondwaterlevellow
  state_topic: "DUMSHOME/PondWaterLevelControler/binary_sensor/levellow/state"

In my entities i see the 2 entoties as binary_sensor.pondwaterlevelhigh and binary_sensor.pondwaterlevellow.
Fort the 2 entities, when clicking on them, I see an error “The entity is unavailable”.

I am not able the use these entities in either a dashboard, nor in an Automation.

What Am I missing here ?

Hello Marc,

You have control over the topics if you wrote the ESPHome sketch.

I don’t know how you set HA to read the MQTT data.

I know of 2 ways. Create an MQTT sensor to read those topics, or a better way would be to send the data from ESPHome to a discovery topic directly and HA will just find them. If you created MQTT Sensors can you share the YAML?

Either way I suggest have retain on on these values so that it will not report an error in the logs at HA or device restart.

I created a yaml file, and the content is in the original topic, in the code section.
When I use Settings->Devices and Services and select Entities, I see both sensors.
I also see timestamps when the value changes, but there is the error message, and I am not able to use them anywhere else

Where exactly?

in my original configuration file I have the following

mqtt: 
  sensor: !include_dir_merge_list mqtt/sensor/
  binary_sensor: !include_dir_merge_list mqtt/binary_sensor/
  switch: !include_dir_merge_list mqtt/switch/
  light: !include_dir_merge_list mqtt/light/

thus in the folder mqtt/binary_sensor/. i have a file named pondwaterlevel.yaml with this content

- name: "pondWaterLevelHigh"
  unique_id : pondwaterlevelhigh
  state_topic: "DUMSHOME/PondWaterLevelControler/binary_sensor/levelhigh/state"
   
- name: "pondWaterLevelLow"
  unique_id : pondwaterlevellow
  state_topic: "DUMSHOME/PondWaterLevelControler/binary_sensor/levellow/state"

Oh wait, I am now back from Diner, and I made a refresh, and the error is gone. What is going on here ?

Ok.
What does the actual data look lile, the value that ESPHome is sending to the topic.

Just sending plain Text, ON or OFF, no Json. It’0s the default that ESPhome is using

Spoted something. You have this:

mqtt: 
  sensor: !include_dir_merge_list mqtt/sensor/
  binary_sensor: !include_dir_merge_list mqtt/binary_sensor/
  switch: !include_dir_merge_list mqtt/switch/
  light: !include_dir_merge_list mqtt/light/

I think MQTT is a list of dictionaries, so you need this:

mqtt: 
  - sensor: !include_dir_merge_list mqtt/sensor/
  - binary_sensor: !include_dir_merge_list mqtt/binary_sensor/
  - switch: !include_dir_merge_list mqtt/switch/
  - light: !include_dir_merge_list mqtt/light/

This is mine: Home-Assistant-Config/configuration.yaml at b2267fc32aadaae03fbd8e5649659d4afb75d259 · SirGoodenough/Home-Assistant-Config · GitHub
and this: Home-Assistant-Config/mqtt/binary_sensor/MQTT_bs_basement.yaml at b2267fc32aadaae03fbd8e5649659d4afb75d259 · SirGoodenough/Home-Assistant-Config · GitHub

If it’s suddenly working, you might need

Your configuration.yaml format ie still weird, though, so not sure there.