Hello there,
I was wondering if there is a way to get a list of devices by integration in a template.
For example, I want to loop over all my Tasmota switches and check for the signal strength without having to list them one by one.
or I want to loop over all my DeCONZ lights and turn them off.
The Home Assistant UI clearly knows the Integration each entity and device belongs to, do we have access to this property?
Thanks,
This is how I did it but I figured there has to be a more generic way.
I don’t like defining things manually, It makes the process of adding devices in the future more complicated, and I tend to forget after a few months.
I might be able to get the list through a command-line sensor, this is what I am currently exploring.
To be honest, I don’t care so much about doing it manually, I mean it’s not like I add new devices on a daily basis. Also your approach will only work if you buy the same kind of device, what if you have some lights with deconz and some with lifx? Or you want to check sinbal strength from a non-Tasmota device? Then you anyway need to edit it manually.
Also for the deconz example, it’s more reliable and efficient to create groups in deconz and use these to turn oo/off lights than to each individual bulb (which can lead to lost/delayed messages and therfore lights not turning on/off).
Hi Buddy,
The examples I gave are just for simplicity.
I do have more than one type of light, I actually have 4 different types (2 of them are custom integration that I wrote myself)
The actual reason is to get a list of all “wireless” devices and check their signal and availability and get a notification when a device disconnects.
I figured that my example will divert the conversation in a direction that is not relevant to the question.
I was able to access the Integration Data from the following sensor I created:
sensor:
- platform: command_line
name: Entity Registry
value_template: "{{ value_json.data.entities | length}}"
command: "cat /config/.storage/core.entity_registry"
scan_interval: 3600 #(default is 60- every minute)
json_attributes:
- data
It works, but I don’t like this solution since it overloads the states inside the hass object with 250kb of extra data.
I tried to create automatic groups via a python script but Home Assistant runs a restricted version of python that has no file system access.
My next effort would be running an external python script as a service and calling on startup to get the required information to create Groups based on the entity’s integration.
My solution above works, but I switched to NodeRed since and recommended you do the same.
Writing templates is not a good framework for managing automations.
Debugging your tricks and workarounds years after you wrote them is hard and cannot be maintained properly over time.
Once you find yourself trying to write simple things in complicated ways, it’s a sign you should switch platforms.
The integration devices page knows all the details:
It even contains a link to the device. So I’d like to have this in a dashboard. Apparently, HA has it somwhere. The file /config/.storage/core.entity_registry you’re grepping does not contain e. g. the IP address.
You can also get it easily,
It is available in an SQL database registry and also in the Home Assistant API.
Both methods are super easy to access in NodeRed, if you got to a point that you need to write complicated templates, it’s time to start writing your automations elsewhere.
2 years ago, when I posted this thread, I was at a similar position. NodeRed was my solution.
Yes, there is! The first example below will give you a list of all entity_ids related to the Tasmota integration, the second example will convert that list into device_ids:
{{ integration_entities('tasmota') }}
{{ integration_entities('tasmota') | map('device_id') | list }}
Simple as that!
UPDATED: I change the integration identifier to lower case, since it appears that is the standard. Not all integrations names in the UI match the identifier used in HA, so here’s a link to a post by petro detailing how to find the proper integration identifiers using a template: