- Platform information:
- OS: Ubuntu Linux, 18.04.2 LTS
- OpenJDK 10.0.2, runtime 10.0.2+13
- OpenHAB 2
I’m a pretty experienced programmer (Python, BASH), so I’m either mixing languages or, having been coding for the last two days, might well have lost it… but here’s what I’m seeing and I’d sure be grateful for another pair of eyes…
I’ve written a Python program to telnet into an Ademco 20p and parse the stream for status. The switches it effects are in good shape and work consistently. The idea behind this code is that when it just detects presence - I’ve just arrived home, JustArrived.state == ON - there’s no point in telling me the front door is open because I will have just opened it. If however I’ve been home a while (JustArrived.state == OFF && groupPresence.state == ON) then if the front door opens let me know. If I’m not home and have been away for a while, send me a chat message via XMPP.
rule "alarm front door"
when
Item AlarmFrontDoor changed from ON to OFF
then
logInfo("AlarmStatus-arr-rule", "WTF.state="+JustArrived.state)
if ((JustArrived.state == OFF) || (JustArrived.state == NULL)) {
if (groupPresence.state == ON) {
say("The front door is open", "pollytts:Salli", "enhancedjavasound")
} else {
sendXMPP("username1@email.com", "The front door has been opened!")
sendXMPP("username2@email.com", "The front door has been opened!")
}
} else {
logInfo("AlarmStatus-arr-rule", "justarrived home: "+JustArrived.state)
}
end
What actually happens though, as you’ll see in the logs, is that it’ll do both: when I’ve just arrived home, it’ll tell me the door is open AND log “justarrived home” . The following logs show checkpoints showing status of the switches.
2019-02-24 13:45:22.619 [DEBUG] [ce.pollytts.internal.PollyTTSService] - Audio Stream for 'User has arrived home' in format AudioFormat [codec=MP3, container=NONE, bitDepth=16, bitRate=64000, frequency=22050]
2019-02-24 13:45:33.410 [INFO ] [me.model.script.AlarmStatus-arr-rule] - WTF.state=ON
2019-02-24 13:45:33.411 [DEBUG] [ce.pollytts.internal.PollyTTSService] - Synthesize 'The front door is open' in format AudioFormat [codec=MP3, container=NONE, bitDepth=16, bitRate=64000, frequency=22050
]
2019-02-24 13:45:33.412 [DEBUG] [ce.pollytts.internal.PollyTTSService] - voice UID: 'pollytts:Salli' voice label: 'Salli' voice Locale: en_US
2019-02-24 13:45:33.413 [INFO ] [me.model.script.AlarmStatus-arr-rule] - justarrived home: ON
2019-02-24 13:45:33.413 [DEBUG] [ce.pollytts.internal.PollyTTSService] - Audio Stream for 'The front door is open' in format AudioFormat [codec=MP3, container=NONE, bitDepth=16, bitRate=64000, frequency=22050]
As you see from the WTF.state, the switch is ON so ==OFF OR ==NULL should not be satisfied and it should only log “justarrived home:”, but it does both tell me the door is open AND log…? It does not, however, both tell me AND send an XMPP text… so ELSE works… sometimes.
I’ve refactored this code in three different ways… I don’t know what the deal is.
Anybody…?