So after many attempts at this I refer to the gods
Basically what I am trying to do, And its not workingâŠ
//* Send selected temperature to MyTotalConnect *)
rule "IndHeatSet"
when
Item IndHeatSet received command
then
if(timer==null) {
timer = createTimer(now.plusSeconds(10)) [|
logInfo("Security", "Timer Set")
sendCommand(SendTemp, receivedCommand) ]
} else {
if(timer!=null) {
timer.reschedule(now.plusSeconds(10))
logInfo("Security", "Rescheduling Timer")
}
}
end
Goal:
When the thermostat app sends a temp to it it timers it to 10 seconds before it sends it out If you hit the temperature up a few degrees at a time it just resets the timer instead of sending EVERY change outâŠ
Also not sure what you mean on the item state thing⊠Not that familiar. If you mean like " If item == ON" kinda thing Im not sure how i would do that with a setpoint.
You can try SendTemp.sendCommand(receivedCommand as DecimalType)
or, as Rich suggested, SendTemp.sendCommand(IndHeatSet.state) IndHeatSet.state should be the very same as receivedCommand, as IndHeatSet is the Item that triggers the rule. receivedCommand as DecimalType would cast the state to number, just to ensure there is a valid value.
This is my current setup which isnt working. Tried all of the above.
var Timer timer = null
//* Send selected temperature to MyTotalConnect *)
rule "IndHeatSet"
when
Item IndHeatSet received command
then
if(timer = null) {
timer = createTimer(now.plusSeconds(10)) [|
logInfo("Security", "TIMER: Heat Timer Set")
//* SendTemp.sendCommand(IndHeatSet.state) ]
SendTemp.sendCommand(receivedCommand as DecimalType) ]
timer = null
} else {
timer.reschedule(now.plusSeconds(10))
logInfo("Security", "TIMER: Rescheduling Heat Timer")
}
}
end
Error:
2016-04-13 08:48:12.936 [ERROR] [o.o.c.s.ScriptExecutionThread ] - Error during the execution of rule âIndHeatSetâ: cannot invoke method public abstract boolean org.openhab.model.script.actions.Timer.reschedule(org.joda.time.base.AbstractInstant) on null.
Beware of mixing â//â style comments and â/"style comments. It doesnât appear to be a problem here but some languages will have a hard time when you use "//â. And for all I know it mght be causing problems here.
You are assigning timer to null inside your if statement. You need to use â==â to compare for equality and â=â for assignment.
Use proper indentation to more easily see what context your lines are in. Any time you start a new context (i.e. â{â or â[â) indent the lines inside that new context.
var Timer timer = null
// Send selected temperature to MyTotalConnect
rule "IndHeatSet"
when
Item IndHeatSet received command
then
if(timer = null) {
timer = createTimer(now.plusSeconds(10)) [|
logInfo("Security", "TIMER: Heat Timer Set")
// SendTemp.sendCommand(IndHeatSet.state)
SendTemp.sendCommand(receivedCommand as DecimalType)
]
timer = null
} else {
timer.reschedule(now.plusSeconds(10))
logInfo("Security", "TIMER: Rescheduling Heat Timer")
}
}
end
With the proper indentation additional problems become obvious. You are resetting the timer to null outside the timer.
There is an extra â}â at the end of your rule. Iâm surprised OH was able to even load your file but I suspect that any rule in the file after this one does not exist because of this syntax error. Errant opening and closing brackets can cause massive problems. I highly recommend using Designer to write rules at it will point out these types of errors.
Also, you are using receivedCommand which will only have the state as it was when the timer was first created. Donât you really want to send the current state (i.e. if the timer has been rescheduled you want to send the new/current value, not that first value). If not realize that any changes made while the timer is active will be lost.
The rule should be:
var Timer timer = null
// Send selected temperature to MyTotalConnect
rule "IndHeatSet"
when
Item IndHeatSet received command
then
if(timer == null) {
timer =createTimer(now.plusSeconds(10), [|
logInfo("Security", "TIMER: Heat Timer triggered")
SendTemp.sendCommand(IndHeatSet.state as DecimalType)
timer = null
])
logInfo("Security", "TIMER: Heat Timer Set")
} else {
timer.reschedule(now.plusSeconds(10))
logInfo("Security","TIMER: Rescheduling Heat Timer")
}
end
Instead of creating a new topic, i will recycle this one:
i have a problem with a timer, which helps me setting a global variable for human presence in the living room, which is used for switching lights:
var Timer timer = null
rule "Presence Wohnzimmer"
when
Item alarm_multisensor_3 received update or
Item sw_tv_wohnzimmer changed
then
if (timer != null) {
timer.cancel
timer = null
}
Thread::sleep(10000)
presence_wohnzimmer = 1
timer = createTimer(now.plusMinutes(20)) [|
presence_wohnzimmer = 0
]
end
I thought that was working so far. But yesterday i mentioned, that my lights turned off when i didnât expect it, because i went through the living room and saw, that the movement sensor recognized me (led). My events say:
2016-10-05 19:23:05 - alarm_multisensor_3 state updated to 0
2016-10-05 19:24:18 - alarm_multisensor_3 state updated to 0
and my lights turned off
2016-10-05 19:25:00 - sw_light_wohnzimmer received command OFF
but shouldnât, because presence_wohnzimmer should have been 1, because of the 2 events before.
My first question is: where is the definition of presence_wohnzimmer?
2nd: why doing a Thread::sleep()?
3rd: which rule did switch of sw_light_wohnzimmer?
Hi,
thanks for your reply. Here the answers of your questions:
1st:
In the global part of the file:
var Number presence_wohnzimmer = 0
2nd:
The presence_wohnzimmer is a condition for switching on lights (see also 3rd). The 10seconds are a small time window, if you want to ventilate the room and open the terrasse door, to avoid toggeling the light, because opening the door will switch off the lights immediately.
3rd:
rule "Automatik Wohnzimmer"
when
Time cron "0 0/1 * * * ?"
then
// Einschalten bei Anwesenheit in Wohnung und Wohnzimmer, nach 16:00Uhr
if (sw_lueften.state == OFF && auto_on_light_wohnzimmer == 0 && presence.state == ON && now.getHourOfDay() >= 16 && presence_wohnzimmer == 1) {
// Einschalten nach Sonnenuntergang
if (now.isAfter((sunset_time.state as DateTimeType).calendar.timeInMillis)) {
if (sw_light_wohnzimmer.state != ON) sendCommand(sw_light_wohnzimmer, ON)
auto_on_light_wohnzimmer = 1
}
// Einschalten nach Helligkeitssensor
else if (lumen_multisensor_3.state <= thres_lumen) {
if (sw_light_wohnzimmer.state != ON) sendCommand(sw_light_wohnzimmer, ON)
auto_on_light_wohnzimmer = 1
}
}
// Abschalten bei fehlender Anwesenheit und abgeschaltetem TV im Wohnzimmer nach mindestens 10min Leuchtdauer
if (auto_on_light_wohnzimmer == 1 && sw_tv_wohnzimmer.state != ON && presence_wohnzimmer == 0 && !sw_light_wohnzimmer.changedSince(now.minusMinutes(10))) {
if (sw_light_wohnzimmer.state != OFF) sendCommand(sw_light_wohnzimmer, OFF)
auto_on_light_wohnzimmer = 0
}
end
To paste code, you have to use code fences (2nd right button at the edit area, or type three backticks in a row before and after the code:
```
your code goes here
```
Itâs essential to leave the backticks in itâs own rows.
In question of your code, I think, Thread::sleep() will not work as you expected. Did you define timer within the global vars? Maybe itâs unhandy to call the timer timer, as this is a keyword (at least Timer is).
Thanks for the hint with the code fences.
Yes, the Timer is defined in the global variables.
The thing i donât understand is, that the timer does work - and the sleep also does work, but not in this one case i mentioned.
Maybe i should try to rename the timer, that was a thing i also thought about.
In question of Thread::sleep(), in case of rule trigger, timer will be cancelled (if running), then thread will sleep for 10 seconds, then presence_wohnzimmer will be set to 1, regardless, if someone left the room already, so the lights will turn on (and off after another 20 minutes). I think your intention was, not to switch on the lights at all, if leaving the room within 10 seconds.
There is a known issue about using global vars/vals in multiple rules files with the same name. I canât remember where I read this on the wiki, probably a note in the Rules wiki page. If you have other rules files with a timer global var this might be a problem.
@Udo:
No, the intension is, that the ambient lights are on if someone has been in the area within the last 20minutes and with any new movement in that area (or switching tv on or off), the timer should reset and there are 20minutes again. But that doesnât work right in the current setting.
The 10seconds delay is only for preventing, that the lights turn on if someone just walks through the area to open the terrace door for ventilation (dontâ want to get mosquitoes between june and september).
@Rich: This is the only timer i have, so that can not be the problem