Trying to create rules/event based on item DateTime

Hello,

I’m trying to mimic an event based rules with some data I’m currently retrieving from a JSON Api but cannot figure out how to properly do it.

I’m using the Http Binding to retrieve some Date Time (Start and End Time), I’m assigning these DateTime to two items (Start_DateTime and End_DateTime).

This DateTime is updated randomly during the week so it’s being refreshed every hour. What I want to do is trigger at Start_DateTime and End_DateTime but I can’t figure out how to properly do that.

Currently I have a rule that’s being run every minute with the following code:

val start_datetime = new DateTime(Start_Time.state.toString)
val end_datetime = new DateTime(End_Time.state.toString)
var curr = "UNKNOWN"
switch now {
    case now.isBefore(start_datetime):                                      curr = "Before Event"
    case now.isAfter(start_datetime)   && now.isBefore(end_datetime):       curr = "Event"
    case now.isAfter(end_datetime):                                         curr = "After Event"
}

So the value of curr reflect if I’m currently in the event.

That’s working, but I’m wondering if there is a way to trigger this rule based on the start time and end time when the time comes instead of checkin every minute if I’m currently in the current Timeframe.

I wonder if I can create a custom event (like the astro sun channel event for example) but I have no idea how to do that.

Thanks a lot for you guidance and your help.

Best,

Recent relevant post -

2 Likes

Oh ! I have not thought of creating a timer for that, that would work perfectly, thanks a lot for the quick response, I have searched for custom event but not for timer :frowning:

Thanks !