Python Script - Iterate within the entities of a group

Hi!
I’m really a newby in pyhton writing but I’m trying to write a script that should read the state of every door or window and send a telegram with the name of the entities returning an on (open) state.

I’m stuck in the very first step, I’ve created a group with all entites that it should monitor and now I’m just trying to make a for loop that iterates within the entites of shuch group and logging some info with the following piece of code:

for entity_id in hass.states.group.groupname.attributes.entity_id:
    logger.info(hass.states.get(entity_id).name)
    logger.info(hass.states.get(entity_id).state)

It returns this error that does not help to find the error…

Error executing script: Not allowed to access StateMachine.group

Thanks!