Automation with two scripts in sequence not working

I have a couple of basic scripts to send commands to a Moes IR blaster (ZHA integration) and each of them works fine on their own, but when I try to run them in sequence in an automation or repeat one in an automation only the first instance seem to fire. I’m not sure if this is an issue with my script or an issue with the IR blaster, but here’s an example of the basic script I use for each command on the IR blaster (let’s call them “test1”, “test2” etc.):

alias: test1
sequence:
  - data:
      cluster_type: in
      ieee: 8c:65:a3:ff:fe:a1:cd:d3
      endpoint_id: 1
      command_type: server
      cluster_id: 57348
      command: 2
      params:
        code: >-
          [base64 code]
    action: zha.issue_zigbee_cluster_command
icon: mdi:remote
mode: single
description: ""

and then I call these scripts in an automation with a sensor and time trigger, in this example to run in sequence with a brief pause between them:

alias: test_automation
description: ""
triggers:
  - type: temperature
    device_id: bdcbbd4c9376c0bb602c1783b6ceba89
    entity_id: 24ff6a7d82b938b5d9b8020ef8315a3e
    domain: sensor
    trigger: device
    id: BR temp <67
    below: 67.9
conditions:
  - condition: time
    after: "01:00:00"
    weekday:
      - sat
      - fri
      - thu
      - wed
      - tue
      - mon
      - sun
    before: "07:00:00"
actions:
  - sequence:
      - action: script.test1
        metadata: {}
        data: {}
      - delay:
          hours: 0
          minutes: 0
          seconds: 0
          milliseconds: 200
      - action: script.test2
        metadata: {}
        data: {}
mode: single

I can see from the device that it’s only receiving one command from the IR blaster. The same thing happens when I set up a single script to repeat twice. No idea why the second script in that sequence is not running, but any insight appreciated.

First step is always the automation trace. What does it say?

The traces show that the delay is potentially occurring in the wrong place – the first script is started, turns on and the delay occurs before it is then turned off. Not sure if that is effectively rendering that first script (and its associated IR command) null.

So I tried removing the delay altogether from the sequence, and the traces show everything starting/turning on/turning off as expected but no commands apparently being received by the appliance I’m trying to control. I tried various other configurations of two scripts in the automation and concluded that only the first one is ever being properly executed by the IR blaster. The second script is just never getting through to the blaster despite traces suggesting it’s firing OK.

Makes me wonder if this is an issue with the IR blaster itself or whether there’s a more reliable way of having an IR blaster send two consecutive commands to an appliance.

Have hou tried a much longer delay? My guess is the blaster ignores new commands while it is still busy. The fact that the command returns does not mean the blaster is done, it means the command was sent successfully.

If you use your phone camera you might be able to see how long it takes the blaster to sens a command. You can compre that to the automtion trace timings.

Ah-ha – that seems to be the trick.

It’s in infuriating quirk of the appliance that when it’s actually turned on and operating it’s not ready to receive new IR commands until the receiver is woken by a “junk” button press on the remote (but when it’s in standby the IR receiver is always listening… go figure). So I timed how long the front panel of the appliance stayed lit after pressing a button on the remote, and set just shy of that as the delay in the automation (3 seconds), and it seems to work.

Thanks for the suggestion!

1 Like