Template integration_entities not working reliably?

I'm having issues where when I uses integration_entities in a template it randomly won't work and I can't figure out why or what to do about it. I've had this with both built-in integrations (e.g. apcupsd) and HACS integrations with no apparent rationale as to why.

This is especially problematic when I have templates which report for things like low batteries and suddenly they're listing stuff for excluded integrations as being unavailable when its expected the device should be unavailable (e.g. a phone that isn't home when the system reloads, a device that is powered down and shouldn't be reporting).

Anyone have suggestions how to troubleshoot? It looks like starting with a sensor ID the system knows what integration it should belong to, but the other way doesn't?

Here's an example from the Template Dev Tools:

{% set ent = "number.x2d_20p6aj630401658_bed_target_temperature" %}
{%- set integ = device_attr(ent, 'identifiers')|list %}
Integration: {{ integ[0][0] if (integ|length) > 0 else '??' }}
{{ integ }}

Entities:
{{ integration_entities('bambu_lab') }}

Result:

Integration: bambu_lab
[('bambu_lab', '20P6AJ630401658')]

Entities:
[]

Do you ever see entities in that list from the template?
Is this solely integrated via Bambu Lab or do you have perhaps some MQTT Entities
What does the Device page that lists this entity look like
Is the entity number.x2d_20p6aj630401658_bed_target_temperature hidden or disabled?

integration_entities purely works off config entries. If the custom integration does not properly create a config entry or entities inside that config entry, then the function will return an empty list.

When it can't grab things from the config entry, then the fallback is to provide entities with the listed domain. This is a fallback essentially for yaml based entities, which do not have a config entry.

Based on what I'm seeing, I'd wager you're hitting the first if statement, where the config entry is not named bambu_labs which means integration_entities will always return an empty list. Go look at your config entries file, find bambu_labs and find out the config entry name.

Sometimes, yes. At the moment it shows "unknown" because the printer is off but when I have the printer turned on it shows correct values.

Annoyingly, today its all happy...same exact template code:

Integration: bambu_lab
[('bambu_lab', '20P6AJ630401658')]

