Is there any way currently to get a list of entity aliases from either the websocket or rest API?
Bump, hoping someone can help, please.
I need this too, Planning to amend my adaptor between my home assistant and alexa
Bump.
If this could be added then Rhasspy (and maybe other services?) would be able to dynamically load slots from device aliases, isn’t that supposed to be what the alias feature is for?
If they could just be added to entity state that would work fine, we could use them in templates too that way.
Any solution here? It’s annoying to have parts of an entity locked inside HA without API access.
Hi, sorry been away for a bit but actually yeah I did solve it. The python script below works to get a list of entities and aliases. It’s designed to be run on a Rhasspy 2.5 system but that’s really just to read the HA API key from the config. It can easily be adjusted to hard code it or read it from somewhere else. Basically it first compiles a list of devices using the device registry. Then it pulls the entity registry and list names and aliases found. It does it’s best to behave to the hidden flag as well.
#!/bin/sh
''''exec python3 -u -- "$0" ${1+"$@"} # '''
# vi: syntax=python
import asyncio
import json
import os
import sys
try:
import asyncws
except ImportError:
print("Trying to Install required module: asyncws\n")
os.system('python3 -m pip install asyncws')
import asyncws
with open(os.environ["RHASSPY_PROFILE_DIR"] + "/profile.json", "r") as f:
config = json.load(f)["home_assistant"]
token = config["access_token"]
url = config["url"].replace("http:", "ws:") + "/api/websocket"
@asyncio.coroutine
def work():
tranNum = 10
websocket = yield from asyncws.connect(url)
msg = yield from websocket.recv()
assert json.loads(msg)["type"] == "auth_required"
yield from websocket.send(
json.dumps({"type": "auth", "access_token": token})
)
msg = yield from websocket.recv()
assert json.loads(msg)["type"] == "auth_ok"
yield from websocket.send(
json.dumps({"id": tranNum, "type": "config/device_registry/list"})
)
msg = yield from websocket.recv()
response = json.loads(msg)
assert response["success"]
tranNum = tranNum + 1
device_registry = response["result"]
yield from websocket.send(
json.dumps({"id": tranNum, "type": "config/entity_registry/list"})
)
msg = yield from websocket.recv()
response = json.loads(msg)
assert response["success"]
tranNum = tranNum + 1
entity_registry = response["result"]
for entity in entity_registry:
if len(sys.argv) > 1:
entity_id = entity['entity_id']
entity_domain = entity_id[:entity_id.find('.')]
for arg in sys.argv:
if entity_domain == arg:
hadevice = next((device for device in device_registry if device['id'] == entity['device_id']), None)
if hadevice == None:
print(f"({entity['original_name']}):{entity['entity_id']}")
if entity['name'] != None:
if len(entity['name']) > 0:
print(f"({entity['name']}):{entity['entity_id']}")
else:
if hadevice['name_by_user'] != None:
print(f"({hadevice['name_by_user']}):{entity['entity_id']}")
else:
print(f"({hadevice['name']}):{entity['entity_id']}")
if entity['name'] != None:
if len(entity['name']) > 0:
print(f"({entity['name']}):{entity['entity_id']}")
if entity['original_name'] != None:
if len(entity['original_name']) > 0:
print(f"({entity['original_name']}):{entity['entity_id']}")
yield from websocket.send(
json.dumps({"id": tranNum, "type": "config/entity_registry/get", "entity_id": entity['entity_id']})
)
msg = yield from websocket.recv()
response = json.loads(msg)
assert response["success"]
tranNum = tranNum + 1
entity_details = response["result"]
if 'aliases' in entity_details.keys():
print("aliases")
for alias in entity['aliases']:
print(f"({alias}):{entity['entity_id']}")
else:
print(f"({entity['original_name']}):{entity['entity_id']}")
asyncio.get_event_loop().run_until_complete(work())
asyncio.get_event_loop().close()