Time controlled switch

I want implement time controlled switch which will switch on/off a pump in defined time. But not sure if it’s possible do it via metadata configuration and is there any chance change this times by user from the mainUI ?
Thanks for help

We need more details but based on what you describe the Expire metadata might work. You set it to command the Item OFF a given amount of time after it changed to ON.

As for changing it from MainUI, see Expire Updater [4.0.0.0;4.1.0.0). The Rule Template is for OH 4 but you should be able to adapt it to OH 3.

If you need more flexibility, use a Rule with a Timer.

As first step I want start a pump in defined time and stop in the other defined time.
If it’s possible, in the second step I want implement possibility that user can change this times from MainUI.

edit : I have idea, to make two trigger times for rule - let say 7:00am and 7:00pm
When rule is started, I will check if actual relay state is ON or OFF and switch relay to reverse state.

But I think I’m not able change this trigger times from MainUI

and

   if (shellyuni_Power_1.state == ON) {
        logInfo("LoggerName", "Pump OFF")
        shellyuni_Power_1.sendCommand(OFF)
      }
   else if (shellyuni_Power_1.state == OFF ) {
        logInfo("LoggerName", "Pump ON")
        shellyuni_Power_1.sendCommand(ON)
      }

But I prefer to check if time is 7:00am or 7:00pm and the do a command OFF or ON

That’s easy. Create two DateTime Items and use an input widget with a type of time or localdatetime which will give you a nice picker widget. There are a couple examples on the marketplace.

Then use the Time is Item trigger which will trigger that rule at the date time (or just the time) stored by the Item.

Thanks,
One question : When power is lost and restored after defined time. Is rule started with delay or will not start ?

Is ir possible difine defaut value or after each power lost is time value NULL and I must again define ?

edit : I can implement rule which is started after system restore

So I did rule other way :

val ZonedDateTime zdt = ZonedDateTime.now()
val hour = zdt.getHour
val min = zdt.getMinute
if (shellyuni_Power_1.state == OFF ) {
  if ( hour <= 7  && min <= 0 ) {  
      logInfo("LoggerName", "OFF STAY") 
    }
  else if ( hour >= 17  && min >= 0 ) {  
      logInfo("LoggerName", "OFF STAY") 
    }
  else {
      logInfo("LoggerName", "SWITCH ON")
    }
  }
else if (shellyuni_Power_1.state == ON ) {
  if ( hour <= 7  && min <= 0 ) {  
    logInfo("LoggerName", "SWITCH OFF") 
    }
  else if ( hour >= 17  && min >= 0 ) {  
    logInfo("LoggerName", "SWITCH OFF") 
    }
  else {
    logInfo("LoggerName", "ON STAY")
    }
  }

So now I only need define two items (if I want switch only in full hour) which will replace value 7 and 17 and which I can change via my widget

If the power was off when the time passed, it won’t trigger until the next time.

To handke that case trigger with a system run level trigger and check to see where now is compared to the trigger times and do the appropriate thing.

That’s what persistence and restoreOnStartup is for.