Skip to main content
Glama

list_automations

Retrieve all configured Home Assistant automations with their IDs, entity IDs, states, and friendly names to monitor and manage smart home automation tasks.

Instructions

Get a list of all automations from Home Assistant

This function retrieves all automations configured in Home Assistant, including their IDs, entity IDs, state, and display names.

Returns: A list of automation dictionaries, each containing id, entity_id, state, and alias (friendly name) fields.

Examples: Returns all automation objects with state and friendly names

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Handler function for the 'list_automations' MCP tool. Registered via @mcp.tool(). Fetches automations using get_automations() helper and handles errors gracefully.
    @async_handler("list_automations")
    async def list_automations() -> List[Dict[str, Any]]:
        """
        Get a list of all automations from Home Assistant
        
        This function retrieves all automations configured in Home Assistant,
        including their IDs, entity IDs, state, and display names.
        
        Returns:
            A list of automation dictionaries, each containing id, entity_id, 
            state, and alias (friendly name) fields.
            
        Examples:
            Returns all automation objects with state and friendly names
        
        """
        logger.info("Getting all automations")
        try:
            # Get automations will now return data from states API, which is more reliable
            automations = await get_automations()
            
            # Handle error responses that might still occur
            if isinstance(automations, dict) and "error" in automations:
                logger.warning(f"Error getting automations: {automations['error']}")
                return []
                
            # Handle case where response is a list with error
            if isinstance(automations, list) and len(automations) == 1 and isinstance(automations[0], dict) and "error" in automations[0]:
                logger.warning(f"Error getting automations: {automations[0]['error']}")
                return []
                
            return automations
        except Exception as e:
            logger.error(f"Error in list_automations: {str(e)}")
            return []
  • Helper function that retrieves automation entities using get_entities('automation'), extracts relevant fields like id, entity_id, state, alias, and last_triggered.
    async def get_automations() -> List[Dict[str, Any]]:
        """Get a list of all automations from Home Assistant"""
        # Reuse the get_entities function with domain filtering
        automation_entities = await get_entities(domain="automation")
        
        # Check if we got an error response
        if isinstance(automation_entities, dict) and "error" in automation_entities:
            return automation_entities  # Just pass through the error
        
        # Process automation entities
        result = []
        try:
            for entity in automation_entities:
                # Extract relevant information
                automation_info = {
                    "id": entity["entity_id"].split(".")[1],
                    "entity_id": entity["entity_id"],
                    "state": entity["state"],
                    "alias": entity["attributes"].get("friendly_name", entity["entity_id"]),
                }
                
                # Add any additional attributes that might be useful
                if "last_triggered" in entity["attributes"]:
                    automation_info["last_triggered"] = entity["attributes"]["last_triggered"]
                
                result.append(automation_info)
        except (TypeError, KeyError) as e:
            # Handle errors in processing the entities
            return {"error": f"Error processing automation entities: {str(e)}"}
            
        return result

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/voska/hass-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server