Help with Understanding a specific Addon

Hello,

I’ve got found a good and working Addon for my Solar Inverter. But I’m missing some entities to get all data I need, so I tried to look how to add them but couldn’t figure out how it is done. The Code seems different then how it is shown in the development Docs.

So I would be very happy, if someone can give be some help:

It is this Addon
It Creates a MQTT device and adds 3 entities:

I can’t find the location where the entities are defined.

Thank you very much for your help!

Probably through mqtt auto-discovery.

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…

This must be filled somewhere, not in the discovery message, but where the values are published.

Yes I’ve choosen this Inverter. That is the data collected by the Addon.
The corresponding values are:

  • daily_power_yield

  • monthly_power_yield

  • total_pv_power

Some of the choosable Inverters have one of this 3. But my has only one (total_pv_power). And no Inverter gives all 3 values…