@jazzyisj I also was interested if this template sensor could be modified to ignore entities of disabled devices after taking down my Patio Roku TV for the weather and disabling the device. After a bit of digging and testing, I can see that the core.entity_registry file marks entities as disabled by “config_entry” when the parent device is disabled.
Since this file is JSON, I worked out a command line sensor that uses jq to filter by entities that are marked as disabled by “config_entry”. Additionally, the jq filter has to flatten the resulting JSON to make the array of entities appear in the root level as command line doesn’t support specifying a path to pull data from.
Here is the resulting command line sensor configuration. I’m no JSON or jq expert, so the jq filter may easily be improved, but this sensor configuration has the count of disabled entities as the state, and an array of entity names as an attribute.
command_line:
sensor:
name: Disabled Device Entities
unique_id: amn_disabled_device_entities
json_attributes:
- entities
value_template: >
{{ value_json.entities | length }}
command: 'jq ''.data.entities |= map(select(.disabled_by? == "config_entry") | {name: .entity_id}) | del(.data.deleted_entities) | flatten | .[3]'' < .storage/core.entity_registry'
Adding this to configuration.yaml and reloading command line sensors results in this:
Each name is accessible via state_attr:
{{ state_attr('sensor.disabled_device_entities','entities')[0].name }}
Next steps are to incorporate checking these names in the template to ignore any matches.
This is kind of a hack, but I think it will work.

