Doorbell attachement rule permission error & fired multiple times

Hi,

I modified a 10 euro doorbell from Grundig with a wemos running ESPEasy.
When someone hits the switch it should automatically send a message with a screenshot of the camera.
I changed some permissions but I’m unsure how to fix it properly.

I created a rule:

import org.openhab.core.library.types.*

rule "Hall_DoorBell"
when 
  Item Hall_DoorBell received command ON
then
  executeCommandLine("ffmpeg -i rtsp://192.168.1.12/live2.sdp -f image2 -vframes 1 /etc/openhab2/html/screenshots/pic.jpg")

  sendMail("mgkooi@gmail.com", "Hall_DoorBell gaat.", "Er staat iemand voor de deur","http://192.168.1.20:8080/static/screenshots/pic.jpg")
  sendTelegramPhoto("bot1", "http://192.168.1.20:8080/static/screenshots/pic.jpg", "Hall_DoorBell gaat")
  executeCommandLine("rm /etc/openhab2/html/screenshots/pic.jpg")
  sendCommand(Hall_DoorBell, OFF)

end

This is the permission of the file:

[22:39:15] openhabian@openhab:/etc/openhab2/html$ ls -l /etc/openhab2/html/screenshots/
total 32
-rw-rw-r-- 1 openhab openhab 32537 Nov 8 22:39 pic.jpg

But in the log I see this error(s):

22:39:36.253 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Hall_DoorBell' received command ON
22:39:36.256 [INFO ] [marthome.event.ItemStateChangedEvent] - Hall_DoorBell changed from OFF to ON
22:39:36.268 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'ffmpeg -i rtsp://192.168.1.12/live2.sdp -f image2 -vframes 1 /etc/openhab2/html/screenshots/pic.jpg'
22:39:36.291 [ERROR] [rg.openhab.action.mail.internal.Mail] - Error adding attachment to email.
org.apache.commons.mail.EmailException: Invalid URL set:http://192.168.1.20:8080/static/screenshots/pic.jpg
        at org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:395)
        at org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:339)
        at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:120)
        at org.openhab.action.mail.internal.Mail.sendMail(Mail.java:89)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)[:1.8.0_121]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)[:1.8.0_121]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)[:1.8.0_121]
        at java.lang.reflect.Method.invoke(Method.java:498)[:1.8.0_121]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1085)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeOperation(XbaseInterpreter.java:1060)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._invokeFeature(XbaseInterpreter.java:1046)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.invokeFeature(XbaseInterpreter.java:991)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.smarthome.model.script.interpreter.ScriptInterpreter.invokeFeature(ScriptInterpreter.java:114)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:901)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:864)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:223)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter._doEvaluate(XbaseInterpreter.java:446)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.doEvaluate(XbaseInterpreter.java:227)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.internalEvaluate(XbaseInterpreter.java:203)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.xtext.xbase.interpreter.impl.XbaseInterpreter.evaluate(XbaseInterpreter.java:189)[145:org.eclipse.xtext.xbase:2.9.2.v20160428-1452]
        at org.eclipse.smarthome.model.script.runtime.internal.engine.ScriptImpl.execute(ScriptImpl.java:77)[130:org.eclipse.smarthome.model.script.runtime:0.9.0.b5]
        at org.eclipse.smarthome.model.script.engine.ScriptExecutionThread.run(ScriptExecutionThread.java:42)[129:org.eclipse.smarthome.model.script:0.9.0.b5]
Caused by: java.io.FileNotFoundException: http://192.168.1.20:8080/static/screenshots/pic.jpg
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872)[:1.8.0_121]
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1474)[:1.8.0_121]
        at java.net.URL.openStream(URL.java:1045)[:1.8.0_121]
        at org.apache.commons.mail.MultiPartEmail.attach(MultiPartEmail.java:390)
        ... 22 more
22:39:37.679 [ERROR] [ab.action.telegram.internal.Telegram] - Method failed: HTTP/1.1 404 Not Found
22:39:37.685 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine 'rm /etc/openhab2/html/screenshots/pic.jpg'
22:39:37.699 [INFO ] [smarthome.event.ItemCommandEvent    ] - Item 'Hall_DoorBell' received command OFF
22:39:37.711 [INFO ] [marthome.event.ItemStateChangedEvent] - Hall_DoorBell changed from ON to OFF

The file is created successfully by the rule but it cannot be found by the rule but it is actually there

Also when hitting the bell changes 8 times to state ON.
Is it possible to check that in the rule like:
(Item Hall_DoorBell received command ON).count=8

Well, seems sendTelegramPhoto needs its 2nd argument to be a file - you gave a URL.
To fix this, you would need to prefetch that URL to a file first.

Nope, at least not that know of any such possibility.
But you can apply locking. Check for a ‘lock’ variable to be false at the beginning of your processing rule and set it to ‘true’ as the next step. Unset the lock variable at the end.

Hi Markus,

I tested each individual steps, which all works!
I did receive a telegram, with a picture as well as an email.
The thing is that after succesfully create a screenshot by ffmpeg openhab does have insufficient permission to open the file:

22:39:36.291 [ERROR] [rg.openhab.action.mail.internal.Mail] - Error adding attachment to email.
org.apache.commons.mail.EmailException: Invalid URL set:http://192.168.1.20:8080/static/screenshots/pic.jpg

The file is there though.

The sendMail command is not complaining about permissions (and these are ok) but about an invalid URL.
I doubt this command is working standalone as you claim it does.
According to the docs, the 4th argument would need to be a list, not a single URL string. Try that instead.