minmax sensorvärde per dygn

Moderators: hekj, Telldus

orjan
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

minmax sensorvärde per dygn

Post by orjan »

Grafisk termometer inkl minmax värden samt tidsstämpling.

start.bsh

Code: Select all

startTimer("minmax_101_temp", 70);
minmax_101_temp.bsh

Code: Select all

//logga min samt max per dygn till fil
//spara värden för att presentera termometer (.png) 
import java.text.SimpleDateFormat;
sensor = "101";
name = "T1 - Ute";
setData("name" + sensor, name);
temp = getSensorValue(sensor); //sträng
temp_timestamp = getSensorTimestamp(sensor, true);
if (temp_timestamp != null && temp_timestamp.length() != 0) {
   temp_date = temp_timestamp.substring(0, 10);
   temp_time = temp_timestamp.substring(11, 16);
   echo(sensor + " = " + temp_time);
}
echo(sensor + " = " + temp);
setData("temp" + sensor, temp);
setData("temp_time" + sensor, temp_time);
temp_value = Float.parseFloat(temp); //decimaltal
min = getData("min" + sensor);
min_time = getData("min_time" + sensor);
max = getData("max" + sensor);
echo("min = " + min + ", max = " + max);
max_time = getData("max_time" + sensor);
minmax_date = getData("minmax_date" + sensor);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
Calendar cal = Calendar.getInstance();
date = sdf.format(cal.getTime());
if (min != null && min.length() != 0) {
   min_value = Float.parseFloat(min);
   max_value = Float.parseFloat(max);
   graf_offset = 59;
   pixel_per_grad = ((float)620 - 59) / 80;
   temp_graf_value = (float)409 - (temp_value * pixel_per_grad);
   temp_graf_value = Math.round(temp_graf_value);
   setData("temp_graf_value" + sensor, temp_graf_value);
   temp_graf_text_pos = temp_graf_value - 12;   
   setData("temp_graf_text_pos" + sensor, temp_graf_text_pos);
   graf_height_value = (float)409 - (-33 * pixel_per_grad) - temp_graf_value + 1;
   graf_height_value = Math.round(graf_height_value);
   setData("graf_height_value" + sensor, graf_height_value);
   max_graf_value = (((float)50 - max_value) * pixel_per_grad) + graf_offset;
   max_graf_value = Math.round(max_graf_value);
   max_graf_value =    max_graf_value - 19;
   setData("max_graf_value" + sensor, max_graf_value);
   max_graf_text_pos = max_graf_value - 17;   
   setData("max_graf_text_pos" + sensor, max_graf_text_pos);
   min_graf_value = (((float)50 - min_value) * pixel_per_grad) + graf_offset;
   min_graf_value = Math.round(min_graf_value);
   min_graf_value =    min_graf_value - 19;
   setData("min_graf_value" + sensor, min_graf_value);
   min_graf_text_pos = min_graf_value + 36;   
   setData("min_graf_text_pos" + sensor, min_graf_text_pos);
   if (temp_value < min_value) {
      echo("nytt värde - mintemp = " + temp_value);
      min = temp_value;
      min_time = temp_time;
      setData("min" + sensor, temp);
      setData("min_time" + sensor, temp_time);
   } else if (temp_value > max_value) {
             echo("nytt värde - maxtemp = " + temp_value);
             max = temp_value;
             max_time = temp_time;
             setData("max" + sensor, temp);
             setData("max_time" + sensor, temp_time);
          } else {
             hideOutput();
   }
   if (!date.equals(minmax_date)) {
      //echo(date + " - " + minmax_date);
      //sdf.format(cal.getTime())
	if (temp_time.equals("23:59")) {temp_time="00:00";}
	try{
        file = "temp_minmax" + "." + sensor + ".txt";
        FileWriter fw = new FileWriter(file, true);
        BufferedWriter out = new BufferedWriter(fw);
        out.write(minmax_date + "\t" + min + "\t" + min_time + "\t" + max + "\t" + max_time+ "\r\n");
        out.close();
        echo("write to file");
		setData("min" + sensor, temp);
        setData("min_time" + sensor, temp_time);
        setData("max" + sensor, temp);
        setData("max_time" + sensor, temp_time);
        setData("minmax_date" + sensor, date);
        echo(sensor + " min/max = " + temp + ", datum = " + date);
      } catch (Exception e) {
         echo("Error: " + e.getMessage());
      }
   }
} else { 
   setData("temp" + sensor, temp);
   setData("temp_time" + sensor, temp_time);
   setData("min" + sensor, temp);
   setData("min_time" + sensor, temp_time);
   setData("max" + sensor, temp);
   setData("max_time" + sensor, temp_time);
   setData("minmax_date" + sensor, date);
   setData("name" + sensor, name);
   echo(sensor + " min/max = " + temp + ", datum = " + date);
}
startTimer("minmax_101_temp", 60);
/Webserver/minmax101.html

