Script does not execute

Hi, I have a script which checks if any doors or windows are open and stops the alarm arming if they are. Up until upgrading to 2022.5.3 I assumed this was working fine as no errors were reported. It was during upgrade testing I noticed that a window was open and no notification was triggered. The script fires, but completes without any of the steps executing or any error appearing in the logs. Any suggestions as to the issue?

The script is:

script:
  # script.security_check - confirm all doors are shut and set alarm to on

  security_check:
    alias: security check
    sequence:
      choose:
        - conditions:
            - condition: state
              entity_id: !include ../group_openings.yaml
              state: "off"
            - condition: state
              entity_id: input_boolean.guest
              state: "off"
          sequence:
            - service: tts.cloud_say
              data:
                entity_id: media_player.living_room_sonos
                message: Attention, the alarm is about to arm 
                options:
                  gender: female
                language: en-GB
        - conditions:
            - condition: state
              entity_id: !include ../group_openings.yaml
              state: "on"
          sequence:
            - service: notify.mobile_app_1
              data_template:
                title: "the security system could not arm, {{ trigger.to_state.attributes.friendly_name }} is open please resolve before trying again."
                message: TTS
                data:
                  ttl: 0
                  priority: high
                  channel: alarm_stream_max
            - service: notify.mobile_app_2
              data:
                title: "the security system could not arm, {{ trigger.to_state.attributes.friendly_name }} is open please resolve before trying again."
                message: TTS
                data:
                  ttl: 0
                  priority: high
                  channel: alarm_stream_max
            - service: alarm_control_panel.alarm_disarm
              entity_id: alarm_control_panel.home
              data:
                code: !secret alarm_code
        - conditions:
            - condition: state
              entity_id: input_boolean.guest
              state: "on"
          sequence:
            - service: notify.mobile_app_1
              data:
                title: Attention, guest mode is on, the security system could not arm
                message: TTS
                data:
                  ttl: 0
                  priority: high
                  channel: alarm_stream_max
            - service: notify.mobile_app_2
              data:
                title: Attention, guest mode is on, the security system could not arm
                message: TTS
                data:
                  ttl: 0
                  priority: high
                  channel: alarm_stream_max
            - service: alarm_control_panel.alarm_disarm
              entity_id: alarm_control_panel.home
              data:
                code: !secret alarm_code

Thanks for any assistance you can provide.

Use the script trace feature to see what is going on.

Hi Tom_I thanks for responding. Do you mean the “Debug Script” button in Automations and Screens? If yes I have and it shows zero activity. Under Step Details it confirms script fired, “Executed: 10 May 2022, 10:08:47” but Trace Timeline shows no conditions were tested and the script finished with a runtime of 0.01 sec. If it was an error in the script I would have at least expected some sort of error message related to a step in the config.

So neither of your choose conditions resolved to true.

What does group_openings.yaml contain?

its a list of binary sensors. replaces the group.openings entity because that does not resolve which opening is open for the template. In the Debug Script function the above script is expanded in the Step Config window to:

choose:
  - conditions:
      - condition: state
        entity_id:
          - binary_sensor.frontdoor
          - binary_sensor.kitchen_door
          - binary_sensor.kitchen_window
          - binary_sensor.patio_door
          - binary_sensor.garage_door
          - binary_sensor.hall_window
          - binary_sensor.morning_room_window
          - binary_sensor.lounge_window_right
          - binary_sensor.lounge_window_left
          - binary_sensor.dining_room_window
          - binary_sensor.garage_upandover
          - binary_sensor.utility_toilet_window
        state: 'off'
      - condition: state
        entity_id: input_boolean.guest
        state: 'off'

This: {{ trigger.to_state.attributes.friendly_name }} is local to the automation an will not be defined in the script. Try removing it.

Hi Tom, not sure what you mean “local to the automation and will not be defined in the script”. But you question prompted me to replace the “entity_id: !include …/group_openings.yaml” with “entity_id: group.opening” which is still a valid entity. The script worked. So it must be the include statement that is causing the problem. Has anything changed in the way includes function recently?

I would leave it at that, except the reason for the include is so the TTS statement later can announce the specific entity that is open, with the group entity it cannot resolve which entity is open because group is open.

Automations have triggers. Scripts have no triggers.

Your script refers to the trigger variable (trigger.to_state.attributes.friendly_name). How can that work given that a script has no triggers?

Thanks, I was trying to extract which door or window was open into the script. While my script is incorrect and creates an error in the script debug when executed with group.opening as the condition this was not the cause of my original issue which seems to be around the use of “!include: group_openings.yaml”

If you want to use the trigger variable you would have to pass it to the script.

Or just put your script sequence directly in the automation.

Thanks Tom, I have taken it out for now

Definitely not the cause but nevertheless a non-functional part of the script. I mentioned it because you said you assumed it was “working fine” prior to 2022.5.3.

I don’t see how that script was ever able to report which door or window was open given that the trigger variable isn’t defined in a script.