-
Platform information:
- Hardware: _CPUArchitecture: RPi /RAM: ?/storage: 16GB
- OS: openHAB 3.4.1
- Java Runtime Environment: I don’t know
- openHAB version: 3.4.1
-
Issue of the topic: I have changed the state of the items, the Timer_state item remains on “NULL” and I do not see any change. Anyone have an idea what to do?
-
Please post configurations (if applicable):
- Items configuration related to the issue:
timer.items file in openhab-conf/items
- Items configuration related to the issue:
Switch mySwitch "My Switch"
Switch mySwitch_reset "My Switch Reset"
String Timer_state "Timer State [%s]"
- Rules code related to the issue:
timer.py file in openhab-conf/automation/jsr223
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
var DateTime start = now()
var Timer timer = null
rule "start timer"
when
Item mySwitch received command ON
then
start = now()
timer = createTimer(1000, [[
elapsed = (24*60*60) - ((now().millis - start.millis)/1000)
postUpdate(Timer_state, formatElapsed(elapsed))
]])
end
rule "reset timer"
when
Item mySwitch_reset received command ON
then
start = now()
postUpdate(Timer_state, formatElapsed((24*60*60)))
if(timer != null) {
timer.cancel()
timer = null
}
end
def formatElapsed(elapsed) {
def hours = elapsed / (60 * 60)
elapsed -= hours * (60 * 60)
def minutes = elapsed / 60
elapsed -= minutes * 60
def seconds = elapsed
return String.format("%02d:%02d:%02d", hours, minutes, seconds)
}
- If logs where generated please post these here using code fences: No error log and no logs about automation
Thanks in advance!