Hello folks,
i’m struggling with an add-on for which I want to allow the optional configuration of MQTT discovery templates, similar to this:
templates:
- name: tpl_blind
payload:
device_class: blind
payload_open: longup
payload_close: longdown
payload_stop: stop
optimistic: true
tilt_min: 0
tilt_max: 1
tilt_closed_value: 0
tilt_opened_value: 1
tilt_command_template: >-
{% set tilt = state_attr(entity_id, "current_tilt_position") %}{{ tilt
}}
But I don’t get past the schema definition. I defined an empty list within the options
, similar to the buttons
. When I leave out a schema for templates
, I can configure the block in YAML mode, but it does not show up in the final config[].
When I try to configure a schema entry for templates
I found no way to define an “arbitary list of key/value pairs”, as I do not know in advance what names/values will have to be configured for this template. I want to allow “any”.
How would I have to write that? Currently it’s
"options": {
"mediola": {
"host": "",
"password": ""
},
"mqtt": {
"host": "",
"port": 1803,
"username": "",
"password": "",
"discovery_prefix": "homeassistant",
"topic": "mediola",
"debug": false
},
"blinds": [ ],
"switches": [ ],
"buttons": [ ],
"templates": [ ]
},
"schema": {
"mediola": {
"host": "str",
"password": "str"
},
"mqtt": {
"host": "str",
"port": "int(0,65535)",
"username": "str",
"password": "password",
"discovery_prefix": "str",
"topic": "str",
"debug": "bool"
},
"blinds": [
{
"type": "match(ER|RT)?",
"adr": "str?",
"name": "str?",
"template": "str?"
}
],
"switches": [
{
"type": "match(IT|IR)?",
"adr": "str?",
"name": "str?",
"on_value": "str?",
"off_value": "str?"
}
],
"buttons": [
{
"type": "match(IT)?",
"adr": "str?"
}
]
}
I tried
"templates": [
{
"name": "str",
"payload": [ ]
}
]
but this rejects my intended configuration. So the question is: How do I “schema” the “payload” to accept the structure show on top?