Add button to rf433 receiver side and control reley (with delay timer)

Hi guys,

I'm beginner and have a problem to add button to to controll relay on receiver side. I found sketch to control relay over rf433 wireless modul. This works perfect so I'm able to turn on/off relay. Now I would like to add button to reciver side to be able also controll the same relay over this button but with delay function so If I press button then relay will turn on for 30 seconds and then swithc off.
Will you help me and show how should I do it? I tried it but without succsess.
Thank you...

Here is the basic sketch>

Receiver >

#include <RH_ASK.h>
#include <SPI.h>

RH_ASK driver;
const int output = 2;
char receive[32];
int output_state = 0;
void setup()
{
driver.init();
pinMode(output, OUTPUT);
}

void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);

if (driver.recv(buf, &buflen))
{
memset(receive, 0, sizeof(receive));
for (int i = 0; i < buflen; i++) {
receive[i] = buf[i];
}
if (strcmp(receive, "Switch") == 0) {
output_state = !output_state;
digitalWrite(output, output_state);
}
}
}

And trasmiter side>

#include <RH_ASK.h>
#include <SPI.h>

const int switch_in = 3;
int state = 0;
char *msg;
RH_ASK driver;

void setup()
{
driver.init();
pinMode(switch_in, INPUT);
}

void loop()
{
if (digitalRead(switch_in) == HIGH && state == 1) {
msg = "Switch";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
state = 0;
}
else if (digitalRead(switch_in) == LOW) {
state = 1;
}
}

have you tried searching for a post describing this
https://www.google.com/search?q=site%3Aforum.arduino.cc%2F+button+led+timed&rlz=1C1CHBF_enUS802US802&sxsrf=ALiCzsbTwtNfao-c6Gw5x1fYBBnGxHAtNw%3A1670325472351&ei=4CSPY8-JFZmNytMP3Y2piAs&ved=0ahUKEwjP-cCj7-T7AhWZhnIEHd1GCrEQ4dUDCBA&uact=5&oq=site%3Aforum.arduino.cc%2F+button+led+timed&gs_lcp=Cgxnd3Mtd2l6LXNlcnAQA0oECEEYAUoECEYYAFCJA1jiB2DWCmgBcAB4AIABN4gBowKSAQE2mAEAoAEBwAEB&sclient=gws-wiz-serp

I know how to setup relay to turn on for 30 seconds like for example here:

const uint8_t pinRelay = 2;

void setup()
{
pinMode( pinRelay, OUTPUT );

}//setup

void loop()
{
digitalWrite( pinRelay, HIGH ); //turn the relay on
delay(30000ul); //wait 10-seconds
digitalWrite( pinRelay, LOW ); //turn the relay off

}

But I have a problem to combine these two codes so I would like to control relay remotely over rf433 and also over button on receiver side with this 30 second delay.

Now I have two codes and I would to combine them so this is my problem. :frowning:

put the above code inside the condition for some event such as a button press OR the reception of a remote msg