Check state of group in automation action

i have an automation that with few trigger and condition it will set the alarm mode, and send a message via telegram informing that the alarm is on, i also have an automation that check if i left any door open and this a message too, after your help here i customized the second automation with the name of the sensors that were left open, now i would like to make this a single automation (do you think it’s a good idea?)
but i’m having an issue, in the message action i’ve wrote this:

data:
      message: "Allarme Attivato! {% if group.sensori_porte.state == 'on' %} \nhai\
        \ lasciato aperto: \n{{ expand('group.sensori_porte') | selectattr('state',\
        \ 'eq', 'on') | map(attribute='name') | list | join('\n') }}  {% endif %}"

but with this when the automation is triggered i get

Error rendering data template: UndefinedError: ‘group’ is undefined

so i tried make it a string: ‘group.sensori_porte.state’ and now i don’t get any error, but i don’t think it will work as expected; i don’t know what the issue is, maybe group.name.state doesn’t exist ?
i would like to get the status of the group to check if i left anything open, if yes loop through the group and write the message, otherwise skip it.

any suggestions
thanks!

if states.group.sensori_porte.state == 'on'

or

if states('group.sensori_porte') == 'on'

thank you so much, is there a documentation with all the function or properties that i can read ?
thanks again

Yes, the additions to Jinja2 (Python) templating are explained here.

thank you so much!!!

1 Like