Script doesn't work; individual service calls do

I’m really puzzled by what has been happening with an actionable notification/automation that seems to have been running correctly for a month or so. When I arrive home and the alarm system is armed, pop up a notification to ask if I want to disarm/unlock or not. Below is the section of code that performs the action based on my selection from the actionable notification.

      - choose:
        - conditions: '{{ wait.trigger.event.data.action == "UNLOCK_ME" }}'
          sequence:
            - service: lock.unlock
              target:
                entity_id: lock.garage_entry_lock
        - conditions: '{{ wait.trigger.event.data.action == "DISARM_ME" }}'
          sequence:
            - service: alarm_control_panel.alarm_disarm
              target:
                entity_id: alarm_control_panel.alarm_panel
              data:
                code: !secret alarm_code
        - conditions: '{{ wait.trigger.event.data.action == "LET_ME_IN" }}'
          sequence:
            # - service: script.let_me_in
            - service: lock.unlock
              target:
                entity_id: lock.garage_entry_lock
            - service: alarm_control_panel.alarm_disarm
              target:
                entity_id: alarm_control_panel.alarm_panel
              data:
                code: !secret alarm_code

You’ll see that I’ve commented out the service call for ‘script.let_me_in’ and doing 2 separate service calls instead. It’s because all of a sudden, that script stopped working. The script is a cut and paste of the above 2 actions:

let_me_in:
  alias: Let Me In
  sequence:
  - service: alarm_control_panel.alarm_disarm
    data:
      code: '!secret alarm_code'
    target:
      entity_id: alarm_control_panel.alarm_panel
  - service: lock.unlock
    data: {}
    target:
      entity_id: lock.garage_entry_lock
  mode: single
  icon: mdi:security

I’ve been trying to troubleshoot this and what seems to happen when I say it doesn’t work is that any time I call that script, it will stall something related to my alarm system’s integration. The physical alarm controls on my walls in the house all still work fine. It’s only the integration into HA that freezes: no more motion sensor, door contact, alarm status updates – everything just freezes in time at the moment the script is called.

If instead of calling the script, I go into the Developer Tools and run the 2 service calls for the alarm_control_panel.alarm_disarm and lock.unlock, everything works normally. So I don’t know whether this is a problem with my script, or is it a problem with the alarm integration?

I run the AlarmDecoder integration and have been doing so for 8yrs or so, which utilizes a board that connects to the GPIO of a Raspberry Pi and is wired back to the alarm system’s panel. In order to un-freeze, I reboot the Raspberry Pi and everything is back to normal.

Thoughts?

if it’s a script then it has to be initiated manually so naturally it won’t work automatically.
But to be sure post it all so that we see what you have. Posting just a snippet is worthless

I’m not sure I quite follow, but yes the script is initiated manually and it is done so in the 3rd condition of the actionable notification (which as I mentioned above I have commented out). I have also initiated the script manually from the developer’s tools and as well as creating a button just to call the script. As soon as I trigger the script, the alarm integration freezes.

Here’s the full automation if it helps:

    - alias: 'Occupancy: Welcome Home'
      description: ''
      trigger:
      - platform: zone
        entity_id: person.him
        zone: zone.home
        event: enter
      - platform: zone
        entity_id: person.her
        zone: zone.home
        event: enter
      condition:
      - condition: state
        entity_id: alarm_control_panel.alarm_panel
        state: armed_away

      action:
      - variables:
          target: >
            {% set x = trigger.to_state.attributes.source %}
            {{ states[x].object_id }}
      - service: notify.mobile_app_{{ target }}
        data:
          title: 'Welcome home, {{ trigger.to_state.attributes.friendly_name }}!'
          message: "Unlock door, Disarm Alarm or Both?"
          data:
            actions:
              - action: UNLOCK_ME
                title: "Unlock"
                icon: "sfsymbols:lock.open.fill"
              - action: DISARM_ME
                title: "Disarm"
                icon: "sfsymbols:bell.slash"
              - action: LET_ME_IN
                title: "Both"

      - wait_for_trigger:
        - platform: event
          event_type: mobile_app_notification_action
          event_data:
            action: UNLOCK_ME
        - platform: event
          event_type: mobile_app_notification_action
          event_data:
            action: DISARM_ME
        - platform: event
          event_type: mobile_app_notification_action
          event_data:
            action: LET_ME_IN
        timeout:
          hours: 0
          minutes: 3
          seconds: 0
          milliseconds: 0

      - choose:
        - conditions: '{{ wait.trigger.event.data.action == "UNLOCK_ME" }}'
          sequence:
            - service: lock.unlock
              target:
                entity_id: lock.garage_entry_lock
        - conditions: '{{ wait.trigger.event.data.action == "DISARM_ME" }}'
          sequence:
            - service: alarm_control_panel.alarm_disarm
              target:
                entity_id: alarm_control_panel.alarm_panel
              data:
                code: !secret alarm_code
        - conditions: '{{ wait.trigger.event.data.action == "LET_ME_IN" }}'
          sequence:
            # - service: script.let_me_in
            - service: lock.unlock
              target:
                entity_id: lock.garage_entry_lock
            - service: alarm_control_panel.alarm_disarm
              target:
                entity_id: alarm_control_panel.alarm_panel
              data:
                code: !secret alarm_code
      mode: queued

