Hi guys,
great thank to you all trying to explain it to me. Still, I feel a little bit dumb as it appears to be so easy for you guys and I still do not get it…
Oh, wait…while writing: may I have misunderstood the whole autodiscovery stuff? Is it HA sends configuration information to the device which configure themselves according to the payload in configuration topic???
I expected it the other way round- HA will poll (preconfigured) topics and based on this add the found devices.
So I need to tell my devices to listen to the configuration topic and update its state according to the configuration found there?
Still, I have to generate the script to define the topics and payloads for every 24 devices, right? My initial intension was so save typing and do some automated generation of the sensors, but the autodiscovery will not save typing, instead I will have more to type in the script…
If so I got it totally wrong and you can forget the following:
=====================snip===========
What did I get so far?
I need a script which generates some sort of entries in HA. There I have to define the configuration topics, right? So HA will then execute this script and the script will tell HA where to look for devices. Once a message has been posted in the configuration topic HA will poll the state topic for the sensor’s state and use this. Correct so far?
An example of such a script is this (thanks to @123 ):
script:
create_sensors:
alias: "Create sensors via MQTT Discovery"
sequence:
- service: mqtt.publish
data:
topic: homeassistant/sensor/temperatura_dnevna/config
retain: true
payload: >
{
"name": "Temperatura Dnevna",
"unique_id": "esp9_temperature_dneva",
"device_class": "temperature",
"unit_of_measurement": "°C",
"state_topic": "home/esp9/dnevna",
"value_template": "{{ value_json.temperatura }}",
"device": {
"identifiers": ["esp9"],
"name": "ESP9",
"model": "ESP",
"manufacturer": "Espressif",
"sw_version": "1.XX"
}
}
I am missing to things to understand completely:
First, where do I place the script and how is it executed? (may be a little bit off topic but will help)
Second, does the script mention all configuration topics? The above example will (as far as I understand) create a single entry to discover a sensor for temperature. So for a second sensor I have to add nearly the same to the above script (ie replace name and stuff in topic string), correct?
Or can I use some sort of variables in the script to tell them: “hey, do this twenty times and replace the variable for every run with the current run”? If not, I do not see advantage of the script compared to directly configure the sensors…
Ok, what Do I have so far? I will configure my script:
script:
create_sensors:
alias: "Create iforecast sensors via MQTT Discovery"
sequence:
- service: mqtt.publish
data:
topic: homeassistant/sensor/forecast_VARIABLE/config
retain: true
payload: >
{
"name": "Temperatura in VARIABLE hours",
"unique_id": "forecast_temp_VARIABLE",
"device_class": "temperature",
"force_update": "true",
"unit_of_measurement": "°C",
"state_topic": "home/forecast/VARIABLE/",
"value_template": "{{ value_json.temp }}",
"device": {
"identifiers": ["forecastVARIABLE"],
"name": "Forecast Temp VARIABLE",
}
}
Am I right about the devices itself do not need to do anything with the configuration topic as it is solely for HA? From what I see in the script it appears to me HA executes the script and sends the payload to the configuration topic…
/KNEBB