I have the following rule:
rule "Driveway Laser 1 Trigger"
when
Item DrivewayLaser1Status changed to CLOSED
then
var String Timestamp = df.format( new Date() )
/* Email photo from Driveway CCTV, but only once every 15 seconds */
if(DrivewayLaser1EmailTimer == null || DrivewayLaser1EmailTimer.hasTerminated) {
sendMail("me@me.com", "Driveway Laser Triggered " + Timestamp, "The driveway laser has been triggered on " + Timestamp + ".", "http://camera.local.ip.addy/onvif/snapshot")
DrivewayLaser1EmailTimer = createTimer(now.plusSeconds(15), [|
DrivewayLaser1EmailTimer = null
])
}
end
The rule technically works, but the problem I’ve got is the sendMail() appears to download the attachment 4 times, and only send the last one.
eg, the clock on the camera and the openhab server are synced, An email will turn up with the Timestamp variable being 2017-04-08 18:36:13, but the camera time will be 2017-04-08 18:36:21. Due to the nature of what this is trying to trigger it often means the picture I get is too late.
Debug logs below, is it potentially not getting the right mime to start with and then constantly retrying? Is this potentially a bug with sendMail? If it sent the first image it tried to download everything would be good!
2017-04-08 19:01:36.827 [ItemStateChangedEvent ] - DrivewayLaser1Status changed from OPEN to CLOSED
2017-04-08 19:01:36.829 [DEBUG] [rg.quartz.core.QuartzSchedulerThread] - batch acquisition of 0 triggers
2017-04-08 19:01:37.257 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@20f78eb35 pairs: {GET /onvif/snapshot HTTP/1.1: null}{User-Agent: Java/1.8.0_121}{Host: openhab.server.ip.addy}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2017-04-08 19:01:38.170 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@4074d1e3 pairs: {null: HTTP/1.1 200 OK}{Content-Type: image/jpeg}{Content-Length: 326820}
2017-04-08 19:01:38.172 [DEBUG] [javax.activation ] - MailcapCommandMap: createDataContentHandler for text/plain
2017-04-08 19:01:38.172 [DEBUG] [javax.activation ] - search DB #1
2017-04-08 19:01:38.172 [DEBUG] [javax.activation ] - got content-handler
2017-04-08 19:01:38.172 [DEBUG] [javax.activation ] - class com.sun.mail.handlers.text_plain
2017-04-08 19:01:38.174 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@219b54485 pairs: {GET /onvif/snapshot HTTP/1.1: null}{User-Agent: Java/1.8.0_121}{Host: openhab.server.ip.addy}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2017-04-08 19:01:39.216 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@3d05d4de3 pairs: {null: HTTP/1.1 200 OK}{Content-Type: image/jpeg}{Content-Length: 324668}
2017-04-08 19:01:39.216 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@35411dd5 pairs: {GET /onvif/snapshot HTTP/1.1: null}{User-Agent: Java/1.8.0_121}{Host: openhab.server.ip.addy}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2017-04-08 19:01:40.151 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@65820b7f3 pairs: {null: HTTP/1.1 200 OK}{Content-Type: image/jpeg}{Content-Length: 325024}
2017-04-08 19:01:43.732 [DEBUG] [javax.activation ] - MailcapCommandMap: createDataContentHandler for multipart/mixed
2017-04-08 19:01:43.732 [DEBUG] [javax.activation ] - search DB #1
2017-04-08 19:01:43.732 [DEBUG] [javax.activation ] - search DB #2
2017-04-08 19:01:43.732 [DEBUG] [javax.activation ] - search fallback DB #1
2017-04-08 19:01:43.733 [DEBUG] [javax.activation ] - got content-handler
2017-04-08 19:01:43.733 [DEBUG] [javax.activation ] - class com.sun.mail.handlers.multipart_mixed
2017-04-08 19:01:43.733 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@688efa535 pairs: {GET /onvif/snapshot HTTP/1.1: null}{User-Agent: Java/1.8.0_121}{Host: openhab.server.ip.addy}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
2017-04-08 19:01:44.166 [DEBUG] [.www.protocol.http.HttpURLConnection] - sun.net.www.MessageHeader@3dd1504e3 pairs: {null: HTTP/1.1 200 OK}{Content-Type: image/jpeg}{Content-Length: 324760}
2017-04-08 19:01:46.111 [DEBUG] [rg.openhab.action.mail.internal.Mail] - Sent email to 'me@me.com' with subject 'Driveway Laser Triggered 2017-04-08 19:01:36'.
Versions FYI:
openhab> bundle:list -s | grep openhab
166 | Active | 90 | 2.0.0 | openHAB Core | org.openhab.core
167 | Active | 80 | 2.0.0 | openHAB Karaf Integration | org.openhab.core.karaf
169 | Resolved | 80 | 2.0.0 | openHAB Sound Support, Hosts: 111 | org.openhab.io.sound
170 | Active | 80 | 2.0.0 | openHAB Dashboard UI | org.openhab.ui.dashboard
176 | Active | 80 | 2.0.0 | openHAB 1.x Compatibility Layer | org.openhab.core.compat1x
200 | Active | 80 | 2.0.0 | openHAB REST Documentation | org.openhab.io.rest.docs
201 | Resolved | 80 | 2.0.0 | openHAB Basic UI Fragment, Hosts: 197 | org.openhab.ui.basicui
202 | Active | 80 | 2.0.0 | openHAB Classic UI Fragment | org.openhab.ui.classicui
203 | Active | 80 | 2.0.0 | HABmin User Interface | org.openhab.ui.habmin
204 | Active | 80 | 2.0.0 | HABPanel User Interface | org.openhab.ui.habpanel
205 | Resolved | 80 | 2.0.0 | openHAB Paper UI Theme Fragment, Hosts: 199 | org.openhab.ui.paperui
209 | Active | 80 | 1.9.0.201701200211 | openHAB Piface Binding | org.openhab.binding.piface
210 | Active | 80 | 1.9.0 | openHAB Mail Action | org.openhab.action.mail
211 | Active | 80 | 1.9.0 | openHAB Twitter Action | org.openhab.action.twitter
213 | Active | 80 | 2.0.0 | ZWave Binding | org.openhab.binding.zwave
214 | Active | 80 | 1.9.0 | openHAB Serial Binding | org.openhab.binding.serial
215 | Active | 80 | 1.9.0 | openHAB MQTT Binding | org.openhab.binding.mqtt
216 | Active | 80 | 1.9.0 | openHAB MQTT Transport Bundle | org.openhab.io.transport.mqtt
217 | Active | 80 | 1.9.0 | openHAB RRD4j Persistence Bundle | org.openhab.persistence.rrd4j
218 | Active | 80 | 1.9.0 | openHAB InfluxDB Persistence bundle | org.openhab.persistence.influxdb
219 | Active | 80 | 2.0.0 | Network Binding | org.openhab.binding.network