How can I include a chart in an email report?

is it possible to include a chart in an email remote?
In my case I am looking for a solution to the get the solar power generation by email. In this email I want to get some more information: total power and the chart of the day before.
Is this somehow possible?

Thanks

Hello there,

what kind of chart are you talking about? Grafana?

The standard openHAB charts can be created directly, see Here..
In order to include such a chart in an email I would use an external html-to-picture converter. Something like the one I was talking about in Here

1 Like

Thanks, this was really helpful
I got the external html-to-picture converter for several html pages, but it does not work for my default sitemap in which I have the graphs.

this works, but does not contain anything interesting:

sudo xvfb-run wkhtmltoimage --crop-h 350 --crop-w 350 http://192.168.2.121:8080/static/index.html /home/pi/IOTstack/MyPicture.jpg

but this does not work (my basic UI)

sudo xvfb-run wkhtmltoimage --crop-h 350 --crop-w 350 http://192.168.2.121:8080/basicui/app /home/pi/IOTstack/MyPicture.jpg

How can I get my graphs into the http://192.168.2.121:8080/static/ ?

Hello Elias,
the simple build in chart is all I need :wink:

I need the chart to be reportet by an email,
Thank you for you help.

I want the same thing,
I hope that I can execute the external html-to-picture by a crontab in Linux and from Openhab send a mail from a rule with:
sendMail(“test@hotmail.com”, “Electrical Consumtion”, “Graph of todays energy consumption”, “file:///home/pi/IOTstack/MyPicture.jpg”)

I have not verified that this will work - first step is to get the picture, but I can not get a jpg export of my graph in opehab - I need some help with this step

You could use a script to capture a Grafana chart if running on Raspberry or Linux.

The stored image you can use to send to your email.

Thanks Charley - Finally got it to work. I run Openhab on raspberry pi using docker:

  1. Raspberry pi: sudo apt install cutycapt
  2. Openbhab generate separate sitemaps for each graph you want to mail: conf/sitemaps/Electric_Power.sitemap
sitemap default  {
Chart item=ElectricalPower label="Last hour Temp" service="influxdb" period=D refresh=30000 //visibility=[Temp_Chart_Period==1]

}
  1. Raspberry pi: crontab -e (will run 23:56 etc. CET):
56 22 * * * xvfb-run --server-args="-screen 0, 640x480x24" cutycapt --url=http://192.168.2.121:8080/basicui/app?sitemap=OutDoor_Temp --out=/home/pi/IOTstack/volumes/openhab/userdata/tmp/OutDoor_Temp.png >/dev/null 2>&1
57 22 * * * xvfb-run --server-args="-screen 0, 640x480x24" cutycapt --url=http://192.168.2.121:8080/basicui/app?sitemap=Electric_Power --out=/home/pi/IOTstack/volumes/openhab/userdata/tmp/Electric_Power.png >/dev/null 2>&1
58 22 * * * xvfb-run --server-args="-screen 0, 640x480x24" cutycapt --url=http://192.168.2.121:8080/basicui/app?sitemap=District_Heating_Volume --out=/home/pi/IOTstack/volumes/openhab/userdata/tmp/District_Heating_Volume.png >/dev/null 2>&1
59 22 * * * xvfb-run --server-args="-screen 0, 640x480x24" cutycapt --url=http://192.168.2.121:8080/basicui/app?sitemap=District_Heating_Volume_Week --out=/home/pi/IOTstack/volumes/openhab/userdata/tmp/District_Heating_Volume_Week.png >/dev/null 2>&1
  1. Rules in Openhab:
import java.util.List
rule "Reset Cost"
when
   Time cron "0 1 0 * * ?" 
   
then
  	var doorbellmessage = "El Konsumption="+ ElectricalCost2.state as DecimalType  + "Kr. Fjärr Värme Konsumption="+ DistricHeatingCost2.state as DecimalType + "Kr. Medel Temperatur=" + TemperatureAverage.state as DecimalType + "C" +"\nMvH Patrik"  
        val List<String> attachmentUrlList = newArrayList(
        "file:tmp/Electric_Power.png",
        "file:tmp/District_Heating_Volume.png",
        "file:tmp/District_Heating_Volume_Week.png",
        "file:tmp/OutDoor_Temp.png"
        )
	sendMail("Test@hotmail.com", "Dagens Energi Kostnad", doorbellmessage, attachmentUrlList)
	
end

Great job,
I am sending an email and a telegram with a small video file when someone rings my doorbell or the mail has dropped something in my mailbox.

Could you mark my answer as a solution.

Hi Patrick,

I am trying to do something similar, but I don’t have much experience with linux and permission issues, etc. I installed cutycapt and xvfb:

sudo apt install cutycapt
sudo apt-get install xvfb

I am trying to see if the command work first (take a screenshot of sitemap, and save the png file in the html folder), then I’ll put the command inside a .sh file, and run the script using executeCommandLine in a rule.

In putty terminal:

openhabian@FlowerRoom2:~ $ 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
[1] 1514
-bash: --out=/etc/openhab2/html/Grafana_Temp.png: No such file or directory
openhabian@FlowerRoom2:~ $ xvfb-run: error: Xvfb failed to start

Then I used sudo:

openhabian@FlowerRoom2:~ $ 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
[1] 1655
-bash: --out=/etc/openhab2/html/Grafana_Temp.png: No such file or directory

Could someone please assist me? I don’t have enough knowledge or experience to figure this out. Thank you.

FYI: openhab2.5.12, RPi3B+. influxdb and grafana running smoothly as well.