Enumerate and filter entities of a specific integration - Notify when a camera goes offline

Hey everyone,

I have several cameras integrated through the Tapo Camera integration.

I want to create a sensor that I can use to notify my when one of the devices go offline/unknown.

Following this, and other similar threads i managed to get close, but im not there yet :slight_smile:

{{ integration_entities('tapo_control')
      | select('match', 'update')
      | list
  }}

Using this, i can filter all the update entities of each camera, thiking that if one of them goes unavailable or unknown, it means the camera is offline. It indeed returns all the update.xxx entities belonging to the tapo control integration.
image

The issue is that if i try to filter any further (i.e. for unavailable), i get no results.

{{ integration_entities('tapo_control')
      | select('match', 'update')
      | selectattr('state','in', ['unknown', 'unavailable', 'off', 'on']) 
      | list
  }}

This gives me [] (I added off and on for test purposes)
Additionally, in this case, if I try to map anything (like | map(attribute='entity_id')) I get a list of undefined results.


On the other hand, if i try to filter all update entities starting with states then i can select only the unavalable/unknown etc

{{ states
| selectattr('domain','in',['update'])
| selectattr('state','in', ['unknown', 'unavailable', 'off', 'on']) 
| map(attribute='entity_id')
| list }}

this gives me pretty much all update entities, and i can filter correctly by choosing the keywords in the 3rd line.

What am I missing here?
How can i filter entities when starting by state when looking into a specific integration?
Or how can i filter only a specific integration’s entities when starting from all states?

Thanks in advance

Your template is returning a list of entity ID strings, not states. Add a |map('states') after your filter for update to turn that list back into states.

Great, this gives me a list of states, which i can then filter out as i want using this:

{{ integration_entities('tapo_control')
      | select('match', 'update')
      | map('states')
      | select('in',  ['unknown', 'unavailable']) 
      | list
      | count      
  }}

Now i have a sensor that counts how many cameras are offline!
Thanks.

Is there a way to figure out which camera it is?
If i remove the count and finish with |list can i have it return the entity id(s) of the selected entities?

You can also use
| select('is_state', ['unknown', 'unavailable'])


{{ integration_entities('tapo_control')
      | select('match', 'update')
      | select('is_state',  ['unknown', 'unavailable']) 
      | list
  }}

2 Likes

or

{{ integration_entities('tapo_control')
      | select('match', 'update')
      | reject('has_value') 
      | list
  }}
2 Likes

Thank you, this gives me the names of the unavailable ones, and if i add a |count at the end, it gives me a number so i can create a sensor.

Exactly what I needed!

Then TheFes should win the laurels :wink:

Quoted wrong reply :slight_smile:
I used yours
Thanks!

@TheFes 's | reject('has_value') also works, but i like having more control with | select('is_state', ['unknown', 'unavailable']), where i can also check if off/on works, for test purposes.

Now i need to go find an entity on each camera that updates more regularly, because the update entity seems to be lazy!

Also, a screenshot of my final template sensor:

1 Like

Update:
If anyone ends up here interested in detecting the offline Tapo cameras through the specific integration, the update.xxx entities wont work, they do not seem reflect the camera’s availability.

Sirens seem to work better.

New template code:

{{ integration_entities('tapo_control')
      | select('match', 'siren')
      | select('is_state',  ['unknown', 'unavailable']) 
      | list
      | count
  }}