Hardware: RPi3 B+
openHAB version: openhab2.5.12 (v1.6.1b)
FYI: I have some experience with Java and C++, but I do not have much experience with linux, shell scripting, or permission issues, etc. So please excuse my ignorance. I have spent a few days trying to learn, understand and figure it out, but I haven’t been successful. I have no other choice but to ask the community for help. This might be a long post, since I have tried to explain as much as I think might be relevant. Hopefully a kind soul will see this and act as a mentor.
This is probably my first topic ever, so if I make any mistake or do things incorrectly, please advise how I can do it correctly.
I am trying to follow this post:
Some things I would like to do differently:
- instead of using crontab, I would like to use a rule which will trigger once a day, take a screenshot of my sitemap and save in /etc/openhab2/html folder
- then another rule will send an email with that png as an attachment
How exactly does executeCommandLine work? I am still not sure that I understand. From the docs, I see it can execute a .sh file, like we would from the terminal ./file.sh, but it does not run like any command from a linux terminal? Almost all of the examples that I have seen in the community forums execute a .sh file using executeCommandLine.
IF thats the case, then I can write a .sh file (as of now I do not know exactly how to do this) which will contain the commands to take screenshot and save it as a png (contents of Rule 1 below), put this file in the scripts directory of openhab (/etc/openhab2/scripts), then execute this file using executeCommandLine in a rule.
Before putting anything in a rule, I tried to run the command from the terminal (putty) and see if it works and saves a screenshot in the directory provided:
sudo xvfb-run --server-args="-screen 0, 640×480x24" cutycapt --url=http://192.168.1.252:8080/basicui/app?w=0300&sitemap=FR2 --out=/etc/openhab2/html/Grafana_Temp.png
This returns:
[1] 17496
-bash: --out=/etc/openhab2/html/Grafana_Temp.png: No such file or directory
I have no idea what that means, because that directory (html folder) definitely exists. Ideally, my two rules would be as follows:
rule "Rule 1: take screenshot and save grafana chart"
when
Time Cron "0 0 12 ? * * *" //At 12:00:00pm every day
then
logInfo("Notification", "screenshotGrafana RULE triggered")
executeCommandLine("xvfb-run --server-args="-screen 0, 640×480x24" cutycapt --url=http://<ip_address>:8080/basicui/app?w=0300&sitemap=FR2 --out=/etc/openhab2/html/Grafana_Temp.png")
end
Inside the executeCommandLine(“”), should I use \ for the quotation marks around --server-args=“-screen 0, 640×480x24” ?
Like this:
executeCommandLine("xvfb-run --server-args=\"-screen 0, 640×480x24\" cutycapt --url=http://192.168.1.252:8080/basicui/app?w=0300&sitemap=FR2 --out=/etc/openhab2/html/Grafana_Temp.png")
rule "Rule 2: send grafana screenshot as email attachment"
when
Time Cron "0 0 13 ? * * *" //At 13:00:00pm every day
then
logInfo("Notification", "Sending email with screenshotGrafana - RULE triggered")
//for now just one screenshot, later I'll add another file when I have this working
val List<String> emailAttachments = newArrayList(
"file:/etc/openhab2/html/Grafana_Temp.png"
)
val mailActions = getActions("mail","mail:smtp:sample") //
mailActions.sendMail("myname@myemail.com", "Email-Notification", emailAttachments)
end
Any suggestions, advice, tutorials would be highly appreciated. Thank you!