The method getLocalMillis() is not visible, error

Hi,
I’m totally new about rules and I don’t understand Xtend very well.

I wanna ask you why I get the error “The method getLocalMillis() is not visible” aside of my rule in OH designer.

I used Habmin to compile the rule and then I’m looking inside of it to understand how to create from txt lines.

The line with error is

if (PIR_soggiorno.state == ON && (new LocalTime().getLocalMillis() >= new LocalTime(21, 0, 0, 0).getLocalMillis() || new LocalTime().getLocalMillis() <= new LocalTime(7, 0, 0, 0).getLocalMillis()) && LIFX1_Int_Soggiorno_Accendi.state == OFF && Luminosita_Int_Soggiorno.state < 15)

The complete rule is

// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
import org.joda.time.*

// Global Variables
var boolean PIR_Flag = false
var Timer _timer_001_A = null

rule "PIR_Soggiorno"
when
    Time cron "0 0 * * * ?"
    or
    Item PIR_soggiorno changed
    or
    Item LIFX1_Int_Soggiorno_Accendi changed
    or
    Item Luminosita_Int_Soggiorno changed
then
  if (PIR_soggiorno.state == ON && (new LocalTime().getLocalMillis() >= new LocalTime(21, 0, 0, 0).getLocalMillis() || new LocalTime().getLocalMillis() <= new LocalTime(7, 0, 0, 0).getLocalMillis()) && LIFX1_Int_Soggiorno_Accendi.state == OFF && Luminosita_Int_Soggiorno.state < 15) {
    sendCommand(LIFX1_Int_Soggiorno_Dimmer, 25)

    PIR_Flag = true
  }

  if ((PIR_Flag == true)) {
    if (_timer_001_A == null) {
      _timer_001_A = createTimer(now.plusSeconds(30)) [|
        _timer_001_A.cancel()
        _timer_001_A = null
        sendCommand(LIFX1_Int_Soggiorno_Accendi, OFF)

        PIR_Flag = false
      ]
    }
  }
  else if(_timer_001_A != null) {
    _timer_001_A.cancel()
    _timer_001_A = null
  }
end

Thank you so much to explain me something.

You should use now for comparisons like this.

now.isAfter(now.withTimeAtStartOfDay.plusHours(21)) ||
now.isBefore(now.withTimeAtStartOfDay.plusHours(7))

withTimeAtStartOfDay gives you midnight of the current day.

If you will be dealing with time a lot I recommend getting openHAB Designer (I’m assuming you are on OH 1.8 given your imports, if on OH 2 realize you should have none of those imports) and in a rule type now.<ctrl><space> which will give you a list of all the methods you can call on now. For further documentation, now is a Joda DateTime object and you can review the javadocs for it on joda’s website.

If you care about times of day in other rules, I also recommend the following.

1 Like

Thanks, @rlkoshak

cristalline explaination!