Code: Select all

<!DOCTYPE html>
<html>
<body>
<img style="position:absolute;top:5px;left:5px;z-index:10" src="/nexahome/termometer 7.png">
<IMG STYLE="position:absolute;TOP:#DATA#temp_graf_value101#px;LEFT:84px;WIDTH:17px;HEIGHT:#DATA#graf_height_value101#px;z-index:1" SRC="/nexahome/röd.png">
<IMG STYLE="position:absolute;TOP:#DATA#max_graf_value101#px;LEFT:83px;z-index:11" SRC="/nexahome/max(6).png">
<IMG STYLE="position:absolute;TOP:#DATA#min_graf_value101#px;LEFT:83px;z-index:11" SRC="/nexahome/min(6).png">

<div style="position: absolute; top: 16px; left: 55px;z-index:11">
#DATA#name101#
</div>

<div style="position: absolute; top: #DATA#max_graf_text_pos101#px; left: 120px;z-index:11">
#DATA#max101# ºC
</div>

<div style="position: absolute; top: #DATA#temp_graf_text_pos101#px; left: 120px;z-index:11">
#DATA#temp101# ºC
</div>

<div style="position: absolute; top: #DATA#min_graf_text_pos101#px; left: 120px;z-index:11">
#DATA#min101# ºC
</div>

<div style="position: absolute; top: 700px; left: 25px">
max
</div>

<div style="position: absolute; top: 700px; left: 65px">
#DATA#max101# ºC (#DATA#max_time101#)
</div>

<div style="position: absolute; top: 720px; left: 65px">
#DATA#temp101# ºC (#DATA#temp_time101#)
</div>

<div style="position: absolute; top: 740px; left: 25px">
min
</div>

<div style="position: absolute; top: 740px; left: 65px">
#DATA#min101# ºC (#DATA#min_time101#)
</div>

</body>
</html>
temp_minmax.101.txt

Code: Select all

2015-01-06	-8.3	02:41	0.5	21:11
2015-01-07	-0.4	20:18	0.4	09:29
2015-01-08	0.1	00:00	4.1	15:41
2015-01-09	-2.6	23:24	2.2	00:00
http://192.168.1.10:80/nexahome?mypage=minmax101
/Webserver/termometer 7.png
/Webserver/röd.png
/Webserver/max(6).png
/Webserver/min(6).png
Attachments
http://192.168.1.10:80/nexahome?mypage=minmax101
http://192.168.1.10:80/nexahome?mypage=minmax101
mypage.PNG (28.55 KiB) Viewed 14805 times
Pee
Posts: 47
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Pee »

Orjan,
Det där ser snyggt ut. Vill du lägga upp bildfilerna?
(Länken går nog till ditt LAN)

/Pee
Leffe
Posts: 96
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Leffe »

Riktigt snyggt jobb!
Skulle man kunna få bilderna ? riktigt snyggt :D :D
orjan
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by orjan »

Leffe wrote:Riktigt snyggt jobb!
Skulle man kunna få bilderna ? riktigt snyggt :D :D
Har lagt till en zippfil pga att man endast kan ha tre filer per inlägg.
Attachments
Termometer.7z
(29.75 KiB) Downloaded 306 times
Leffe
Posts: 96
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Leffe »

Tackar ! :D :D :D :D :D
orjan
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by orjan »

Jag håller nu på att göra ett visarinstrument med hjälp av javascript på en websida.
Attachments
instrument_visare.PNG
instrument_visare.PNG (7.3 KiB) Viewed 14589 times
orjan
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by orjan »

Visarinstrument...
visare.png
visare.png (30.72 KiB) Viewed 14522 times

Code: Select all

