Command line and e-mail attachments

So, let me explain what I am trying to do… I have a MotionEye server that manages a few cameras. With OH2, I am trying to write a rule that will send a still image when a door opens, or motion is detected inside. This is what I have come up with so far for the rule:

import java.util.List    
rule "Room Entry"
                Item ContactRoom changed from OFF to ON
    			var String results = executeCommandLine("wget -O /etc/openhab2/tmp/Room http://[MotionEye-IP&Port]/picture/X/current"
    	    	val List<String> attachmentUrlList = newArrayList(

sendMail ("[10-Digit=Phone#]", "OpenHAB", "Entry Door has been opened", attachmentUrlList)

I don’t have a lot of experience writing rules, so any help would be appreciated. It appears that anything after the “//” in the “var String results” line gets ignored. I should note that this rule works if I eliminate the attachment parts, meaning I get the text message when the door opens, it is just the file attachment that is causing me the headache.


Probably worth reviewing earlier threads e.g.

Thanks Rossko, I did read that post, however, what they did, did not work with my OH2 setup (they were using OH1.8). I should have prefaced my post with “I have searched the forum and could find a post that could resolve my issue”…

A post in that thread explicitly notes that // means to comment out the rest of the line. That still applies in OH2. Later in your own code you use /// instead.

Yes, Rossko, as I stated in my last post, I did see that post (and several other posts) about sendMail and url attachments, but that did not resolve my issue. I have the the “///” in my rule now, but it is still not working.
For some reason, the file is still not being downloaded to my /etc/openhab2/tmp/ folder, so I am not sure that this is not just a permissions issue. I made sure that the “tmp” folder has the same owner and group as the “rules” folder (openhab/openhabian).
I used the sample code from the Mail - Actions wiki page for the attachment part of the rule, and they only use the “///” for a file path, not a url path, but I did try all combinations, and none worked. I think It has to be something with that specific line though, I have tried both curl and wget to download the file, but neither seem to save or download the file when executed from my rule (but both work outside the rule, typing directly into the command line).
I have also tried a timer to wait until the file is downloaded before attaching and sending the e-mail, but that did not have any effect either, so I removed that part of the rule.

I am running OH2 and copied the rule from the same post others mentioned before. I had to remove the delay value from the executeCommandLine and it worked for me. Your “executeCommandLine” line is missing a closing parentheses at the end of the line but IDK if that is the issue or not. I’m downloading a picture from a hikvision camera so its not exactly the same as your situation but below is my rule for reference if you need it.

rule "side doorbell on"
    Item sideDoorbell changed from OFF to ON
	sendNotification("", "Side Doorbell on")
	say("Side Doorbell On")
	var SideDoorCam = "SideDoor.jpg"
    var doorbellmessage = "Side Doorbell on at "+ now.toString ("HH:mm dd-MM-yyyy")
    executeCommandLine("wget http://user:password@ -O /tmp/" + SideDoorCam)
    sendMail("", "Side Doorbell On", doorbellmessage, "file:///tmp/" +SideDoorCam)


Thank you for the reference, I decided to cut and paste it then only change the necessary details and it worked. My problem appears to be a folder permissions issue. Apparently, my creating of a “tmp” folder in the openhab2 directory was not allowing the download of the images. So it was the “/tmp/” folder reference that fixed it. I tried this in my original code and that one works too.

Thanks again,


After updating OH to version 2.1, my rule does not work anymore.
In version 2.0, it still worked.

After a doorcall, a snapshot was taken and after 4 seconds again. After that, these snapshots were sent to my gmail.

I have no idea what’s wrong with this rule

var Number counter = 1
var Timer timer = null

//  camera upload naar Gmail

  rule "Camera upload"


 Item test changed to ON


var  Cam1 = "Links1" +".jpg"
var  Cam2 = "Rechts1" +".jpg"
var  Cam3 = "Links2" +".jpg"
var  Cam4 = "Rechts2" +".jpg"

executeCommandLine("wget http://login:passwd@ipadres/Streaming/channels/1/picture -O /tmp/" + Cam1,5)
executeCommandLine("wget http://login:passwd@ipadres/Streaming/channels/1/picture -O /tmp/" + Cam2,5)

val List<String> attachmentUrlList = newArrayList(

executeCommandLine("wget http://login:passwd@ipadres/Streaming/channels/1/picture -O /tmp/" + Cam3,5)
executeCommandLine("wget http://login:passwd@ipadres/Streaming/channels/1/picture -O /tmp/" + Cam4,5)


sendMail("","Bezoek","Bezoeker heeft om "+now.toString("HH:mm:ss")+" aangebeld", attachmentUrlList)


See if you can find out. Anything related reported in logs? Is the rule triggered? Add logInfo() to follow progress. Are the snapshot files generated? Is the email sent?