Template finding Variables in trace

First post here and not an experts but have been reading the forum for many hours to try and find a response that matches my problem. So head up over the parapet!

I am trying to implement a Wiser Thermostat template from the GitHub put together to assist in coding third party thermostats with wiser.
https://github.com/asantaga/wiserHomeAssistantPlatform/blob/8511c8dc01d1469c5d531584573ba397ec910463/recipes/manage_temps_v2.md

My question is the trace says that the section testing if my device entity is part of the sensor integration fails.

This part :` {% if temp_sensor in integration_entities(temp_sensor_integration)
and temp_sensor.startswith(temp_sensor_prefix)
and temp_sensor.endswith(temp_sensor_suffix)
%}
True
Now the trace says this always fails. So I have broken down the code by removing each element (deleting the code for each of the select statements (in each and section and it appears that the integration never has my ESP32 device in it.

So I have been trying to find out how to obtain a list of integration entities to see if my device is in fact there.

  temp_sensor_integration: esphome
  temp_sensor_prefix: sensor.bathtemp
  temp_sensor_suffix: temperature

I need to find a way of getting the variables out of the code. Of course this does not work until there is a proper event, otherwise the entity is null.

My question is how do I find out why the test is false?
I have tried verifying the device details and I believe they are correct..

Thank you for anyone who can improve my understanding.

Cheers

The YAML is here

alias: Fire Event When Room Monitoring Temp Sensors Change Reading
description: ""
triggers:
  - event_type: state_changed
    variables:
      temp_sensor: "{{trigger.event.data.entity_id}}"
    trigger: event
conditions:
  - condition: template
    value_template: |-
      {% if temp_sensor in integration_entities(temp_sensor_integration)
            and temp_sensor.startswith(temp_sensor_prefix) 
            and temp_sensor.endswith(temp_sensor_suffix)  
      %}
        True
      {% endif %}
actions:
  - event: external_temp_sensor_changed
    event_data:
      entity_id: "{{temp_sensor}}"
      old_temp: "{{trigger.event.data.old_state.state}}"
      new_temp: "{{trigger.event.data.new_state.state}}"
trigger_variables:
  temp_sensor_integration: esphome
  temp_sensor_prefix: sensor.bathtemp
  temp_sensor_suffix: temperature
mode: queued
max: 25

That trigger is going to cause problems… it’s effectively triggering on every single state and attribute change of every entity in your system.

Because it’s being continuously spammed by state changes, the vast majority of them won’t match all those criteria; and with only 25 available slots, the state change events that would match the criteria have a pretty low chance of ever actually getting picked up.

While I don’t think it will solve your problem, you can use the Template Editor tool and the following template to see all the entities from the ESPHome integration:

{{ integration_entities('esphome') }}

Thank you Didgeridrew for the quick response and I note that your comment matches the feedback from others regarding this template causing hangs etc. I am becoming aware that I could be flogging the proverbial dead horse as the device I am seeking to control is in fact a Schneider towel rail which as has been discussed, needs a Wiser thermostat anyway and I was pushing this challenge mainly for self development/punishment. I only have a small system so I might get away with the risk but I very much take your point seriously.
Hey ho…

So, do the wiser actions shown in the second automation work for you if you use them in the Action tool?

If that side of it works, we can help work around the poorly designed first automation.

Well thank you for shining light on the scenario. I added the query to the script and saw a fairly long list of triggers including the ones I needed right at the end. They never did receive a True status.

I will continue to test the second part of the automation but I think that this effort will only pay back on basic radiators if I can achieve success(not the towel rails that must have a thermostat). In the meantime if you would be happy to support me with some of your expertise I would be extremely grateful. I realise now how far down I am on the steep part of the curve.