custom-components / pyscript

Pyscript adds rich Python scripting to HASS
Apache License 2.0
894 stars 47 forks source link

Generate promote for AI conversation agent #611

Open itispip opened 4 months ago

itispip commented 4 months ago

With HA added Open AI, Google Gen AI as conversation agent, user now use Template in promote box to list out all rooms, device, entity for AI. Is that possible to be done by PyScript?

ALERTua commented 4 months ago

Without the examples I can only show you how to list all HA devices:

from homeassistant.helpers import device_registry
from homeassistant.helpers.device_registry import DeviceEntry
from typing import List

registry = device_registry.async_get(hass)
devices: List[DeviceEntry] = registry.devices.values()

The devices object is filled like so: https://github.com/home-assistant/core/blob/2024.6.4/homeassistant/helpers/device_registry.py#L977 The DeviceEntry object is described here: https://github.com/home-assistant/core/blob/2024.6.4/homeassistant/helpers/device_registry.py#L977