Compare two DateTimeType - formatting

Hi,
simple question - I want to compare two items:

Item KalendarOdpady_NextEventStart is defined as Type DateTime and has value (2022-02-10T00:00:00.000+0100)
Value tomorrow is defined in rule:

val tomorrow = now.plusDays(1)

    if (KalendarOdpady_NextEventStart.state == tomorrow) {
        sendBroadcastNotification("zajtra sa daco deje", "sewerage", "WARN")
    }

how should I format those two items to be matching?
where can I see actual value of the tomorrow Item?

Thanks,
Michal, Slovakia

Can you clarify what you really want? These are datetime remember, they’ll only be “equal” at the exact millisecond.

You might want to set ‘tomorrow’ to some date but time 00:00, and then compare the other Item state to state to see if it is after?

I want to know, if the KalendarOdpady_NextEventStart is tomorrow. So practically I need to compare dates only.

Example here

Yes, I red it, but it is hard to understand the code. I think there needs something like:
KalendarOdpady_NextEventStart.state.toString == tomorrow.state.toString. Obviously, it does not work for me :frowning:

The important parts of the example -

val tomorrow = now.plusDays(1)

val Wert = (i.state as DateTimeType).zonedDateTime

if (Wert.year == tomorrow.year && Wert.month == tomorrow.month && Wert.dayOfMonth == tomorrow.dayOfMonth) { ...

There are cleverer ways to do this, but that is understandable.

1 Like

Thanks for guiding me again :slight_smile:

just to leave here the complete solution:
the rule check the text in the calendar KalendarOdpady_NextEventTitle and start date of the event from calendar KalendarOdpady_NextEventStart and then lights up the Xiaomi Hub light depending on the event name next day.

val tomorrow = now.plusDays(1)

rule "kalendar-odpady"
//zasviet svetielko na xiaomi hube podla vyvozu smeti
when
    Time cron "0 00 18 1/1 * ? *" //o 18:00
then
    val odpadCas = (KalendarOdpady_NextEventStart.state as DateTimeType).zonedDateTime
    logInfo("kalendar-odpady", "je ZAJTRA nejaky vyvoz odpadu?")
    if (odpadCas.year == tomorrow.year && odpadCas.month == tomorrow.month && odpadCas.dayOfMonth == tomorrow.dayOfMonth) {
        sendBroadcastNotification("zajtra sa daco deje", "sewerage", "WARN")
        if (KalendarOdpady_NextEventTitle.state == "Papier") {
            sendBroadcastNotification("Vyvazaju papier.", "sewerage", "WARN")
            XiaomiGW_Color.sendCommand("240,100,100")
            XiaomiGW_Brightness.sendCommand(10)
            }
        if (KalendarOdpady_NextEventTitle.state == "Plasty") {
            sendBroadcastNotification("Vyvazaju plasty.", "sewerage", "WARN")
            XiaomiGW_Color.sendCommand("60,100,100")
            XiaomiGW_Brightness.sendCommand(10)
            }
        if (KalendarOdpady_NextEventTitle.state == "Komunálny odpad") {
            sendBroadcastNotification("Vyvazaju komunálny odpad.", "sewerage", "WARN")
            XiaomiGW_Color.sendCommand("0,0,75")
            XiaomiGW_Brightness.sendCommand(10)
            }
/*        if (KalendarOdpady_NextEventTitle.state == "Kovy") {
            sendBroadcastNotification("Vyvazaju kovy.", "sewerage", "WARN")
            XiaomiGW_Color.sendCommand("0,100,100")
            XiaomiGW_Brightness.sendCommand(10)
            }
*/
    }
end

rule "kalendar-odpady.svetielkoOff"
//zhasni svetielko na xiaomi hube o 21:00
when
    Time cron "0 00 21 1/1 * ? *" //o 21:00
then
    logInfo("kalendar-odpady", "je ZAJTRA nejaky vyvoz odpadu?") 
        XiaomiGW_Brightness.sendCommand(0)
end