Script to momentarily trigger Rpi_gpio switch

I have an Arduino ATTiny with a 315 Mhz transmitter that I can trigger as a switch from HA using a gpio pin connected to the ATTiny. The problem is that I want a momentary on or off signal so that the ATTiny transmitter isn’t continuously sending “on” or “off” or both. My goal is to use this wireless switch with automations.

I tried writing a script to send a momentary “on” but it doesn’t work.

 switch:
  platform: rpi_gpio
    ports:
      17: 315mhz_on
      27: 315mhz_off
    invert_logic: true

 script:
  315mhz_switch_on:
    sequence:
      service: rpi_gpio.315mhz_on

The code on the ATTiny is the following

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

const int onPin = 1;
const int offPin = 2;

void setup()
{
// Transmitter is connected to Arduino Pin #5
mySwitch.enableTransmit(0);
mySwitch.setProtocol(2);
mySwitch.setPulseLength(800);
//mySwitch.setRepeatTransmit(10);

digitalWrite(onPin,HIGH);
digitalWrite(offPin,HIGH);
}

void loop()
{
int onval = digitalRead(onPin);
int offval = digitalRead(offPin);

if (onval == LOW)
{mySwitch.send(53440 + 2, 17);
delay(5000);}

if (offval == LOW)
{mySwitch.send(53280 + 2, 17);
delay(5000);}
}

Add a delay and then turn the GPIO off again. Minimum delay is one second. If you set it as less than 1 second it will sometimes faster than one second sometimes not. Depends on the timing of the request. HA runs on a second schedule.

Instructions about half way down on this page.