I have read a lot am I am using homeassistant for several years now, but I did not manage to add MQTT topics manually. Thats way easier with openhab.
So I have a python script sending messages via mqtt. It publishes p.ex.:
So topic is simon-server/acpitz-acpi-0
I now tried to work with the mqtt autodiscovery by sending a message:
topic: homeassistant/sensor/cpu_temp/config
payload:
{"availability":[{"topic":"simon-server/acpitz-acpi-0"}],"device":{"identifiers":["acpitz"],"manufacturer":"Asus","model":"simon j4205","name":"cpu","sw_version":"3000-0001"},"device_class":"temperature","enabled_by_default":true,"json_attributes_topic":"simon-server/acpitz-acpi-0","name":"simon cpu temperature","state_class":"measurement","state_topic":"simon-server/acpitz-acpi-0","unique_id":"cpu_simon","unit_of_measurement":"°C","value_template":"{{ value_json.temperature }}"}
Now I can see the device, but there are no entities. How to add them?
I also tried to add via configuration.yaml, but there is no such file in the relevant folder. The folder is named in the system configuration.
simon-itx:/docker/volumes/openhab/conf$ ls -lh
insgesamt 20K
drwxr-xr-x 3 9001 9001 3 Apr 24 14:30 automation
drwxr-xr-x 2 9001 9001 4 Apr 24 14:46 html
drwxr-xr-x 3 9001 9001 3 Apr 12 23:37 icons
drwxr-xr-x 2 9001 9001 3 Apr 24 14:46 items
drwxr-xr-x 2 9001 9001 4 Apr 24 14:46 persistence
drwxr-xr-x 2 9001 9001 3 Apr 24 14:46 rules
drwxr-xr-x 2 9001 9001 3 Apr 24 14:46 scripts
drwxr-xr-x 2 9001 9001 9 Apr 24 14:46 services
drwxr-xr-x 2 9001 9001 3 Apr 24 14:46 sitemaps
drwxr-xr-x 2 9001 9001 4 Apr 24 14:46 sounds
drwxr-xr-x 2 9001 9001 3 Apr 24 14:46 things
drwxr-xr-x 2 9001 9001 5 Apr 24 14:46 transform
francisp
(Francis)
2
Your screenshot shows {“temp1” : 64.0} so it should be
"value_template":"{{ value_json.temp1 }}"}
koying
(Chris B)
3
Additionally:
"availability": [
{
"topic": "simon-server/acpitz-acpi-0"
}
],
should be
"availability_topic": "simon-server/acpitz-acpi-0/<whatever topic>"
It must be a different topic whose content is, by default, online
or offline
"json_attributes_topic": "simon-server/acpitz-acpi-0",
It works (I guess), but doesn’t make sense as the only object in that topic is the state.
EDIT: Should be availability_topic
Many thanks. I now published:
{
"availability": "simon-server/acpitz-acpi-0/online",
"device": {
"identifiers": [
"acpitz2"
],
"manufacturer": "Asus",
"model": "simon j4205_",
"name": "cpu_temp",
"sw_version": "3000-0001"
},
"device_class": "temperature",
"enabled_by_default": true,
"json_attributes_topic": "simon-server/acpitz-acpi-0",
"name": "simon cpu temperature",
"state_class": "measurement",
"state_topic": "simon-server/acpitz-acpi-0",
"unique_id": "cpu_simon",
"unit_of_measurement": "°C",
"value_template": "{{ value_json.temp1 }}"
}
but still have this:
koying
(Chris B)
5
I don’t think you understood me (and I made a mistake myself, should be availability_topic
)
This is a working example (with abbreviations)
{
"uniq_id": "mqtt_sensor.temperature_humidity_sensor_0ef5_humidity",
"name": "Temperature Humidity Sensor 0Ef5 Humidity",
"stat_t": "ha_stream/sensor/temperature_humidity_sensor_0ef5_humidity/state",
"json_attr_t": "ha_stream/sensor/temperature_humidity_sensor_0ef5_humidity/attributes",
"avty_t": "ha_stream/sensor/temperature_humidity_sensor_0ef5_humidity/availability",
"dev_cla": "humidity",
"unit_of_meas": "%",
"stat_cla": "measurement",
"dev": {
"mf": "Xiaomi",
"mdl": "LYWSD03MMC",
"name": "Temperature/Humidity Sensor 0EF5",
"ids": [
"A4:C1:38:14:0E:F5"
]
}
}
Also, look in your HA log for possible errors.