Configure max automations limit

This commit is contained in:
RmG152
2025-06-20 13:53:24 +02:00
parent 65df474438
commit 6cba44c3d5
12 changed files with 75 additions and 21 deletions

View File

@@ -45,6 +45,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
domains = call.data.get("domains", {})
entity_limit = call.data.get("entity_limit", 200)
automation_read_yaml = call.data.get("automation_read_yaml", False)
automation_limit = call.data.get("automation_limit", 100)
# Parse domains if provided as a string or dict
if isinstance(domains, str):
@@ -76,6 +77,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
coordinator.selected_domains = domains
coordinator.entity_limit = entity_limit
coordinator.automation_read_file = automation_read_yaml
coordinator.automation_limit = automation_limit
try:
await coordinator.async_request_refresh()
@@ -86,6 +88,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
coordinator.selected_domains = []
coordinator.entity_limit = 200
coordinator.automation_read_file = False
coordinator.automation_limit = 100
except KeyError:
raise ServiceValidationError("Provider configuration not found")

View File

@@ -131,6 +131,7 @@ class AIAutomationCoordinator(DataUpdateCoordinator):
self.selected_domains: list[str] = []
self.entity_limit = 200
self.automation_read_file = False # Default automation reading mode
self.automation_limit = 100
super().__init__(hass, _LOGGER, name=DOMAIN, update_interval=None)
self.session = async_get_clientsession(hass)
@@ -278,7 +279,7 @@ class AIAutomationCoordinator(DataUpdateCoordinator):
async def _build_prompt(self, entities: dict) -> str: # noqa: C901
"""Build the prompt based on entities and automations."""
MAX_ATTR = 500
MAX_AUTOM = 100 # Change this to user input?
MAX_AUTOM = getattr(self, "automation_limit", 100)
ent_sections: list[str] = []
for eid, meta in random.sample(

View File

@@ -13,7 +13,7 @@ generate_suggestions:
name: Custom Prompt
description: Optional custom prompt to override or enhance the default system prompt.
required: false
example: "Focus on energy-saving automations"
example: "Focus on energy-saving automations"
selector:
text:
multiline: true
@@ -22,20 +22,22 @@ generate_suggestions:
description: "If true, consider all entities instead of just new entities."
required: false
default: false
example: false
selector:
boolean: {}
domains:
name: Domains
description: "List of domains to consider. If empty, consider all domains."
required: false
default: {}
selector:
object: {}
default: {}
entity_limit:
name: Entity Limit
description: "Maximum number of entities to consider (randomly selected from the chosen domains)."
required: false
default: 200
example: 200
selector:
number:
min: 50
@@ -46,5 +48,17 @@ generate_suggestions:
description: "Reads and appends the yaml code of the automations found in the automations.yaml file. This action will use a lot of input tokens, use it with care and with models with a large input window (e.g. Gemini)."
required: false
default: false
example: false
selector:
boolean: {}
automation_limit:
name: Automation Limit
description: "Maximum number of automations to analyze (default: 100)."
required: false
default: 100
example: 100
selector:
number:
min: 10
max: 500
mode: slider

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "One or more values are invalid."
"invalid_input": "One or more values are invalid."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Read 'automations.yaml' file",
"description": "Reads and appends the yaml code of the automations found in the automations.yaml file. This action will use a lot of input tokens, use it with care and with models with a large input window (e.g. Gemini)."
},
"automation_limit": {
"name": "Automation Limit",
"description": "Maximum number of automations to analyze (default: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "Un o més valors són invàlids."
"invalid_input": "Un o més valors són invàlids."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Llegir arxiu 'automations.yaml'",
"description": "Llegeix i afegeix el codi yaml de les automatitzacions trobades a l'arxiu automations.yaml. Aquesta acció utilitzarà molts tokens d'entrada, utilitza-la amb cura i amb models amb una finestra d'entrada gran (ex. Gemini)."
},
"automation_limit": {
"name": "Límit d'automatitzacions",
"description": "Nombre màxim d'automatitzacions a analitzar (per defecte: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "Ein oder mehrere Werte sind ungültig."
"invalid_input": "Ein oder mehrere Werte sind ungültig."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Datei 'automations.yaml' lesen",
"description": "Liest und hängt den YAML-Code der in der Datei automations.yaml gefundenen Automatisierungen an. Diese Aktion verbraucht viele Eingabe-Tokens. Verwenden Sie sie mit Bedacht und mit Modellen mit einem großen Eingabefenster (z.B. Gemini)."
},
"automation_limit": {
"name": "Automatisierungslimit",
"description": "Maximale Anzahl der zu analysierenden Automatisierungen (Standard: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "One or more values are invalid."
"invalid_input": "One or more values are invalid."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Read 'automations.yaml' file",
"description": "Reads and appends the yaml code of the automations found in the automations.yaml file. This action will use a lot of input tokens, use it with care and with models with a large input window (e.g. Gemini)."
},
"automation_limit": {
"name": "Automation Limit",
"description": "Maximum number of automations to analyze (default: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "Uno o más valores son inválidos."
"invalid_input": "Uno o más valores son inválidos."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Leer archivo 'automations.yaml'",
"description": "Lee y añade el código yaml de las automatizaciones encontradas en el archivo automations.yaml. Esta acción usará muchos tokens de entrada, úsala con cuidado y con modelos con una ventana de entrada grande (ej. Gemini)."
},
"automation_limit": {
"name": "Límite de automatizaciones",
"description": "Número máximo de automatizaciones a analizar (por defecto: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "Uno o più valori non sono validi."
"invalid_input": "Uno o più valori non sono validi."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Leggi file 'automations.yaml'",
"description": "Legge e aggiunge il codice yaml delle automazioni trovate nel file automations.yaml. Questa azione utilizzerà molti token di input, usala con cautela e con modelli con una grande finestra di input (es. Gemini)."
},
"automation_limit": {
"name": "Limite automazioni",
"description": "Numero massimo di automazioni da analizzare (predefinito: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "Een of meer waarden zijn ongeldig."
"invalid_input": "Een of meer waarden zijn ongeldig."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Lees 'automations.yaml' bestand",
"description": "Leest en voegt de yaml-code van de automatiseringen in het bestand automations.yaml toe. Deze actie zal veel input tokens gebruiken, gebruik het voorzichtig en met modellen met een groot input venster (bijv. Gemini)."
},
"automation_limit": {
"name": "Automatiseringslimiet",
"description": "Maximum aantal te analyseren automatiseringen (standaard: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "Одно или несколько значений недействительны."
"invalid_input": "Одно или несколько значений недействительны."
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "Прочитать файл 'automations.yaml'",
"description": "Читает и добавляет yaml-код автоматизаций, найденных в файле automations.yaml. Это действие будет использовать много входных токенов, используйте его осторожно и с моделями с большим окном ввода (например, Gemini)."
},
"automation_limit": {
"name": "Лимит автоматизаций",
"description": "Максимальное количество автоматизаций для анализа (по умолчанию: 100)."
}
}
}
}
}
}

View File

@@ -191,7 +191,7 @@
}
},
"error": {
"invalid_input": "一个或多个值无效。"
"invalid_input": "一个或多个值无效。"
}
},
"services": {
@@ -222,8 +222,12 @@
"automation_read_yaml": {
"name": "读取 'automations.yaml' 文件",
"description": "读取并附加 automations.yaml 文件中找到的自动化的 yaml 代码。此操作将使用大量输入令牌,请谨慎使用并配合具有较大输入窗口的模型(例如 Gemini。"
},
"automation_limit": {
"name": "自动化数量上限",
"description": "要分析的自动化最大数量默认100。"
}
}
}
}
}
}