We have moved at community.getvera.com

Author Topic: Stories of openHAB conversion, co-existence & augmentation  (Read 8748 times)

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #15 on: March 23, 2015, 03:40:51 pm »
PS: I discovered with your example the possibility to call  kTimer.reschedule. In my case, I was first killing the timer and then crating again. Your solution looks better.

I went back to the original model, and updated the examples as such.  I don't think Timer.reschedule works correctly on a Timer that's already completed.  I ran a bunch of experiments last night and, as far as I can tell, it doesn't re-trigger correctly IF the original Timer has already ended.

Offline jdr0berts

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #16 on: March 24, 2015, 05:01:32 pm »
Hi guessed,

I think there's a typo in the night-time script, you have:
Code: [Select]
if (kTimer == null) {
        kTimer.cancel
        logInfo("house-kitchen", "Kitchen-Motion Timer Cancel")
    }

which gives in the logs:
Code: [Select]
Error during the execution of rule 'Hall Motion': cannot invoke method public abstract boolean org.openhab.model.script.actions.Timer.cancel() on null

changing the if statement to
Code: [Select]
if (kTimer == null), solves the problem, although it doesn't seem to allow the timer to cancel and extend?

Also, an additional question - I'm slowly (painfully) trying to migrate to openHab and have moved a timer and have tried my milight rules - anyone else tried milight, as I'm having no end of problems?

Cheers
James

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #17 on: March 24, 2015, 05:44:51 pm »
Thanks for the catch!  The online version has now been corrected.   I made a transcription error on my part as I publish simpler versions of my live rules.

Quote
Also, an additional question - I'm slowly (painfully) trying to migrate to openHab and have moved a timer and have tried my milight rules - anyone else tried milight, as I'm having no end of problems?

I can't tell if you're having issues with a new openHAB-based Binding, or with the rules that are driving it.  Either way, it would pay to open up a thread on the openHAB Google groups, since you'll get a wider set of eyes on it.

That said, if it's a "before-and-after" type scenario, we might also be able to do it here also, esp if the issue is Rule syntax/semantics.  I'm hoping we can get more examples published, since there are a lot of nuances to writing Rules (and having them actually work as expected 8) )

Offline jdr0berts

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #18 on: March 24, 2015, 07:14:06 pm »
Quote
Thanks for the catch!
No problem.

Quote
I'm hoping we can get more examples published, since there are a lot of nuances to writing Rules (and having them actually work as expected 8) )

That would be great, the learning curve is greater than I expected; even after being put off by the level of complexity before. It's the not knowing whether it's a problem with the binding, the rule or something else.

Here's a simple one, I've got the following rule (log statement removed):
Code: [Select]
rule "Lounge Lights Off"
when
Time cron "0 50/1 21 ? * MON-THU,SUN" or
Time cron "0 0/1 22-23,0-4 ? * MON-THU,SUN" or
Time cron "0 45/1 22 ? * FRI-SAT" or
Time cron "0 0/1 23,0-4 ? * FRI-SAT"
then

if (Network_TV.state == OFF && Network_Amp.state == OFF)
{
sendCommand(Light_GF_LoungeLamps, OFF)
}
end

For some reason, it will run when I've saved the rule and it gets reloaded, but the following day, it never restarts and I'm at a loss as to why!  (I'll post to google groups too).

Offline jdr0berts

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #19 on: March 24, 2015, 07:19:51 pm »
One further thing, I've ommitted this section from the example:
Code: [Select]
if (KitchenMotionZoneArmed.state != ON) {
        logInfo("house-kitchen", "Kitchen-Motion Not Armed, skipping")
        return void
}

As of yesterday, whenever I restart the rule, the motion sensor is set to not armed for some reason - I've never knowingly disarmed it.

Cheers
James

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #20 on: March 24, 2015, 07:54:52 pm »
One further thing, I've ommitted this section from the example:
Code: [Select]
if (KitchenMotionZoneArmed.state != ON) {
        logInfo("house-kitchen", "Kitchen-Motion Not Armed, skipping")
        return void
}

As of yesterday, whenever I restart the rule, the motion sensor is set to not armed for some reason - I've never knowingly disarmed it.

Cheers
James

For this, make sure you have Persistence on, and data being actively collected, for the Item being evaluated.

Without persistence, a "flush" of Item State (because of a Repository Rule/Item change, for example) can leave the value in "UnDef" state, which will cause it to skip.

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #21 on: March 24, 2015, 08:03:40 pm »
Here's a simple one, I've got the following rule (log statement removed):
Code: [Select]
rule "Lounge Lights Off"
when
Time cron "0 50/1 21 ? * MON-THU,SUN" or
Time cron "0 0/1 22-23,0-4 ? * MON-THU,SUN" or
Time cron "0 45/1 22 ? * FRI-SAT" or
Time cron "0 0/1 23,0-4 ? * FRI-SAT"
then

if (Network_TV.state == OFF && Network_Amp.state == OFF)
{
sendCommand(Light_GF_LoungeLamps, OFF)
}
end

For some reason, it will run when I've saved the rule and it gets reloaded, but the following day, it never restarts and I'm at a loss as to why!  (I'll post to google groups too).

Switch to DEBUG Mode logging and see if there are other clues.  I ran each expression through a Cron/Quartz eval tool and they appear correct.

That said, since you know when the Amp and TV are off, it may be easier to write it as events against those changing state, and then perform DateTime calcs within the rule.  It'll definitely be less taxing on the system, since it's only have to Eval each time the TV or Amp changes it's power-state.

Offline jdr0berts

  • Newbie
  • *
  • Posts: 15
  • Karma: +0/-0
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #22 on: March 27, 2015, 04:14:50 am »
Thanks again - it seems to be working again now, though I can't work out what changed.

Yes - I'd come to a similar conclusion about reducing the number of repeated cron calls, I'll still need a timed action for when the TV or Amp aren't turned off (they're already off), but the bit I can't work out is how to setup a fixed time, I assume the best way to do this would be a DateTime item?
Code: [Select]
DateTime ClockGoodnight  "Goodnight [%1$tH:%1$tM]" <calendar> {"22:10:00"}
which would allow
Code: [Select]
if Goodnight.isafternow

Cheers
James

Offline guessed

  • Moderator
  • Master Member
  • *****
  • Posts: 5301
  • Karma: +92/-22
  • Release compat is not a bolted-on afterthought
Re: Stories of openHAB conversion, co-existence & augmentation
« Reply #23 on: March 27, 2015, 06:43:41 pm »
James,
See the code/Rule snippet I posted to your openHAB Group posting.  It's not 100% of what you're asking for, but it should get you closer.