Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to select devices for large HomeAssistant Installations #75

Open
kidhasmoxy opened this issue Sep 16, 2023 · 1 comment
Open

Comments

@kidhasmoxy
Copy link

In the case of a large installation, the configure devices screen will never load because of the amount of data the hub has to process. Is there a way to blanket allow certain types of devices, like all switches, all lights, all binary sensors? Or perhaps it's better to have the option to only select specific devices.

The workaround is to get the entity id of each device and enter them in manually, but that can be tedious with 100 devices.

@masterHman
Copy link

I think the solution here is to use the "Templating" feature in Home Assistant.
NOTE: I have not yet been able to get the char encoding correct on the grovvy side and there might be another tweak or two needed in the template.

I am intentionally removing the Hubitat Entities to reduce cyclical events.
Here is the template I wrote:

{% set devices = states 
    | rejectattr('entity_id', 'in', integration_entities('hubitat'))   
    | rejectattr('state', 'eq', 'unavailable') 
    | map(attribute='entity_id')   
    | map('device_id') 
    | unique 
    | reject('eq',None)
    | list 
%}


{% set devices = states | rejectattr('entity_id', 'in', integration_entities('hubitat')) | rejectattr('state', 'eq', 'unavailable') | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list %} 
{%- set ns = namespace(devices = []) %} 
{%- for device in devices %} 
	{%- set entities = device_entities(device) | list %}
	{%- if entities %}
		{%- if device_attr(device, 'model') not in [ 'Home Assistant Add-on', 'Home Assistant Supervisor', 'Home Assistant Operating System','Home Assistant Core', 'theme', 'plugin', 'integration'] %} 
			{%- for entity in entities %} 
				{%- set ent = namespace(entity = [])%} 
				{%- set ent = namespace(attributes = [])%} 
				
				{% for attr in states[entity].attributes %} 
					{%- if attr in ('friendly_name', 'icon', 'device_class', 'assumed_state') -%} 
						{%- set ent.attributes = ent.attributes + [ { attr : states[entity].attributes[attr] }] %} 
					{%- endif %} 
				{%- endfor -%} 
				
				{%- set ent.entity = { 'entity_id': entity, 'state': states[entity].state, 'name': device_attr(device, 'name'), 'manufacturer': device_attr(device, 'manufacturer'), 'model': device_attr(device, 'model'), 'friendly_name': states[entity].attributes.friendly_name, 'attributes': ent.attributes } %} 
				{%- set ns.devices = ns.devices + [ent.entity] %} 
			{%- endfor %} 
		{%- endif %} 
	{%- endif %} 
{%- endfor %} 

{{ ns.devices }}

And instead of calling:
GET -> http://homeassistant.local:8123/api/states

You would instead call:
POST -> http://homeassistant.local:8123/api/template

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants