now.getMinuteOfDay in openHAB 3

Hi, I run into problems with the migration this days from openHAB 2.5 to 3.0 with my rules, which use the now.getMinuteOfDay method. It seems, that this method is not available anymore. I used this for Time comparison to see, if a special time or an astro time is the first one, which should be used. One example:

var aktuelle_zeit = now.getMinuteOfDay
var buergerliche_abenddaemmerung = new DateTime(astro_buergerliche_abenddaemmerung_startzeit.state.toString).getMinuteOfDay
if (aktuelle_zeit == 1140 || buergerliche_abenddaemmerung <= 1140) {
    r_eg_badezimmer_rolllade_fenster.sendCommand(DOWN)
    logInfo("rolladensteuerung.rules", "Badezimmerrolllade geschlossen")
}

I looked here, but did not understand what to do. I also read the Release notes, but there was no sentence about getMinuteofDay.

Any help is welcome. :grinning:

If you go back to the release notes, scroll down to Rules. Does the date related information there, and the link(s) help?

Rules now use Java Time API instead of Jodatime so some expressions need to be adapted:
getHourOfDay → getHour, getMinuteOfHour → getMinute, getMonthOfYear → getMonthValue
Some simple >and < comparisons may no longer work and you may need to use isAfter()/isBefore() instead.
See also this thread for more information.

Copied from release notes

Rules now use Java Time API instead of Jodatime so some expressions need to be adapted:

  • getHourOfDay → getHour, getMinuteOfHour → getMinute, getMonthOfYear → getMonthValue
  • Some simple >and < comparisons may no longer work and you may need to use isAfter()/isBefore() instead.

Edit: @hafniumzinc was faster :wink:

Yeah, but yours was much prettier!

2 Likes

I changed my rules by writing an lambda.
val getMinuteOfDay= [ZonedDateTime x |
val int minutesOfDay= (x.getHour() * 60) + x.getMinute()
minutesOfDay
]
and using like this:
val int tSunrise = getMinuteOfDay.apply((dtSunrise_Time.state as DateTimeType).zonedDateTime)

I am sorry, but in the Release Notes I can only read:

  • getHourOfDay
  • getMinuteOfHour
  • getMonthOfYear

Where do you read getMinuteOfDay?

We don’t, just asked whether it helped, but I did say:

The link in question is reproduced below:

Any use? Otherwise, I guess you’ll have to look up

Seems to be more complicated then before, but in a test rule the following worked:

var regel_startzeit = now()
var aktuelle_zeit = regel_startzeit.getHour() * 60 + regel_startzeit.getMinute()
var buergerliche_abenddaemmerung_java_time = (astro_buergerliche_abenddaemmerung_startzeit.state as DateTimeType).getZonedDateTime()
var buergerliche_abenddaemmerung = buergerliche_abenddaemmerung_java_time.getHour() * 60 + buergerliche_abenddaemmerung_java_time.getMinute()

A question for optimizing, is one of these solutions better then the other or is both qual in time and resources?

Solution A:

var regel_startzeit = now()
var aktuelle_zeit = regel_startzeit.getHour() * 60 + regel_startzeit.getMinute()

Solution B:

var aktuelle_zeit = now.getHour() * 60 + now.getMinute()

5 Likes

According to the API that method doesn’t exist.

thanks, this worked for me. appreciate the easy solution as i use getminuteofday quite a lot

var minute = now.getHour() * 60 + now.getMinute()

1 Like

Will it work like on example below?

OH2.5 version:

rule "Test rule 2"
when
	Item test_item_3 changed
then
    if (now.getMinuteOfDay > 240 && now.getMinuteOfDay < 600)
    {
	test_item_4.sendCommand(ON)
    }
end

OH3 version:

rule "Test rule 2"
when
	Item test_item_3 changed
then
    var minutes = now.getHour() * 60 + now.getMinute()
	if (minutes > 240 && minutes < 600)
    {
	test_item_4.sendCommand(ON)
    }
end
1 Like

Yes, spontaneously I have not seen any error. I make it comparable.

Thank you Lars for your help.

Or may be

import java.time.temporal.ChronoField;
ZonedDateTime.now().getLong(ChronoField.MINUTE_OF_DAY)