Tutorial for heating, generic rule

Hi everyone,
I believe everyone that has OH also have some kind of heating(unless u live in hawaii or some other exotic place) and hence I will like to discuss a tutorial I trying to put together.

So question number 1:
What is recomennded room temperatures?
I assume this is dependent of age(old/infant??)
What kind of activity(sleeping,working,relaxing)

So if we somehow can answer question 1 we can move on to number two
The rooms will have different modes(away, sleeping etc…) so we need to figure out how long it takes to change from one mode to another mode. This can be found by using thermodynamics: Q=k*deltaT-Heatsource

So lets say we are at work and know that we will be home 4, so question is when do we start heating? This is a bit tricky, but in most practical cases we can do experiments and achieve more than good enough results.
We could make a lambda function which takes in outside temperature,inside temperature,wind speed,power consumption,desired temperature and returns a time, but I would assume that inside temperature and desired temperature would be enough or?

So there are several types of heating but in general a simple On/off regulator is enough for most heating and my lambda fuction for this is given below:

val Functions.Function3 heatings = [ GenericItem setPoint,GenericItem temperature,GenericItem relay |
// Turn on the heater if the temp gets more than 2 degrees below the Heating_LivingRoom_Setpoint to prevent rapid cycling
     if((temperature.state as DecimalType)-1.0< (setPoint.state as DecimalType)) {
//Items connected to NC, i.e sendcommand off is ON!!
if(relay.state != OFF) relay.sendCommand(OFF)
}
else {
//Items connected to NC, i.e sendcommand off is ON!!
if(relay.state != ON) relay.sendCommand(ON)
}
 ]

So this basic lambda function takes 3 arguments which then user need to specify:

  1. The set point, the temperature that the user feels comfortable with(See Q1),
  2. The measured temperature, if you have a large room you could take the average or similiar for several temperature measurement and use this.
  3. A switch item, this is a generic item, so here you could have mqtt, gpio, http and many other bindings as long as it compatible with a switch item(@ThomDietrich can lambda function take optinal argument in case you want to invert the item, i.e On=OFF or set delta temperature ?)

The rule to use this generic function is then simple as this

// Rule to drive the Heater
rule "Heater in living room"
when
Item Netatmo_Indoor_Temperature received update or
Item Heating_LivingRoom_Setpoint received update
then
heatings.apply(Heating_LivingRoom_Setpoint,Netatmo_Indoor_Temperature,Heating_LivingRoom)
end

@ThomDietrich Maybe the simple rule could use group instead to make it more versatile, that you simply tag your control temp measure with [Temperature_control_LivingRoom] and than the witch item with [Heating_output_LivingRoom] and finally [SetPoint_Control_LivingRoom] and then a generic rule somehow loop throug all with tags Setpoint_Control* instead of having to define one rule for each room…

GREAT now we can control our heat! So lets move on… We want our heating to be smart right?
So we dont have to have our heating on standard temperature while we are away, or at night while we are sleeping?

So then the idea is to alter the set temperature, todo this my solution is to have a seperate sitemap called admin where i can configure the set temperatures:

So my solution is to have 3 different temperature set points,

  1. When you are away, you want it just above freezing basically
  2. Normal, when you are home(I does not have different temp for activity level yet…)
  3. When sleeping, at night(You want not to set this to low because you do not want to rapid tempertaure changes every night)

So now @ThomDietrich or @Kai or someone else might have some clever ideas how to do this:)

  • So typically we would enable presence, (WIFI,bluetooth,motion sensors) to detect if away mode should be activated or not
  • Then we would like to sync the alarm clock /calender to find out when the night is over
  • Use IFTTT gps bounding box or similiar to detect that you will be home in XX minutes, calender,cron job
  • To enable night mode use some motion sensors(like under the bed), cron combined with the trigger that bedroom light most likely go on first then off, and other lights are off/other motion sensor off and its after 10 pm or so.
  • Finally what most smart thermostat has, is that if you open a door or window and there is a rapid temperature gradiant then lower the set temperature by 4 degreece untill the door is closed again

This is the most tricky part in my opinion, thats why i just run a simple cron job so far…

So lets recap, does this actually make sense? I am not quite sure with kwh prices around 0.1$. But we can figure out:

Heating cable has pretty constant current draw, so what we can do is just to measure on time:)
Then we could generate a string item which looks like something like this:

Living Room (ON) Last 24H: 0.300kWh/20% Last Week 2.300kWh/20% Last Month 23.00kWh/20% Total Last Week 3300kWh/20%

@ThomDietrich Didnt u write something like that, could we make it generic?

To be updated is alarms, temperature to low, to high, battery changes etc…

2 Likes

Hello @skatun I’ve got a “Heating Boilerplate” tutorial in the first halve of my todo list (yes, it has come to this - prioritization levels :relieved:). The logic is already finished in my home, in the tutorial I’ll discuss related topics and try to explain the whole code for openHAB newcomers. I was hoping to add tutorials for basic topics like heating control, lighting scenes, media control and presence detection/reaction in order to attract and guide new users…

To be honest my implementation is pretty simple and does not consider the main part of your posting. It works with (time, temperature) pairs, which is more than enough for my needs and better suited for a tutorial and general base for openHAB heating control.
Nevertheless the implementation is ready to be extended by ideas like yours. If you want to join me, we can address this topic in the second part of the Tutorial. I also planned to add calendar based control/corrections.

I believe this should be addressed on several levels.

A the top we have your question about the number of “house modes”, and suitable temperatures to go with these. The answer to this is highly subjective, I guess.

At the bottom there is the actual control of the heater, to try to reach and maintain whatever temperature is desired at a given time (i.e. the setpoint). This part is more or less only governed by the setpoint and the actual temperature.

I strongly believe this part is not so well suited for implementation in openHAB (as rules).

My main reason for stating this, is that I believe the basic heater control should keep working even if openHAB happens to be offline for shorter or longer periods of time.

If you have ever woken up a Sunday morning in the wintertime to a very cold house, just to figure out that this is because your newly developed heating control algorithm in the cloud is no longer working - the reason being that your Internet connection died sometime during the night - then you know what I mean, :slight_smile:

Anyway and furthermore, a good control of your heater is likely to require a proper PID algorithm, something that may not be as easily implemented in openHAB.

Now, the “middle level” is an interesting one; given a set of predefined “house mode / temperature levels” how do we decide when to start heating (or cooling) to reach the temperature defined by the next mode at a given time?

This will probably be directly or indirectly affected by the outside temperature (and wind speed) along with the level of insulation and “wind-proofing” of your house. I think this is something that must be decide upon by trial-and-error. Going more high-tech some kind of learning algorithm could be the answer.

In my case all the temperature sensors are running on local host, and if you noticed i connected them to NC on relays in case something happens, then I will just have to open windows in case it gets to hot while i figure out why the RPI crashed, which it still hasn’t done (2 years now…) At least after TEK10 buildings regulations in Norway you can not get your home approved if it has heating that can not be left continuously on. What if a manual thermostat fails? Same likelihood as the rpi crashing…

There are some scientific papers on this, so at least there are some boundaries…

@ThomDietrich set his values fixed in the startupscript, I did this at first aswell, however my GF didnt like the idea that she needed to find a pc, ssh into and change the constant if she got wet and felt cold coming home and wanted to rise the temp by a few degreece. So I made an admin sitemap where you can change these values. But both methods works:)

1 Like

Temperature is slow, so no need for PID, underfloor water heating maybe PI,

The plot shows me its working good enough for my purposes with out a PI regulator

Just use worse case scenario??

Please note, I am no trying to shoot down your idea by being negative, :slight_smile:

I am simply trying to (for my own sake) address the “problem” in a structured manner, since I strongly believe this is the best way to find a solution. Lot’s of smaller problems tends to be easier to solve than a big one, :slight_smile:

Please edit text to make it better :slight_smile:

I thought the lamba function made it super easy for people to adapt to their own home,

  1. Make a sitemap with the desired temp item(number)
  2. Make an item where you read the temp, i.e phillips hue motion sensor or similiar (number)
  3. Connect your heater to a switch item(Like gpio, fibaro outlet etc, if the oven has inbuilt thermostat make sure to set higher then your max desired temp)

Paste my simple rule which triggers when the hue item receives an update(refresh interval of several minutes,20 min or so is fine)

Then for advanced users we add prescence and cron jobs to alter the set point… Persitance to keep the desired temp on reboot etc…

What does this error in my heating rule mean?

21:53:34.332 [ERROR] [.script.engine.ScriptExecutionThread] - Rule 'Heater in living room': org.eclipse.smarthome.core.library.types.DecimalType