Okay I found this:
def publish_mqtt_discovery(inverter):
mqtt_client.reconnect()
logging.info("Publish Home Assistant Discovery message")
SENSOR_TOPIC = 'inverter/tele/SENSOR'
DISCOVERY_TOPIC = 'homeassistant/sensor/inverter/{}/config'# energy/power
if "sungrow-" in options['model']:
manufacturer = 'Sungrow'
else:
manufacturer = 'SMA'
DISCOVERY_PAYLOAD = '{{"name": "Inverter {}", "uniq_id":"{}","stat_t": "{}", "json_attr_t": "{}", "unit_of_meas": "{}","dev_cla": "{}","state_class": "{}", "val_tpl": "{{{{ value_json.{} }}}}", "ic": "mdi:solar-power","device":{{ "name": "Solar Inverter","mf": "{}", "mdl": "{}", "connections":[["address", "{}" ]] }} }}'
energy_today_msg = DISCOVERY_PAYLOAD.format("Energy Today","inverter_energy_today", SENSOR_TOPIC, SENSOR_TOPIC, "kWh", "energy", "total_increasing", "daily_power_yield / 1000", manufacturer, options['model'], options['inverter_ip'])
energy_month_msg = DISCOVERY_PAYLOAD.format("Energy Monthly","inverter_energy_month", SENSOR_TOPIC, SENSOR_TOPIC, "kWh", "energy", "total_increasing", "monthly_power_yield / 1000", manufacturer, options['model'], options['inverter_ip'])
power_msg = DISCOVERY_PAYLOAD.format("Power", "inverter_power", SENSOR_TOPIC, SENSOR_TOPIC, "W", "power", "measurement","total_pv_power", manufacturer, options['model'], options['inverter_ip'], options['inverter_port'])
result = mqtt_client.publish(DISCOVERY_TOPIC.format("energy_today"), energy_today_msg)
result = mqtt_client.publish(DISCOVERY_TOPIC.format("energy_monthly"), energy_month_msg)
result = mqtt_client.publish(DISCOVERY_TOPIC.format("power"), power_msg)
result.wait_for_publish()
But what I now do not understand is: how does this autodiscovery Sensor bind to a value. Because there is no variable used…
Any help please…