Hello everyone! I’m really excited to share my journey with setting up a dynamic timer for my heating system. This project has been a bit of a challenge, but it’s also been a lot of fun. Let me walk you through what I’ve done and how I overcame some of the hurdles along the way.
So, the goal here was to create a heating system that starts at a specific time before I want it to reach a certain temperature. For example, if I want my bathroom to be warm by 7:40 AM, I want the heater to start earlier, depending on the current temperature. If it’s colder, it starts sooner and runs longer; if it’s warmer, it starts later and runs for a shorter time. This way, I ensure that the temperature is just right when I need it.
I found a script on the forum that was a great starting point. It used some Java functions to create timers with arguments, which was exactly what I needed. However, I ran into a bit of a snag when trying to pass arguments to the function. I kept getting an error that the ‘command’ was null, which was pretty frustrating. After some research and trial and error, I realized that I needed to make sure the arguments were properly formatted and that the function was correctly handling them.
Here’s a snippet of the code I ended up using. It calculates the time needed based on the temperature difference and sets the timer accordingly:
java
var ScriptExecution = Java.type(“org.openhab.core.model.script.actions.ScriptExecution”);
var ZonedDateTime = Java.type(“java.time.ZonedDateTime”);
var TimerMinutes = items[“BadkamerVerwarmingTimer”];
var SetpointTemp = items[“BadkamerTemperatuur”];
var currentTemp = items[“CurrentTemperature”];
function adjustHeating() {
var tempDiff = SetpointTemp - currentTemp;
var x = (tempDiff - 3) * 60 + 20;
if (x > 140) {
x = 140;
}
var y = 150 - x;
var startTime = ZonedDateTime.now().plusMinutes(y);
ScriptExecution.createTimerWithArgument(startTime, x, startHeating);
}
function startHeating() {
events.sendCommand(“BadkamerVerwarmingTimer”, x);
events.sendCommand(“HeaterSwitch”, “ON”);
}
This script calculates how long the heater needs to run based on the temperature difference and sets a timer to start it at the right time. It’s been working perfectly for me, and I couldn’t be happier with the result!
I’d love to hear if anyone else has tackled a similar project or has any tips for optimizing this further. Let’s keep the ideas flowing and help each other create smarter homes!
Cheers,
Peter