New platform for fan passing config from component to platform

I need a bit of help on figuring out how to pass config around between the component __init__.py and the platform.

Originally I started with just he platform of my device for the fan component and that worked fine.

Creating components/airscape/fan.py, defined PLATFORM_SCHEMA etc I was able to control the fan as expected. I decided that I wanted to create a custom service to speed_up and slow_down the fan. It’s a whole house fan and I want to incrementally adjust the speed based on the inside and outside temperature delta.

The only thing I need for the component is the two custom services I’m trying to add. Otherwise I would just leave it as a platform entity.

I started building out the __init__.py for the component and got stuck with how to get the config to the platform setup_platform from the component setup. In setup I make a call to hass.helpers.discover.load_platform using it’s required parameters. And I can see the config I want in config that was passed into setup. I pass that same config in load_platform But when setup_platform executes the config attribute is empty.

I’m not trying to define the config as a platform… declaring it directly in the configuration.yaml like:

airscape:
  name: Whole House Fan
  host: '192.168.10.10'

I would just like to declare the config as a fan entity using the airscape platform:

fan:
  - platform: airscape
    name: Whole House Fan
    host: '192.168.10.10'

The component __init__.py is still simple at this point. I haven’t add any of the service stuff. I am still trying to get the platform working by declaring it through load_platform

"""The Airscape component."""
import logging

_LOGGER = logging.getLogger(__name__)

DOMAIN = "airscape"

def setup(hass, config):
    """Set up is called when Home Assistant is loading our component."""
    
    hass.helpers.discovery.load_platform("fan", DOMAIN, {}, config)

    # Return boolean to indicate that initialization was successfully.
    return True

In setup I could stuff all the config in hass.data[DOMAIN] and then pull it back out in setup_platform, but that doesn’t seem like the right way to do that. It seems like since I can pass config into load_platform I should be able to get get it from config in setup_platform.

I’ve got the same issue…For me, I want to pass a config entry value from the top-level __init__.py to the sensor.py for my integration. The config dict is empty in the sensor.py setup_platform function. How can I get it to populate? Have you had any luck @barryq?

I never figured out why config was empty in setup_platform. My guess would be how the config is parsed at the component vs. platform level. I also never got a good answer as to what is the best way to get the config there, but based on lots of example code, it looks like people are just shoving things into hass.data[DOMAIN]. The other option would be to add data to the discovery_info passed into setup_platform

Thanks for your update…I’ve been looking over various integrations and see the same thing you state. I think I’ll take the discovery_info object approach as I don’t need this data to persist in global hass.data.

Hi,
i got the exact same problem. I’m trying to follow the example components on github, but none of them are really working.
the light example has a wrong configuration, and is missing the interesting parts of the implementation. the load platform example does not show how to read and forward config values. the other async examples are mostly just using init.py
I can’t find a good example that includes and explains a working component.

hey i’m just curious if you ever got your AirScape fan integrated to hass.io. I’m looking at a fan from them but it seems like they offer a propriety RJ-45 connected remote only which would be annoying if it didn’t integrate with my air-conditioning and furnace. Please reply here if you see this and let me know what model fan you used and how (at a high level) you integrated it. Thanks!

I was able to integrate the fan: GitHub - quielb/hass-airscape: A custom component to control a Airscape Whole House Fan with Gen2 controls

They do still sell the network controls. They just don’t list them on their website. If you want to order them you have to call them and place the order over the phone. If you get the network control add-on you can turn the fan on/off and set the speed with my HA component. It also allows to set the off timer, but that really doesn’t have a lot of value. The fan should be controlled based on the difference between the inside and outside temperature.

Which fan I have really isn’t relevant to you. I have a fan from the Sierra line (the one that supports the network controls) . But the fan you select should be based on the the SQ/ft of your home. And if you live in California, I think the current Title 24 requires 1.5CFM per SQ/ft. But you should verify that on your own.