<canvas id="myCanvas" width="300" height="300" style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
    var x = canvas.width / 2;
    var y = canvas.height / 2;
    var radius = 120;
	grafMinAngle = 1.06;
	grafMaxAngle = 1.94;
	grafMinGrader = 180 + 10;
	grafMaxGrader = 360 - 10;

   grafMinTemp = -20;
   grafMaxTemp = 20;
	sensorName 				= "Ute";	//"#DATA#name101#";
	minTemp 				= -3.1;		//#DATA#min101#;
	minTempTime				= "12:23";	//"#DATA#min_time101#";
	currentTemp 			= -1.9;		//#DATA#temp101#;
	maxTemp 				= 2.1;		//"#DATA#max101#";
	maxTempTime 			= "12:32";	//"#DATA#max_time101#";
	
	range = grafMaxTemp - grafMinTemp;
	anglePerEnhet = (grafMaxAngle - grafMinAngle) /(grafMaxTemp-grafMinTemp);
	gradPerEnhet = (grafMaxGrader - grafMinGrader) /(grafMaxTemp-grafMinTemp);
	zeroGrader = grafMinGrader + ((0 - grafMinTemp) * gradPerEnhet);
	minTempGrader = grafMinGrader + ((minTemp - grafMinTemp) * gradPerEnhet)
	currentTempGrader = grafMinGrader + ((currentTemp - grafMinTemp) * gradPerEnhet)
	maxTempGrader = grafMinGrader + ((maxTemp - grafMinTemp) * gradPerEnhet)
	
	//ska röd yta ritas?
	if (grafMaxTemp > 0) { 
	if (grafMinTemp < 0) {
			startAngle = (grafMinGrader + (0 - grafMinTemp) * gradPerEnhet) * Math.PI / 180;
		} else {
			startAngle = grafMinGrader * Math.PI / 180;
		} 
		endAngle = grafMaxGrader * Math.PI / 180;
		var counterClockwise = false;
		context.beginPath();
		context.arc(x, y, radius - 1, startAngle, endAngle, counterClockwise);
		context.lineWidth = 7;
		context.strokeStyle = 'red';
		context.stroke();
	}
	
	//ska blå yta ritas?
	if (grafMinTemp < 0) {
		startAngle = grafMinGrader * Math.PI / 180;
		if (grafMaxTemp > 0) {
			endAngle = (grafMinGrader + (0 - grafMinTemp) * gradPerEnhet) * Math.PI / 180;
		} else {
			endAngle = grafMaxGrader * Math.PI / 180;
		} 
		counterClockwise = false;
		context.beginPath();
		context.arc(x, y, radius - 1, startAngle, endAngle, counterClockwise);
		context.lineWidth = 7;
		context.strokeStyle = 'blue';
		context.stroke();
	}
	
// gradering 0.5
x_center = x;
y_center = y;
context.strokeStyle = 'black';
for (var i = grafMinGrader + 180; i <= grafMaxGrader + 180; i = i + gradPerEnhet*0.5) {
    radianer = 	i * Math.PI/180;
	x_cb1 = x_center - ((radius - 1) * Math.cos(radianer));
	y_cb1 = y_center - ((radius - 1) * Math.sin(radianer));
	x_cb2 = x_center - ((radius + 0) * Math.cos(radianer));
	y_cb2 = y_center - ((radius + 0) * Math.sin(radianer));
	if (i < zeroGrader + 180) {
		context.strokeStyle = 'white';
	} else { 
		context.strokeStyle = 'black';
	}
	context.beginPath();
    context.moveTo(x_cb1, y_cb1);
    context.lineTo(x_cb2, y_cb2);
    context.lineWidth = 1;
	context.lineCap = 'round';
    context.stroke();
}
	
// gradering 1	
for (var i = grafMinGrader + 180; i <= grafMaxGrader + 180; i = i + gradPerEnhet*1) {
    radianer = 	i * Math.PI/180;
	x_cb1 = x_center - ((radius - 6) * Math.cos(radianer));
	y_cb1 = y_center - ((radius - 6) * Math.sin(radianer));
	x_cb2 = x_center - ((radius + 5) * Math.cos(radianer));
	y_cb2 = y_center - ((radius + 5) * Math.sin(radianer));
	context.beginPath();
    context.moveTo(x_cb1, y_cb1);
    context.lineTo(x_cb2, y_cb2);
    context.lineWidth = 1;
	context.lineCap = 'round';
    context.stroke();
}

// gradering 5
for (var i = grafMinGrader + 180; i <= grafMaxGrader + 180; i = i + gradPerEnhet*5) {
    radianer = 	i * Math.PI/180;
	x_cb1 = x_center - ((radius - 6) * Math.cos(radianer));
	y_cb1 = y_center - ((radius - 6) * Math.sin(radianer));
	x_cb2 = x_center - ((radius + 10) * Math.cos(radianer));
	y_cb2 = y_center - ((radius + 10) * Math.sin(radianer));
	context.beginPath();
    context.moveTo(x_cb1, y_cb1);
    context.lineTo(x_cb2, y_cb2);
    context.lineWidth = 2;
	context.lineCap = 'round';
    context.stroke();
}

// gradering 10
	text = grafMinTemp;
for (var i = grafMinGrader + 180; i <= grafMaxGrader + 180; i = i + gradPerEnhet*10) {
    radianer = 	i * Math.PI/180;
	x_cb1 = x_center - ((radius - 6) * Math.cos(radianer));
	y_cb1 = y_center - ((radius - 6) * Math.sin(radianer));
	x_cb2 = x_center - ((radius + 15) * Math.cos(radianer));
	y_cb2 = y_center - ((radius + 15) * Math.sin(radianer));
	context.beginPath();
    context.moveTo(x_cb1, y_cb1);
    context.lineTo(x_cb2, y_cb2);
    context.lineWidth = 2;
	context.lineCap = 'round';
    context.stroke();
	
	textPosX = x_cb2 + 0;
	textPosY = y_cb2 + -4;
	context.font = 'bold 13pt Calibri';
	context.textAlign = 'center';
	context.fillStyle = 'black';
	context.fillText(text, textPosX, textPosY);
	text = text + 10;
}

	//minTemp visare
	if (minTempGrader >= grafMinGrader && minTempGrader <= grafMaxGrader){
		radianer = 	(minTempGrader + 180) * Math.PI/180;
		x_cb1 = x_center - ((radius - 40) * Math.cos(radianer));
		y_cb1 = y_center - ((radius - 40) * Math.sin(radianer));
		x_cb2 = x_center - ((radius - 9) * Math.cos(radianer));
		y_cb2 = y_center - ((radius - 9) * Math.sin(radianer));
		context.beginPath();
		context.moveTo(x_cb1, y_cb1);
		context.lineTo(x_cb2, y_cb2);
		context.lineWidth = 3;
		context.strokeStyle = 'blue';
		context.lineCap = 'round';
		context.shadowColor = '#999';
		context.shadowBlur = 10;
		context.shadowOffsetX = 5;
		context.shadowOffsetY = 5;
		context.stroke();
		
		if ((minTemp - grafMinTemp) / range <= 0.5) { 
			xMod = -1;
			yMod = 9;
		} else {
			xMod = -4;
			yMod = -9;
		}
		context.shadowColor = '#999';
		context.shadowBlur = 0;
		context.shadowOffsetX = 0;
		context.shadowOffsetY = 0;
		context.font = 'normal 10pt Calibri';
		context.textAlign = 'right';
		context.fillStyle = 'blue';
		context.fillText("(" + minTempTime + ")", x_cb1 + xMod, y_cb1 + yMod);
	}
	
	//max visare
	if (maxTempGrader >= grafMinGrader && maxTempGrader <= grafMaxGrader){
		radianer = 	(maxTempGrader + 180) * Math.PI/180;
		x_cb1 = x_center - ((radius - 40) * Math.cos(radianer));
		y_cb1 = y_center - ((radius - 40) * Math.sin(radianer));
		x_cb2 = x_center - ((radius - 9) * Math.cos(radianer));
		y_cb2 = y_center - ((radius - 9) * Math.sin(radianer));
		context.beginPath();
		context.moveTo(x_cb1, y_cb1);
		context.lineTo(x_cb2, y_cb2);
		context.lineWidth = 3;
		context.strokeStyle = 'red';
		context.lineCap = 'round';
		context.shadowColor = '#999';
		context.shadowBlur = 10;
		context.shadowOffsetX = 5;
		context.shadowOffsetY = 5;
		context.stroke();	

		if ((maxTemp - grafMinTemp) / range > 0.5) {
			xMod = -1;
			yMod = 10;
		} else {
			xMod = -4;
			yMod = -10;
		}
		context.shadowColor = '#999';
		context.shadowBlur = 0;
		context.shadowOffsetX = 0;
		context.shadowOffsetY = 0;		
		context.font = 'normal 10pt Calibri';
		context.textAlign = 'left';
		//context.textBaseline = 'center';
		context.fillStyle = 'red';
		context.fillText("(" + maxTempTime + ")", x_cb1 + xMod, y_cb1 + yMod);
	}
	
	//currentTemp visare
	if (currentTempGrader >= grafMinGrader && currentTempGrader <= grafMaxGrader){
		radianer = 	(currentTempGrader + 180) * Math.PI/180;
		start = 9;
		len = 67;
		end = start + len;
		x_cb2 = x_center - ((radius - start) * Math.cos(radianer));
		y_cb2 = y_center - ((radius - start) * Math.sin(radianer));
		x_cb1 = x_center - ((radius - end) * Math.cos(radianer));
		y_cb1 = y_center - ((radius - end) * Math.sin(radianer));
		context.beginPath();
		context.moveTo(x_cb1, y_cb1);
		context.lineTo(x_cb2, y_cb2);
		context.lineWidth = 3;
		context.strokeStyle = 'black';
		context.lineCap = 'round';
		context.shadowColor = '#999';
		context.shadowBlur = 10;
		context.shadowOffsetX = 5;
		context.shadowOffsetY = 5;
		context.stroke();	
	}

	//minTemp "punkt"
	if (minTempGrader >= grafMinGrader && minTempGrader <= grafMaxGrader){
		radianer = 	(minTempGrader + 180) * Math.PI/180;
		start = 24;
		len = 1;
		end = start - len;
		x_cb2 = x_center - ((radius - start) * Math.cos(radianer));
		y_cb2 = y_center - ((radius - start) * Math.sin(radianer));
		x_cb1 = x_center - ((radius - end) * Math.cos(radianer));
		y_cb1 = y_center - ((radius - end) * Math.sin(radianer));
		context.beginPath();
		context.moveTo(x_cb1, y_cb1);
		context.lineTo(x_cb2, y_cb2);
		context.lineWidth = 8;
		context.strokeStyle = 'blue';
		context.lineCap = 'round';
		context.stroke();
	}

	//maxTemp "punkt"
	if (maxTempGrader >= grafMinGrader && maxTempGrader <= grafMaxGrader){
		radianer = 	(maxTempGrader + 180) * Math.PI/180;
		start = 15;
		len = 1;
		end = start - len;
		x_cb2 = x_center - ((radius - start) * Math.cos(radianer));
		y_cb2 = y_center - ((radius - start) * Math.sin(radianer));
		x_cb1 = x_center - ((radius - end) * Math.cos(radianer));
		y_cb1 = y_center - ((radius - end) * Math.sin(radianer));
		context.beginPath();
		context.moveTo(x_cb1, y_cb1);
		context.lineTo(x_cb2, y_cb2);
		context.lineWidth = 8;
		context.strokeStyle = 'red';
		context.lineCap = 'round';
		context.stroke();	
	}
	
	//minTemp
	context.font = 'normal 13pt Calibri';
	context.textAlign = 'left';
	context.fillStyle = 'blue';
	DEGREE  = "\u00B0" + "C";
	context.shadowColor = '#999';
	context.shadowBlur = 0;
	context.shadowOffsetX = 0;
	context.shadowOffsetY = 0;
    context.fillText(minTemp + DEGREE, x - radius - 12, y - 5);
	
	//currentTemp
	context.beginPath();
    context.arc(150, 150, 38, 0, Math.PI, true);
    context.closePath();
	context.lineWidth = 2;
	if (currentTemp < 0) {
		context.shadowColor = '#999';
		context.shadowBlur = 10;
		context.shadowOffsetX = 5;
		context.shadowOffsetY = 5;
		
		context.fillStyle = 'lightskyblue';
		context.fill();
		context.strokeStyle = 'blue';
		context.stroke();
	} else {
		context.shadowColor = '#999';
		context.shadowBlur = 10;
		context.shadowOffsetX = 5;
		context.shadowOffsetY = 5;
		context.fillStyle = '#FFAD99';
		context.fill();
		context.strokeStyle = 'red';
		context.stroke();
	}
	context.shadowColor = '#999';
	context.shadowBlur = 0;
	context.shadowOffsetX = 0;
	context.shadowOffsetY = 0;
	context.font = 'normal 15pt Calibri';
	context.textAlign = 'center';
	context.fillStyle = 'black';
	DEGREE  = "\u00B0" + "C";
    context.fillText(currentTemp + DEGREE, x, y - 5);

	//maxTemp
	context.font = 'normal 13pt Calibri';
	context.textAlign = 'right';
	//context.textBaseline = 'left';
	context.fillStyle = 'red';
	DEGREE  = "\u00B0" + "C";
    context.fillText(maxTemp + DEGREE, x + radius + 12, y - 5);
	
	//sensorName
	context.beginPath();
	context.rect(x - radius - 14, y, (radius + 14) * 2, 22);
	context.shadowColor = '#999';
	context.shadowBlur = 10;
	context.shadowOffsetX = 5;
	context.shadowOffsetY = 5;
	context.fillStyle = 'lightgray';
	context.fill();
	context.lineWidth = 2;
	context.strokeStyle = 'black';
	context.stroke();
	context.font = 'normal 14pt Calibri';
	context.textAlign = 'center';
	context.shadowColor = '#999';
	context.shadowBlur = 0;
	context.shadowOffsetX = 0;
	context.shadowOffsetY = 0;
	context.fillStyle = 'black';
	DEGREE  = "\u00B0" + "C";
    context.fillText(sensorName, x, y + 18);
</script>
</body>
</html>  
Leffe
Posts: 96
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Leffe »

Orjan

Jag får ingen datafil bara en fil som heter "minmax112temp.bsh.dump" och som ser mycket konstig ut!
(Min utegivare har ID 112)
Vad är det jag missar?

´skulle vara väldigt tacksam för all hjälp :? :?
hekj
Posts: 992
Joined: Fri Mar 17, 2023 9:45 am
Location: Stockholm
Contact:

Re: minmax sensorvärde per dygn

Post by hekj »

Leffe wrote:Jag får ingen datafil bara en fil som heter "minmax112temp.bsh.dump" och som ser mycket konstig ut!
(Min utegivare har ID 112)
Vad är det jag missar?
Eventuellt krävs det att man kör NexaHome v3.9.8, ladda ner den och testa om bsh filen fungerar bättre.
Leffe
Posts: 96
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Leffe »

hekj wrote:
Leffe wrote:Jag får ingen datafil bara en fil som heter "minmax112temp.bsh.dump" och som ser mycket konstig ut!
(Min utegivare har ID 112)
Vad är det jag missar?
Eventuellt krävs det att man kör NexaHome v3.9.8, ladda ner den och testa om bsh filen fungerar bättre.

Jag testade detta men ingen skillnad, "dump fil" fortfarande.

här är några rader med felmeddelanden , kan någon tyda detta



2015-01-21 13:49:58 The script threw an exception (minmax112temp.bsh): Sourced file: minmax112temp.bsh : Method Invocation dataTable_.put : at Line: 683 : in file: inline evaluation of: ``import java.text.SimpleDateFormat; char[] CA_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde . . . '' : dataTable_ .put ( key , value )

Called from method: setData : at Line: 15 : in file: minmax112temp.bsh : setData ( "temp" + sensor , temp )
Target exception: java.lang.NullPointerException

2015-01-21 13:50:41 Script executed (start.bsh), result: [[timer, save_temp:300], [timer, save_fukt:300], [timer, test_ping:120], [timer, check_temp:60], [timer, weather_hourly:30], [timer, minmax112temp:70]]
2015-01-21 13:50:48 Script executed (test_ping.bsh), result: [[exec, c:/nexahome/test_ping.bat], [timer, test_ping:120]]
2015-01-21 13:50:48 Exec (test_ping.bat)
2015-01-21 13:50:48 Script executed (check_temp.bsh), result: [[echo, 21.3], [echo, 13:50], [timer, check_temp:60]]
2015-01-21 13:50:52 Script executed (test_ping.bat.output.bsh), result: [[echo, TV is OFF], [device, TV, Off]]
2015-01-21 13:50:52 :OFF 1(2): Turning off dummy device: 13 TV - ok
2015-01-21 13:50:52 :OFF 2(2): Turning off dummy device: 13 TV - ok
2015-01-21 13:51:41 Script executed (check_temp.bsh), result: [[echo, 21.3], [echo, 13:51], [timer, check_temp:60]]
2015-01-21 13:51:49 Script executed (check_temp.bsh), result: [[echo, 21.3], [echo, 13:51], [timer, check_temp:60]]
2015-01-21 13:51:51 The script threw an exception (minmax112temp.bsh): Sourced file: minmax112temp.bsh : Method Invocation dataTable_.put : at Line: 687 : in file: inline evaluation of: ``import java.text.SimpleDateFormat; char[] CA_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde . . . '' : dataTable_ .put ( key , value )

Called from method: setData : at Line: 15 : in file: minmax112temp.bsh : setData ( "temp" + sensor , temp )
Target exception: java.lang.NullPointerException

2015-01-21 13:52:41 Script executed (test_ping.bsh), result: [[exec, c:/nexahome/test_ping.bat], [timer, test_ping:120]]
2015-01-21 13:52:41 Exec (test_ping.bat)
2015-01-21 13:52:41 Script executed (check_temp.bsh), result: [[echo, 21.3], [echo, 13:52], [timer, check_temp:60]]
2015-01-21 13:52:45 Script executed (test_ping.bat.output.bsh), result: [[echo, TV is OFF], [device, TV, Off]]
2015-01-21 13:52:45 :OFF 1(2): Turning off dummy device: 13 TV - ok
2015-01-21 13:52:46 :OFF 2(2): Turning off dummy device: 13 TV - ok
2015-01-21 13:52:48 Script executed (test_ping.bsh), result: [[exec, c:/nexahome/test_ping.bat], [timer, test_ping:120]]
hekj
Posts: 992
Joined: Fri Mar 17, 2023 9:45 am
Location: Stockholm
Contact:

Re: minmax sensorvärde per dygn

Post by hekj »

Leffe wrote:2015-01-21 13:51:51 The script threw an exception (minmax112temp.bsh): Sourced file: minmax112temp.bsh : Method Invocation dataTable_.put : at Line: 687 : in file: inline evaluation of: ``import java.text.SimpleDateFormat; char[] CA_ = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcde . . . '' : dataTable_ .put ( key , value )

Called from method: setData : at Line: 15 : in file: minmax112temp.bsh : setData ( "temp" + sensor , temp )
Target exception: java.lang.NullPointerException
Jag modifierade bsh filen lite grann men dom som använder denna måste själv ändra nedanstående rader samt döpa om filen så att den har rätt sensor i filnamnet.
sensor = "101";
name = "Ute";

minmax_101_temp.bsh

Code: Select all

//logga min samt max per dygn till fil
//spara värden för att presentera termometer (.png)
import java.text.SimpleDateFormat;
sensor = "101";
name = "Ute";
setData("name" + sensor, name);
temp = getSensorValue(sensor); //sträng
temp_timestamp = getSensorTimestamp(sensor, true);
echo(sensor + " = " + temp);
if (temp != null && temp_timestamp != null && temp_timestamp.length() != 0) {
   temp_date = temp_timestamp.substring(0, 10);
   temp_time = temp_timestamp.substring(11, 16);
   echo(sensor + " = " + temp_time);
   setData("temp" + sensor, temp);
   setData("temp_time" + sensor, temp_time);
   temp_value = Float.parseFloat(temp); //decimaltal
   min = getData("min" + sensor);
   min_time = getData("min_time" + sensor);
   max = getData("max" + sensor);
   echo("min = " + min + ", max = " + max);
   max_time = getData("max_time" + sensor);
   minmax_date = getData("minmax_date" + sensor);
   SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
   Calendar cal = Calendar.getInstance();
   date = sdf.format(cal.getTime());
   if (min != null && min.length() != 0) {
      min_value = Float.parseFloat(min);
      max_value = Float.parseFloat(max);
      graf_offset = 59;
      pixel_per_grad = ((float)620 - 59) / 80;
      temp_graf_value = (float)409 - (temp_value * pixel_per_grad);
      temp_graf_value = Math.round(temp_graf_value);
      setData("temp_graf_value" + sensor, temp_graf_value);
      temp_graf_text_pos = temp_graf_value - 12;   
      setData("temp_graf_text_pos" + sensor, temp_graf_text_pos);
      graf_height_value = (float)409 - (-33 * pixel_per_grad) - temp_graf_value + 1;
      graf_height_value = Math.round(graf_height_value);
      setData("graf_height_value" + sensor, graf_height_value);
      max_graf_value = (((float)50 - max_value) * pixel_per_grad) + graf_offset;
      max_graf_value = Math.round(max_graf_value);
      max_graf_value =    max_graf_value - 19;
      setData("max_graf_value" + sensor, max_graf_value);
      max_graf_text_pos = max_graf_value - 17;   
      setData("max_graf_text_pos" + sensor, max_graf_text_pos);
      min_graf_value = (((float)50 - min_value) * pixel_per_grad) + graf_offset;
      min_graf_value = Math.round(min_graf_value);
      min_graf_value =    min_graf_value - 19;
      setData("min_graf_value" + sensor, min_graf_value);
      min_graf_text_pos = min_graf_value + 36;   
      setData("min_graf_text_pos" + sensor, min_graf_text_pos);
      if (temp_value < min_value) {
        echo("nytt värde - mintemp = " + temp_value);
        min = temp_value;
        min_time = temp_time;
        setData("min" + sensor, temp);
        setData("min_time" + sensor, temp_time);
      } else if (temp_value > max_value) {
             echo("nytt värde - maxtemp = " + temp_value);
             max = temp_value;
             max_time = temp_time;
             setData("max" + sensor, temp);
             setData("max_time" + sensor, temp_time);
           } else {
             hideOutput();
      }
      if (!date.equals(minmax_date)) {
        //echo(date + " - " + minmax_date);
        //sdf.format(cal.getTime())
      if (temp_time.equals("23:59")) {temp_time="00:00";}
      try{
         file = "temp_minmax" + "." + sensor + ".txt";
         FileWriter fw = new FileWriter(file, true);
         BufferedWriter out = new BufferedWriter(fw);
         out.write(minmax_date + "\t" + min + "\t" + min_time + "\t" + max + "\t" + max_time+ "\r\n");
         out.close();
         echo("write to file");
        setData("min" + sensor, temp);
         setData("min_time" + sensor, temp_time);
         setData("max" + sensor, temp);
         setData("max_time" + sensor, temp_time);
         setData("minmax_date" + sensor, date);
         echo(sensor + " min/max = " + temp + ", datum = " + date);
        } catch (Exception e) {
          echo("Error: " + e.getMessage());
        }
      }
   } else {
      setData("temp" + sensor, temp);
      setData("temp_time" + sensor, temp_time);
      setData("min" + sensor, temp);
      setData("min_time" + sensor, temp_time);
      setData("max" + sensor, temp);
      setData("max_time" + sensor, temp_time);
      setData("minmax_date" + sensor, date);
      setData("name" + sensor, name);
      echo(sensor + " min/max = " + temp + ", datum = " + date);
   }
}
startTimer("minmax_" + sensor + "_temp", 60);
Har inte provkört koden men den borde iaf inte kasta NullPointerException.