Entities:
['binary_sensor.x2d_20p6aj630401658_timelapse', 'binary_sensor.x2d_20p6aj630401658_extruder_filament', 'binary_sensor.x2d_20p6aj630401658_hms_errors', 'binary_sensor.x2d_20p6aj630401658_print_error', 'binary_sensor.x2d_20p6aj630401658_online', 'binary_sensor.x2d_20p6aj630401658_firmware', 'binary_sensor.x2d_20p6aj630401658_door', 'binary_sensor.x2d_20p6aj630401658_developer_lan_mode', 'binary_sensor.x2d_20p6aj630401658_mqtt_encryption', 'binary_sensor.x2d_20p6aj630401658_hybrid_mqtt_control_blocked', 'binary_sensor.x2d_20p6aj630401658_ams_1_active', 'binary_sensor.x2d_20p6aj630401658_ams_2_active', 'binary_sensor.x2d_20p6aj630401658_ams_1_drying', 'binary_sensor.x2d_20p6aj630401658_ams_2_drying', 'binary_sensor.x2d_20p6aj630401658_externalspool_active', 'binary_sensor.x2d_20p6aj630401658_externalspool2_active', 'button.x2d_20p6aj630401658_pause', 'button.x2d_20p6aj630401658_resume', 'button.x2d_20p6aj630401658_stop', 'button.x2d_20p6aj630401658_force_refresh', 'fan.x2d_20p6aj630401658_cooling_fan', 'fan.x2d_20p6aj630401658_aux_fan', 'fan.x2d_20p6aj630401658_chamber_fan', 'fan.x2d_20p6aj630401658_secondary_aux_fan', 'image.x2d_20p6aj630401658_cover_image', 'image.x2d_20p6aj630401658_pick_image', 'light.x2d_20p6aj630401658_chamber_light', 'number.x2d_20p6aj630401658_nozzle_target_temperature', 'number.x2d_20p6aj630401658_bed_target_temperature', 'number.x2d_20p6aj630401658_chamber_target_temperature', 'select.x2d_20p6aj630401658_printing_speed', 'select.x2d_20p6aj630401658_airduct_mode', 'sensor.x2d_20p6aj630401658_externalspool_external_spool', 'sensor.x2d_20p6aj630401658_externalspool2_external_spool', 'sensor.x2d_20p6aj630401658_ams_1_humidity_index', 'sensor.x2d_20p6aj630401658_ams_2_humidity_index', 'sensor.x2d_20p6aj630401658_ams_1_humidity', 'sensor.x2d_20p6aj630401658_ams_2_humidity', 'sensor.x2d_20p6aj630401658_ams_1_temperature', 'sensor.x2d_20p6aj630401658_ams_2_temperature', 'sensor.x2d_20p6aj630401658_ams_1_remaining_drying_time', 'sensor.x2d_20p6aj630401658_ams_2_remaining_drying_time', 'sensor.x2d_20p6aj630401658_ams_1_tray_1', 'sensor.x2d_20p6aj630401658_ams_2_tray_1', 'sensor.x2d_20p6aj630401658_ams_1_tray_2', 'sensor.x2d_20p6aj630401658_ams_2_tray_2', 'sensor.x2d_20p6aj630401658_ams_1_tray_3', 'sensor.x2d_20p6aj630401658_ams_2_tray_3', 'sensor.x2d_20p6aj630401658_ams_1_tray_4', 'sensor.x2d_20p6aj630401658_ams_2_tray_4', 'sensor.x2d_20p6aj630401658_mqtt_connection_mode', 'sensor.x2d_20p6aj630401658_tool_module', 'sensor.x2d_20p6aj630401658_wi_fi_signal', 'sensor.x2d_20p6aj630401658_bed_temperature', 'sensor.x2d_20p6aj630401658_bed_target_temperature', 'sensor.x2d_20p6aj630401658_chamber_temperature', 'sensor.x2d_20p6aj630401658_chamber_target_temperature', 'sensor.x2d_20p6aj630401658_nozzle_temperature', 'sensor.x2d_20p6aj630401658_nozzle_target_temperature', 'sensor.x2d_20p6aj630401658_left_nozzle_temperature', 'sensor.x2d_20p6aj630401658_left_nozzle_target_temperature', 'sensor.x2d_20p6aj630401658_right_nozzle_temperature', 'sensor.x2d_20p6aj630401658_right_nozzle_target_temperature', 'sensor.x2d_20p6aj630401658_aux_fan_speed', 'sensor.x2d_20p6aj630401658_chamber_fan_speed', 'sensor.x2d_20p6aj630401658_cooling_fan_speed', 'sensor.x2d_20p6aj630401658_heatbreak_fan_speed', 'sensor.x2d_20p6aj630401658_model_download', 'sensor.x2d_20p6aj630401658_speed_profile', 'sensor.x2d_20p6aj630401658_airduct_mode', 'sensor.x2d_20p6aj630401658_current_stage', 'sensor.x2d_20p6aj630401658_print_progress', 'sensor.x2d_20p6aj630401658_print_status', 'sensor.x2d_20p6aj630401658_printable_objects', 'sensor.x2d_20p6aj630401658_sd_card_status', 'sensor.x2d_20p6aj630401658_skipped_objects', 'sensor.x2d_20p6aj630401658_start_time', 'sensor.x2d_20p6aj630401658_remaining_time', 'sensor.x2d_20p6aj630401658_end_time', 'sensor.x2d_20p6aj630401658_total_usage', 'sensor.x2d_20p6aj630401658_current_layer', 'sensor.x2d_20p6aj630401658_total_layer_count', 'sensor.x2d_20p6aj630401658_gcode_filename', 'sensor.x2d_20p6aj630401658_gcode_file_downloaded', 'sensor.x2d_20p6aj630401658_task_name', 'sensor.x2d_20p6aj630401658_print_type', 'sensor.x2d_20p6aj630401658_printer_name', 'sensor.x2d_20p6aj630401658_print_length', 'sensor.x2d_20p6aj630401658_print_bed_type', 'sensor.x2d_20p6aj630401658_print_weight', 'sensor.x2d_20p6aj630401658_active_tray', 'sensor.x2d_20p6aj630401658_nozzle_size', 'sensor.x2d_20p6aj630401658_nozzle_type', 'sensor.x2d_20p6aj630401658_left_nozzle_size', 'sensor.x2d_20p6aj630401658_left_nozzle_type', 'sensor.x2d_20p6aj630401658_right_nozzle_size', 'sensor.x2d_20p6aj630401658_right_nozzle_type', 'sensor.x2d_20p6aj630401658_ip_address', 'sensor.x2d_20p6aj630401658_serial_number', 'switch.x2d_20p6aj630401658_camera', 'switch.x2d_20p6aj630401658_prompt_sound']

Where do I look to see if that's the case?

I've intermittently seen this with other integrations too, including the apcupsd one which is "built in". The bambu labs one is just today's example.....or maybe YESTERDAY's example because today its working fine...

The code is very simple, if the key isn't in the config entry, it returns an empty list. If the key has a config entry, it returns the registered entities. If the domain has entities, it returns the domain entities. It checks in that order.