Automatically close windows when people live home

Hello community!
I am struggling with an automation which is probably very simple.
I have two windows that I would like to close if last person leaves home and forgets them open; and HA to send a notification that they have been closed.
This is the code I wrote but it’s not working :frowning:
That’s in advance for your help

- id: '14564064377775'
  alias: You left Velux open
  trigger:
  - platform: state
    entity_id: group.people
    to: not_home
  condition:
  - condition: state
    entity_id: group.velux
    state: 'on'
  action:
  - service: cover.close_cover
    entity_id: group.velux
  - service: notify.iphones
    data:
      title: You left the Velux open
      message: I will close it for you
  initial_state: true
  mode: single

For the notifications I have created a notifications.yaml file with this code


- platform: group
  name: iphones
  services:
    - service: mobile_app_iphone1
    - service: mobile_app_iphone2

Does the closing work through developer tools → Services?

Do you get any errors in the logs?

How did you test the automation?

I don’t get any errors and if I test the automation over Configuration → Automations it works.
Is the error maybe in the location service?

It’s my understanding that the cover.close_cover service call is for closing cover entities.

If you go to Developer Tools > Services and select Cover: Close, when you click ‘Pick entity’ it won’t offer to select anything other than a cover entity.

You’re saying you have tested and confirmed the cover.close_cover service call will work with a group entity?

Yes, the velux group is a cover
This is from the groups.yaml

velux:
  name: Velux
  entities:
      #bedroom velux
    - cover.peq1682254
      #children velux
    - cover.peq1682253

Then it can only be the trigger or the condition. If you go to Developer Tools → States, does group.velux show on when the windows are open? Does group.people show not_home when you leave the house?

If it’s a group of cover entities then I believe the group’s state is the same as the states of its entities. That means open/closed as opposed to on/off. You can confirm that by examining the state value of group.velux in Developer Tools > States. If it’s open/closed then change the State Condition to:

  condition:
  - condition: state
    entity_id: group.velux
    state: 'open'

That solved the problem!