[SOLVED] MQTT not working in custom component

I am new to HASS development, trying to find my way, and getting to the point where I have a working custom component which integrates with my MQTT based device for plant watering.

When I just plain try to subscribe to a topic within async_setup_entry, I will get the following error in the log while starting HASS:

2023-01-20 17:16:01.281 INFO (MainThread) [homeassistant.setup] Setup of domain mqtt took 0.0 seconds
2023-01-20 17:16:01.283 INFO (MainThread) [homeassistant.setup] Setting up met
2023-01-20 17:16:01.283 INFO (MainThread) [homeassistant.setup] Setup of domain met took 0.0 seconds
2023-01-20 17:16:01.284 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.energy
2023-01-20 17:16:01.287 INFO (MainThread) [homeassistant.setup] Setting up binary_sensor
2023-01-20 17:16:01.287 INFO (MainThread) [homeassistant.setup] Setup of domain binary_sensor took 0.0 seconds
2023-01-20 17:16:01.287 INFO (MainThread) [homeassistant.setup] Setting up smart_watering
2023-01-20 17:16:01.287 WARNING (MainThread) [homeassistant.components.smart_watering] async_setup
2023-01-20 17:16:01.288 INFO (MainThread) [homeassistant.setup] Setup of domain smart_watering took 0.0 seconds
2023-01-20 17:16:01.289 WARNING (MainThread) [homeassistant.components.smart_watering] async_setup_entry
2023-01-20 17:16:01.289 INFO (SyncWorker_3) [homeassistant.loader] Loaded notify from homeassistant.components.notify
2023-01-20 17:16:01.292 INFO (MainThread) [homeassistant.setup] Setting up tts
2023-01-20 17:16:01.292 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.smart_watering
2023-01-20 17:16:01.297 INFO (MainThread) [homeassistant.setup] Setting up mobile_app
2023-01-20 17:16:01.297 WARNING (MainThread) [homeassistant.components.smart_watering.binary_sensor] Adding sensor True
2023-01-20 17:16:01.297 WARNING (MainThread) [homeassistant.components.smart_watering] register sensor
2023-01-20 17:16:01.298 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/home/s710/Development/HomeAssistant/core/homeassistant/components/mqtt/client.py", line 211, in async_subscribe
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: Cannot subscribe to topic 'ha/smart_watering/status/0x2341234', MQTT is not enabled

I am starting HASS from the developer venv using hass -c config, where config/configuration.yaml contains:

mqtt:
  broker: myMqttHost
  birth_message:
    topic: 'hass/status'
    payload: 'online'
  will_message:
    topic: 'hass/status'
    payload: 'offline'

Also, from the log you can see that MQTT is actually set up before the custom component. I have mqtt in the dependencies list of manifest.json. So it should be available?!

When I add code to wait for MQTT (as done in the snips integration, found via google), like this:

async def async_setup(hass: HomeAssistant, config: Config) -> bool:
    """Set up using yaml config file."""

    _LOGGER.warn("async_setup")

    coordinator = SmartWateringCoordinator(hass)
    hass.data[DOMAIN] = coordinator

     # Make sure MQTT is available and the entry is loaded

    if not hass.config_entries.async_entries(mqtt.DOMAIN):
        _LOGGER.error("MQTT integration is not available 1 {}".format(mqtt.DOMAIN))
        return False

    if not await hass.config_entries.async_wait_component(hass.config_entries.async_entries(mqtt.DOMAIN)[0]):
        _LOGGER.error("MQTT integration is not available 2")
        return False

    return True

I will get:

2023-01-20 18:06:00.231 INFO (MainThread) [homeassistant.setup] Setting up smart_watering
2023-01-20 18:06:00.231 WARNING (MainThread) [homeassistant.components.smart_watering] async_setup
2023-01-20 18:06:00.231 ERROR (MainThread) [homeassistant.components.smart_watering] MQTT integration is not available 1 mqtt

Why is MQTT not available? What do I need to do?

Found it out myself. Turns out I need to configure the MQTT integration in lovelace. Having the mqtt: in configuration.yaml does not have any effect.