The only thing I can think of is that the wait.trigger.event is not valid.
Where do you see this?
I have never seen that being used.

The alternative method I can see is a separate automation with the mobile app events as triggers, or that you restructure the automation with trigger IDs and have it as one.

I have never seen a template using wait. Perhaps it’s valid but I have never seen it.

The wait variable is valid and very useful for actionable notifications: Script Syntax - Home Assistant

Part of what is befuddling is that this script, automation, actionable notification is not new – it has been in use for about a month or so and this is only just suddenly happening.

One more note to add to this is that when I run the script, the “unlock” portion of the script will actually work; the “disarm” portion of the script is the bit that is hanging.

Could it be attributable to updates I’ve made to the HAOS / Supervisor? Maybe the way I’ve coded the script/automation/actionable notification isn’t quite robust enough and so something in the updates broke it?

1 Like

A weird development in this, but thought I’d update and hope for some more feedback from the community here.

First of all, I want to mention that my dashboard is created through the UI Minimalist “theme”.

So back when the script above wasn’t working, it was part of a “scenes card” that toggled switches and scripts. 3 scripts and 2 switches worked fine, the 4th script was what suddenly did not operate (after it being in use for 2 or 3 months) and it was related to the alarm system. When it suddenly stopped working, I mean that the scene button that called the script did not work, the script itself if you ran it from settings >> automations&scenes did not work either. But if you called the individual services from the developers tools, that worked fine. You just couldn’t string the 2 service calls together.

Next for the current update, I’ve switched the “scene card” to a horizontal stack of vertical buttons.
The buttons toggle scripts and switches, but now none of the scripts run from the button, only the switch does. When you go to settings >> automations&scenes and run the script from there, all the scripts operate correctly. System Log does not show any errors when running the scripts from the buttons.

edit::

just coming back to update my findings for the recent script issue, I’m finding for my specific use case that this works by adding the service call into a tap_action. Without it, it wasn’t working – I’m not sure if this was meant to be that way, but it does mean that you’re now entering the entity twice …

What still doesn’t work is the script not working at all described in the OP, but individual service calls do work.

                    - type: 'custom:button-card'
                      template: card_vertical_button
                      entity: script.water_the_lawn
                      icon: mdi:sprinkler
                      name: Irrigate
                      tap_action:
                        action: call-service
                        service: script.water_the_lawn
                      show_last_changed: true

Looking for help: Thanks in advance!

My AlarmDecoder works fine when connected to a PC. It arms/disarms and is set to CON ADR 18.

When connected to HA through a Pi4 USB, it won’t arm/disarm using HA’s alarm keypad. I’ve tried typing in the 4 digit code and clicking Home or Away; I’ve tried clicking the numbers for the 4 digit code and clicking Home or Away; I’ve tried typing or clicking the code plus ‘3’ (like you do on a real keypad)

The real keypads work fine.

Alarm Decoder shows the Arm/Disarm state when a keypad is used. Alarm Decoder shows all of it sensor states and these can trigger automations (motion sensor to turn on lights, for instance). The tripped alarm state shows up on HA as well and it sends a signal to my phone.

I simply can’t arm/disarm from HA. HA is up-to-date.

I’m getting this error recently as well. I’ve never seen this before and this is a technique I use all the time.

That’s related to 2024.8 and 2024.10’s new YAML. Like the error message says, use either action: (new) or service: (legacy), but don’t mix both.

Actually, you’ve used both for a single action. Just delete the service: line.

Oh I see so I guess the UI has not been updated to do this? I’ve only used the UI and I do not know yaml at all.

Are you saying you created this action with the UI, and it’s now flagging an error with the underlying YAML? Did you type any of the code in that screenshot yourself?

Okay I removed the service line and the script functions normally without error. Just so you know I used the UI to choose a scene and that’s how it got there in the first place.

1 Like

No I did not type any yaml I don’t know yaml I only use the UI so I think there might be something up with the way it chooses scenes and adds service line in error?