Edit: 20150122
Leffe
Posts: 96
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Leffe »

tack för hjälpen , nu blev det bättre men jag får ingen fil till html sidan

2015-01-21 20:39:54 Script executed (minmax_112_temp.bsh), result: [[echo, 55 = 23.0], [echo, 55 = 20:39], [echo, min = 0.3, max = 22.9], [echo, nytt värde - maxtemp = 23.0], [timer, minmax_112_temp:60]]

vofför e de så här ? :cry:
Jocke_E
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by Jocke_E »

Jag får endast en fil som är daterad vid midnatt. Däremot får jag korrekta värden för min/max som uppdateras löpande. Det enda "problemet" är när jag startar om NexaHome så nollställs värdena.


//Jocke
hekj
Posts: 992
Joined: Fri Mar 17, 2023 9:45 am
Location: Stockholm
Contact:

Re: minmax sensorvärde per dygn

Post by hekj »

Leffe wrote:tack för hjälpen , nu blev det bättre men jag får ingen fil till html sidan

2015-01-21 20:39:54 Script executed (minmax_112_temp.bsh), result: [[echo, 55 = 23.0], [echo, 55 = 20:39], [echo, min = 0.3, max = 22.9], [echo, nytt värde - maxtemp = 23.0], [timer, minmax_112_temp:60]]
Hämta bsh filen på nytt, jag har fixat en bug i den.

Ersätt motsvarande rader i html filen med följande samt se till att sensornumret är ditt eget.

Code: Select all

    sensorName          = "#DATA#name101#";
    minTemp             = #DATA#min101#;
    minTempTime         = "#DATA#min_time101#";
    currentTemp         = #DATA#temp101#;
    maxTemp             = #DATA#max101#;
    maxTempTime         = "#DATA#max_time101#";
Har du lagt in följande rad (med din egen sensors nummer) i start.bsh ?

Code: Select all

startTimer("minmax_101_temp", 70);
orjan
Posts: 7
Joined: Fri Mar 17, 2023 9:45 am

Re: minmax sensorvärde per dygn

Post by orjan »

Jocke_E wrote:Jag får endast en fil som är daterad vid midnatt. Däremot får jag korrekta värden för min/max som uppdateras löpande. Det enda "problemet" är när jag startar om NexaHome så nollställs värdena.


//Jocke
Med min bsh fil så sparas minmax endast en gång per dygn. Vem blir först att lägga ut en egen lösning på detta?
Post Reply