I have 2 MQTT devices. 1 commercial and 1 home made. Both send their info to my MQTT broker and I see the data with a MQTT explorer. The commercial device is recognized by HA and I can create graphs.
My objective is to combine tempreature data from both devices in a graph.
The home made device does not support discovery and I try to do it manualy via the configuration option under MQTT integration.
Under Publish a packet I add the following information
Topic: homeassistant/sensor/Sensors-12/Sensor01/Zone-1/config
payload:
My expectation is to find an entity Sensors-12_zone-1 depicting the temperature. But the data is not appearing. I have no errors in the log. The configuration data is depicted in my MQTT explorer.
Any help would be appreciated
discovery topic is for meta data only. It contains information about a location of actual data. The actual data might be located anywhere else in this mqtt.
update: still not working…
I changed the message to Sensors-12/Zone-1 etc
Topic: homeassistant/sensor/Sensors-12/Zone-1/config
Payload
{
"name": "Water temperature Zone 1",
"unique_id": "Sensors-12_Zone-1",
"object_id": "Sensors-12_Zone-1",
"icon": "mdi:thermometer-lines",
"state_topic": "Sensors-12/Zone-1",
"unit_of_measurement": "°C",
"device": {
"name": "Sensors-12",
"identifiers": "Sensor-12",
}
}
I see the new config in MQTT explorer but cannot add it as entity to graph.
Any suggestions?
which is not the topic @warthog618 was talking about.
Change your state topic and device topic back, and only alter the discovery topic. I.e. Only change this topic: homeassistant/sensor/Sensors-12/Zone-1/config
Thanks to all, it’s working!
One more question. As you can see I have 12 sensors. Is there a way to publish them in one go? or should I publish 12 times?
Thanks for all the tips. I was able to configure my 12 sensors (one by one). Unfortunately, after a reboot all sensors indicate ‘unavailable’. They also don’t accept the next value. It can be resolved by by publishing again
If I understand well, I have to use the retain flag and created the following payload
If you are generating the config messages manually then you may as well define them in the configuration.yaml. Though according to the documentation the device section only works via MQTT discovery - not from the config file.
Otherwise you either need to publish the config with retain, or if you have an active element publishing them then subscribe to the HA birth message and republish the config when HA goes online.
Similarly with the sensor state - they need to be retain or republished after HA has had a chance to process the config, be it from the configuration.yaml or the republish. If the state is being published regularly then that might be good enough.
I’ve used both approaches, with my current preference being the republish - otherwise everything ends up being retain which is poor MQTT form, AIUI.
Since the Christmas break I working on my Home assistant project and have to admid, regarding the documentation, some additional information might be helpful. I intend to document my learning as input for improvement once I have finished.
My sensors provide data every 60 seconds, so there is no need to use the retain option.
My issue is to create persistant sensor configurations. I’m able to create them manual (via integrations / configure option) but they are gone after a reboot. So, I try to define the sensors in configuration file.
Unfortunately, the documentation is ambiguous. Sometimes I see
# Example configuration.yaml entry
mqtt:
sensor:
- state_topic: "home/bedroom/temperature"
Alternatively
sensor:
- platform: mqtt
name: "Water temperatuur zone 1"
unique_id: "Sensors-12_zone-1"
object_id: "Sensors-12_zone-1"
icon: "mdi:thermometer-lines"
state_topic: "Sensors-12/Sensor01/Zone-1"
My intend is to configure my 12 sensors and the device
Any example would be great.
The MQTT config format changed in 2022.12. Refer to the breaking changes MQTT in the 2022.12 release notes.
The current doc for MQTT sensor is correct - that corresponding to the first form. The alternate is the old form, which is no longer supported as of 2022.12. Have you tried the first form and it didn’t work for you?
e.g.
mqtt:
sensor:
- name: "Water temperatuur zone 1"
unique_id: "Sensors-12_zone-1"
object_id: "Sensors-12_zone-1"
icon: "mdi:thermometer-lines"
state_topic: "Sensors-12/Sensor01/Zone-1"
Thanks for the tip, a game changer! This code is working. (If you are not sloppy with using capitals. So there is a difference between Mqtt and mqtt. Same for Sensor and sensor. my mistake)
mqtt:
sensor:
- name: "Water temperatuur zone 1"
state_topic: "Sensors-12/Sensor01/Zone-1"
unique_id: "Sensors-12_zone-1"
object_id: "Sensors-12_zone-1"
icon: "mdi:thermometer-lines"
unit_of_measurement: "°C"
device: {
name: "Sensors-12",
manufacturer: "Maarten",
model: "Sensors-12",
identifiers: "Sensors-12"
}
- name: "Water temperatuur zone 2"
......
Disadvantage is my configuration file gets big. Will look for an ‘include’ option.