Getting a list of all devices from a specific integration in a template (all Tasmota switches or DeCONZ lights)

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?

Thank you

1 Like

You can’t access this property currently. The only thing you can do is to put them all in a group and evaluate all members of this group afterwards.

1 Like

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.

It’s still manual but you can add custom attributes to your entities:

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.

1 Like

I managed to reduce the JSON even more:

  - platform: command_line
    name: Entity Registry
    value_template: "{{ value_json.data.entities | length}}"
    command: "egrep -w 'original_icon|\"platform\":|\"entity_id\":|}|{|\\[|\\]' /config/.storage/core.entity_registry | grep -v 'capabilities'" 
    scan_interval: 3600
    json_attributes:
    - data

I still believe this can be optimised, but I am on the right track.

1 Like

Is there meanwhile a official solution to this? Having 20+ tasmota devices in my network it would be very helpful to have a status dashboard on them.

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.

NodeRed and home assistant are a powerful match.

The integration devices page knows all the details:
image
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:

2 Likes

@jksalvo
Well, That’s new (for me at least)…
Templating has evolved since I switched to Node-Red.
I marked your response as an answer to this thread.

Any chance to get an full topic list of all tasmota devices and iterate over them(do an publish on each device)?

Thx