Thanks everybody! I was able to modify the script @123 wrote to work for my needs! As @koying mentioned, I think the dev object is key. It would be great to get the MQTT Configuration documentation updated, as I’m sure this is a common desire.
Also, let me apologize for not finding these previous conversations. I searched youtube, google, and some here in this forum, but it was difficult finding relevant information applicable to modern home assistant.
Just to recap what I did:
I created a scripts.yaml configuration file according to this page.
In configuration.yaml I added:
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
mqtt: !include mqtt.yaml
In this example, I’m configuring a Home Assistant to read sensor data from Honeywell Security Model 5816 Door/Window Sensor. The output from rtl_433 looks like this:
{
"time": "2023-06-27 01:02:18",
"model": "Honeywell-Security",
"id": 181554,
"channel": 8,
"event": 160,
"state": "open",
"contact_open": 1,
"reed_open": 1,
"alarm": 0,
"tamper": 0,
"battery_ok": 1,
"heartbeat": 0
}
In the new scripts.yaml file, I pasted the following code:
create_sensors:
alias: "Create sensors via MQTT Discovery"
sequence:
- service: mqtt.publish
data:
topic: homeassistant/sensor/dw181554reed/config
retain: true
payload: >
{
"name": "DW181554 Reed",
"unique_id": "dw181554_reed",
"state_topic": "rtl_433/Honeywell-Security/181554",
"value_template": {% raw %}"{{ value_json.reed_open }}"{% endraw %},
"device": {
"identifiers": ["dw181554"],
"name": "DW181554",
"model": "Model 5816",
"manufacturer": "Honeywell Security"
}
}
- service: mqtt.publish
data:
topic: homeassistant/sensor/dw181554tamper/config
retain: true
payload: >
{
"name": "DW181554 Tamper",
"unique_id": "dw181554_tamper",
"state_topic": "rtl_433/Honeywell-Security/181554",
"value_template": {% raw %}"{{ value_json.tamper }}"{% endraw %},
"device": {
"identifiers": ["dw181554"],
"name": "DW181554",
"model": "Model 5816",
"manufacturer": "Honeywell Security"
}
}
- service: mqtt.publish
data:
topic: homeassistant/sensor/dw181554contact/config
retain: true
payload: >
{
"name": "DW181554 Contact",
"unique_id": "dw181554_contact",
"state_topic": "rtl_433/Honeywell-Security/181554",
"value_template": {% raw %}"{{ value_json.contact_open }}"{% endraw %},
"device": {
"identifiers": ["dw181554"],
"name": "DW181554",
"model": "Model 5816",
"manufacturer": "Honeywell Security"
}
}
- service: mqtt.publish
data:
topic: homeassistant/sensor/dw181554battery/config
retain: true
payload: >
{
"name": "DW181554 Battery",
"unique_id": "dw181554_battery",
"state_topic": "rtl_433/Honeywell-Security/181554",
"value_template": {% raw %}"{{ value_json.battery_ok }}"{% endraw %},
"device": {
"identifiers": ["dw181554"],
"name": "DW181554",
"model": "Model 5816",
"manufacturer": "Honeywell Security"
}
}
- service: mqtt.publish
data:
topic: homeassistant/sensor/dw181554heartbeat/config
retain: true
payload: >
{
"name": "DW181554 Heartbeat",
"unique_id": "dw181554_heartbeat",
"state_topic": "rtl_433/Honeywell-Security/181554",
"value_template": {% raw %}"{{ value_json.heartbeat }}"{% endraw %},
"device": {
"identifiers": ["dw181554"],
"name": "DW181554",
"model": "Model 5816",
"manufacturer": "Honeywell Security"
}
}
The script can then be found in Home Assistant Settings > Automations & Scenes > Scripts. Just run it.
And the resulting device looks like this, with an entity for each sensor: