diff --git a/esphome/components/api/__init__.py b/esphome/components/api/__init__.py index c4d954bdd2..a0f66c3c80 100644 --- a/esphome/components/api/__init__.py +++ b/esphome/components/api/__init__.py @@ -148,8 +148,8 @@ async def to_code(config): if config.get(CONF_ACTIONS) or config[CONF_CUSTOM_SERVICES]: cg.add_define("USE_API_SERVICES") - # Set USE_API_HOMEASSISTANT_STATES if enabled or homeassistant component is loaded - if config[CONF_HOMEASSISTANT_STATES] or "homeassistant" in CORE.loaded_integrations: + # Set USE_API_HOMEASSISTANT_STATES if enabled + if config[CONF_HOMEASSISTANT_STATES]: cg.add_define("USE_API_HOMEASSISTANT_STATES") if actions := config.get(CONF_ACTIONS, []): diff --git a/esphome/components/homeassistant/__init__.py b/esphome/components/homeassistant/__init__.py index 223d6c18c3..7b23775b47 100644 --- a/esphome/components/homeassistant/__init__.py +++ b/esphome/components/homeassistant/__init__.py @@ -38,3 +38,4 @@ def setup_home_assistant_entity(var, config): cg.add(var.set_entity_id(config[CONF_ENTITY_ID])) if CONF_ATTRIBUTE in config: cg.add(var.set_attribute(config[CONF_ATTRIBUTE])) + cg.add_define("USE_API_HOMEASSISTANT_STATES")