I’m in the process of setting up room presence detection using the mqtt_room component. I’m not interested in keeping any of the database records for these items, as long as I know the most recent state.
Is there a way to exclude all sensors for the platform mqtt_room? I can see how to exclude a domain, or an entity, but ideally, I’d like to just categorically exclude all mqtt_room sensors, but include all my other sensors.
Here’s what I’m currently working with, but I’m planning on adding several new items to room tracking in the near future, and I’d like to avoid adding maintenance overhead.
I feel like I’m being a dunce here, but I can’t see a way to get a sensor’s platform on the state object. Here’s what I would have hoped would work, but doesn’t:
{% for state in states.sensor -%}
{% if state.platform == 'mqtt_room' %}
- {{ state.entity_id }}
{% endif %}
{%- endfor %}
Are you trying to do this in the template editor? If so, you don’t have access to the states object’s platform. The only attributes that exist on a state object in the template editor are documented here:
You’d have to use a unique identifier in the object_id.
{% for state in states.sensor -%}
{% if 'mqtt' in state.object_id %}
- {{ state.entity_id }}
{% endif %}
{%- endfor %}
Assuming that your object_id’s contain the characters ‘mqtt’
Thanks @petro - that’s the same page I linked to above. I was attempting to do what @anon43302295 suggested above, but since that isn’t possible it’s going to be easier to manually grep through my configuration to grab the names of the entities with a given platform than it is to rename them all to a given naming convention and update any and all references to them within my automations etc.
This is an old topic but still actual.
I really like the idea to be able to exclude/include entities to the recorder by the platform. The problem is that platform isn’t available in state.
Seems like you don’t understand the database… Platforms create the entity_ids. Recorder only includes or excludes entities (entity_ids) not platforms. If you want to exclude entity_ids from a platform, you have to exclude all entities created from said platform.
I know that I can include/exclude by entity_id or domain.
But I’m looking at source code and I’m trying to figure out a way to add include/exclude by platform functionality.
Last I checked, there’s no way to infer which platform created entity_id’s. The state machine does not store that information. Logger has it because that’s how python logging is built.
EDIT: Just to clarify
logger for python has a built in method that can track which methods were used. You can simply pass a format to logger and it will output this information in the logged line. That’s what home assistant is doing. Home assistant isn’t actively tracking which platform is logging what.
I need to find a way to know what platform specific entity_id belongs to.
For example:
binary_sensor:
- platform: rpi_gpio
pull_mode: UP
ports:
12: Move
this entry has binary_sensor.move as id.
I can get domain using split_entity_id function, but I don’t know how to get the platform name, in this case, it should be rpi_gpio. Having the domain I will be able to modify generate_filter function and add include and exclude platforms.
I think that having such an option would allow us to exclude platforms like yr, time_date or command_line from recorder or history panel.
I’ll search a bit more and ask on Discord for hints. I think this would be a useful feature. WDYT?