[PyScript] Get trigger from all attributes/entities of a device defined in a group

Hi all,
I’m a newbie with respect to python and pyscript but have some development experience with c and matlab.I recently changed from Domoticz to Home Assistant and now I would like to recode some of my old scripts. One script is to control all thermostats.

I would like to check several attributes/entities of a thermostat (climate) whatever change is made. For example, check or reset ‘temperature’, ‘max_temp’, ‘window_detection’, whatever.
Furthermore, I have made a group with all thermostats I have.

How do I have to define the @state_trigger to trigger a certain reset function, for every attribute change made, for every device in the group? I want to make a more generalized script.

Looking forward to your advice. many thanks in advance.

I just found out how to get there!

In the Python script first define the following function:

def create_state_trigger_expression(): 
  log.info("********************** FUNC: create_state_trigger_expression **********************")
  inclAttributes = ["temperature", "current_temperature", "state", "hvac"]
  triggerExpr = "input_boolean.test_light_switch, " 
  for entity_id in group.thermostats.entity_id:   
    for attr in inclAttributes:
      triggerExpr = triggerExpr + f"{entity_id}.{attr}" + ", "
  triggerExpr = triggerExpr[:-2]
  return triggerExpr

then call the function in the state_trigger:


During loading of the script, the state expression is generated. Works like a charm.