[SOLVED] Displaying image in openHAB

Is it possible to display image in openHAB UI that is collected from MQTT protocol as a base64 data.

MQTT(base64 data)------------->OpenHAB(image)

Not easily. What you would need to do is receive the message and in a Rule decode the base64 into a binary file and save that file to a well-known location under the conf/html folder. You can then set an Item with the name of the Image and use the Image element on your sitemap.

import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.lang.String
import javax.imageio.ImageIO;
rule "image re"
Item getImage received update

 var String base64Image=getImage.state.toString
 logInfo("image","image entered in pir sensor")
var	byte[] imageBytes = javax.xml.bind.DatatypeConverter.parseBase64Binary(base64Image);
	var BufferedImage img 
	try {
		img = ImageIO.read(new ByteArrayInputStream(imageBytes));

	// write the image to a file
	File outputfile = new File("C:\\openhab\\conf\\icons\\classic\\image.png");
	ImageIO.write(img, "png", outputfile);
	} catch (IOException e) {
		// TODO Auto-generated catch block


but nothing is storing in file location

Are you getting errors in the logs?

For example, you are likely getting an error in the line ImageIO.read because read is a static method and one references static methods using ::, e.g. ImageIO::read

am getting this issuse after executing this line img = ImageIO.read(new ByteArrayInputStream(imageBytes));

2017-09-27 11:02:13.975 [ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘image re’: An error occurred during the script execution: Couldn’t invoke ‘assignValueTo’ for feature JvmVoid: (eProxyURI: CDI.rules#|::

Now its working, Thanks just i changed

File outputfile = new File(“C:\openhab\conf\icons\classic\image.png”);


val File outputfile = new File(“C:\openhab\conf\icons\classic\image.png”);

is it possible to show video in openHAB ui