Send a sequence of serial bytes with a delay in between

Hi I have emulated a keypad in ESP home by mapping all of the 16 keys

switch:

  - platform: uart
    name: "Keypad - 0"
    data: [0x4B, 0x30, 0x7B]

  - platform: uart
    name: "Keypad - 1"
    data: [0x4B, 0x31, 0x7C]

  - platform: uart
    name: "Keypad - 2"
    data: [0x4B, 0x32, 0x7D]

How do emulate a sequence of key presses with a delay in between i.e. I want to send 1 0 0 (100) from Home assistant to my keypad input

Regards, Dave

script:
  send_100:
    name: "Send 100"
    sequence:
      - service: switch.turn_on
        entity_id: switch.keypad_1
      - service: switch.turn_off
        entity_id: switch.keypad_1
      - delay: 1
      - service: switch.turn_on
        entity_id: switch.keypad_0
      - service: switch.turn_off
        entity_id: switch.keypad_0
      - delay: 1
      - service: switch.turn_on
        entity_id: switch.keypad_0
      - service: switch.turn_off
        entity_id: switch.keypad_0

You can assign that script to the tap action of a Lovelace button, or put it in an entities card or call the script from an automation.

Many Thanks, had to tweak it a bit so will post for others, as I am sending serial data I don’t need the turn off commands

house_night_mod:
  alias: House Night Mode
  sequence:
  - service: switch.turn_on
    target:
      entity_id: switch.house_keypad_set
  - delay: 1
  - service: switch.turn_on
    target:
      entity_id: switch.house_keypad_prog
  - delay: 1
  - service: switch.turn_on
    target:
      entity_id: switch.house_keypad_2
  mode: single

Regards Dave

1 Like

Nice. So they turn off automatically?

I was wondering about that.