So I‘m currently working on a program to turn on or off my Philips Hue lights when I enter my room. The detection if somebody is coming or which direction he is going is provided by one HCSr505 and two HCSr04 sensors. The program is a java program with the official Hue API. So now my problem is that the Raspberry Pi 3, which the whole system is running on, is getting quite hot (around 60 °C) over time( the system is running 24/7, but the loops to detect the distance from the HCSr04 is only running when the HCSr505 is detecting any movement, at certain day times all loops are paused, because I don’t need to turn on light when the sun is shining). I know that 60° is okay for the raspberry pi but nevertheless I’m a little bit worried because the system is placed in a wardrobe where there’s no way the hot air can escape. I‘ve also mounted heatsinks onto the pi. Is there any way I can decrease the temperature while running my java Programm?
Here's the cpu usage while running the program:

And here's cpu usage I got from the iostat command:

And here is the code: (second class only contains the Hue API and bridge connection)
import java.time.LocalDateTime;
import java.time.ZoneId;
import com.philips.lighting.hue.sdk.PHHueSDK;
import com.pi4j.io.gpio.GpioController;
import com.pi4j.io.gpio.GpioFactory;
import com.pi4j.io.gpio.GpioPinDigitalInput;
import com.pi4j.io.gpio.GpioPinDigitalOutput;
import com.pi4j.io.gpio.PinPullResistance;
import com.pi4j.io.gpio.RaspiPin;
public class Distance {
//GPIO Pins
private static GpioPinDigitalOutput sensorTriggerPin ;
private static GpioPinDigitalInput sensorEchoPin ;
private static GpioPinDigitalOutput sensorTriggerPin1;
private static GpioPinDigitalInput sensorEchoPin1 ;
private static GpioPinDigitalInput pir;
int f=0;
ZoneId id;
public static double distance2;
public static double distanceold;
public static double distanceold1;
public static double distance3;
public static boolean left=false;
public static boolean right=false;
public static long timeleft;
public static long timeright;
public int counter;
final static GpioController gpio = GpioFactory.getInstance();
public static void main(String [] args) throws InterruptedException{
System.out.println("Starting...");
//ZoneId id=ZoneId.of("Europe/Berlin");
int hour = LocalDateTime.now().getHour();
if( hour>17 || hour<7) {
}else {
System.out.println("Hour not in estimated working time");
System.out.println("Hour:"+ hour);
}
pir = gpio.provisionDigitalInputPin(RaspiPin.GPIO_07, PinPullResistance.PULL_DOWN);
sensorTriggerPin = gpio.provisionDigitalOutputPin(RaspiPin.GPIO_00); // Trigger pin as OUTPUT // rechts von Schrank aus
sensorEchoPin = gpio.provisionDigitalInputPin(RaspiPin.GPIO_02,PinPullResistance.PULL_DOWN); // Echo pin as INPUT
sensorTriggerPin1= gpio.provisionDigitalOutputPin(RaspiPin.GPIO_27); // links von Schrank aus
sensorEchoPin1= gpio.provisionDigitalInputPin(RaspiPin.GPIO_25,PinPullResistance.PULL_DOWN);
new UltraHue();
UltraHue.hue();
}
private int hour;
public void run() throws InterruptedException {
do{
hour = LocalDateTime.now().getHour();
while( hour>17 || hour<7 ){
if(pir.isHigh()){ // waiting for my HCsr505 to
//detect any movement
if (getdistance(sensorEchoPin, sensorTriggerPin) < 70 && distanceold<70 ) { //rechts vom Schrank
right = true;
if (left) {
UltraHue.lightson(PHHueSDK.getInstance().getSelectedBridge());
reset();
}
}
distanceold=getdistance(sensorEchoPin, sensorTriggerPin);
Thread.sleep(20);
if (getdistance(sensorEchoPin1, sensorTriggerPin1) < 70 && distanceold1<70) { //links vom Schrank
left = true;
if (right) {
UltraHue.lightsoff(PHHueSDK.getInstance().getSelectedBridge());
reset();
}
}
distanceold1 = getdistance(sensorEchoPin1, sensorTriggerPin1);
if (left || right) {
if (counter++ >= 70) {
reset();
}
}
Thread.sleep(20);
}
}
Thread.sleep(600000);
}while(true);
}
private void reset(){
counter = 0;
left = false;
right = false;
}
private static long endTime;
private static long startTime;
private static long timedout;
public static double getdistance(GpioPinDigitalInput sensorEchoPin3, GpioPinDigitalOutput sensorTriggerPin3) throws InterruptedException{
sensorTriggerPin3.high(); // Make trigger pin HIGH
Thread.sleep((long) 0.01);// Delay for 10 microseconds
sensorTriggerPin3.low(); //Make trigger pin LOW
timedout= System.nanoTime();
while(sensorEchoPin3.isLow()){ //Wait until the ECHO pin gets HIGH
if((System.nanoTime()-timedout)>600000){
break;
}
}
startTime= System.nanoTime(); // Store the current time to calculate ECHO pin HIGH time.
while(sensorEchoPin3.isHigh()){ //Wait until the ECHO pin gets LOW
}
endTime= System.nanoTime(); // Store the echo pin HIGH end time to calculate ECHO pin HIGH time.
return(((endTime-startTime)/1e3)/2) / 29.1;
}
}
//}