Cannot read write-only property: schedule

Hi,

I've implemented recently a code with the schedule function without any problems, But now, I'm getting this error:

So, I'm trying to schedule an event at specific times with the schedule function, and I'm getting an error, what is odd, it’s I'm able to schedule the same event (reset) with runEvery3Hours for example.

Does anyone have an idea how to solve it? This may be obvious for other developers, but since I code essentially for fun without any proper education in this area, sometimes it gets a bit complicated, although usually, I'm able to find my answer on forum or documentation, but not this time...

def updated() {
log.info "updated() "

if (!state.updatedLastRanAt || now() >= state.updatedLastRanAt + 5000) {
  state.updatedLastRanAt = now()
  
  configure()
  refresh()
  try
  {
      unschedule()
  }
  catch (e)
  {
  }
  runEvery3Hours(refreshTime)
  if (EnergyResetInterv == "Daily") {
      schedule("0 0 0 ? * *", reset) 
  } else if (EnergyResetInterv == "Weekly") {
      schedule("0 0 0 ? * 1", reset)
  } else if (EnergyResetInterv == "Monthly") {
      schedule("0 0 0 1 * ?", reset)
  } else if (EnergyResetInterv == "Yearly") {
      schedule("0 0 0 1 1 ?", reset)
  }

}
}

Thanks for your help!

The only thing I see at first glance is that Hubitat documents schedule() as:

void schedule(String expression, String handlerMethod, Map options = null)

Therefore, your calls should look something like this:

schedule("0 0 0 ? * *", "reset")

instead of this:

schedule("0 0 0 ? * *", reset)

(That is, of course, assuming there isn't more we can't see--like if reset is a String variable or getReset() is a String-returning method you declared somewhere else.)

That being said, this is a bit confusing because the example Hubitat goes on to provide violates this signature:

   // run 'mymethod' every tenth minute.
   schedule('0 */10 * ? * *', mymethod)

So, I can't guaranteee that this is your problem. :slight_smile: (In other cases or at least some other cases where the docs are ambiguous, Hubitat seems to handle this fine and just use the string representation of the method name you provide.)

If that doesn't help, I'd provide a minimal, non-working example of an app generates this error for you (i.e., try to take out anything extra and just provide an example of a fully formed app that fails--with the least amount of your own code--to demonstrate the apparent failure). One of two things is then likely to happen: someone can easily copy/paste the code into their IDE and more easily troubleshoot why it doesn't work, or you may discover a seemingly unrelated problem/cause that solves the issue at hand in the process of trying to isolate this one. The latter happens quite often, in my experience, when people try this.

Good luck!

Hi,

I've tried with the reset between "", and still does not work.

But I will try what you are proposing regarding the "non-working" example, it is a good idea.

Thanks!

Something else just came to my mind: is your code part of a thermostat driver, by chance? (Capability "Thermostat" or "ThermostatSchedule," though it's technically now deprecated in the former.) If so, there is a built in setSchedule() command/method that is required for these capabilities (or really only the latter on 2.2.6 and newer), and Groovy will treat that as a write-only schedule property on the class (your driver) by default. Others have worked around this problem by defining a "dummy" method like def getSchedule() {} to trick it into not thinking this.

You are right, my code is part of a thermostat driver and has the capabitiy "Thermostat". In the base code that I took, there was this function
def setSchedule(JSON_OBJECT){
log.info "setSchedule(JSON_OBJECT): is not available for this device"
}
since the thermostat does not have the capability to have "internal" schedule. So, by commenting those line, I'm able now to set schedule for the method that I want too.

I do imagine by commenting those line, error will happen if someone try to use the thermostat scheduler built-in app. So I will try to do the work arround with the dummy method, but for now, I know where the error is comming from.

Thanks!

Download the Hubitat app