Is there a better way to manage states, like 'home', 'away', 'school holiday'?

I am new to openHAB but already I am loving it and have found so much help on the forums to solve the issues I had getting this far. Thanks!

I have got the basics working OK - using an Aeon Labs Z-Stick Gen 5 to control a Horstmann/Secure SRT321 central heating thermostat and a Horstmann/Secure SSR302 two-channel controller to control the hot water. I have some basic rules switching the hot water on and off and setting the heating temperature at different times of day.

Now I want to get more sophisticated and make the heating schedules dependent on what’s going on in our lives. So for example in the summer we will want a completely different heating schedule, so it just warms the towel rails morning and evening. Similarly, during school holidays we will want to override our normal weekday schedule and keep the heating on all day.

Reading around the forums I can’t see a standard way of defining ‘scenes’ or ‘modes’ in openHAB. So I think I need to define some global variables or define items as switches to record these states. But what is considered best practice? What will lead to the cleanest code? I would love to hear your thoughts and experiences before I dive in and make a mess!



To represent these states I prefer to use Switches which get set to ON when in that state and OFF when not in that state. In rules that care about the state they check the Switches and do the desired behavior. Some rules also get triggered when the Switch changes state.

For an example of how Holidays can be tracked see this example on the wiki for calculating public holidays.

See this posting I made for how I keep track of times of day which you can expand to track types of days.

As for detecting presence there are almost as many approaches as there are people. Some people use OwnTracks andthe Mqttitude binding, some use IFTTT, I use network health and some bluetooth scanning scripts, some rely on the Nest, others use motion sensors.

1 Like

I like to use String items that are rendered with a Switch sitemap widget:

// in your items
String desiredComf "desired comf"
// in the sitemap
Switch item=desiredComf mappings=[winter=Winter,summer=Summer,holiday=Holiday,freeze=Freeze]

Your rules would react based on changed to the item:

rule Comfort
  Item desiredComf received command
  if (receivedCommand.toString.equals("summer")) {
    // other stuff
  } else  if (receivedCommand.toString.equals("winter")) {
    // etc

You might also investigate the caldav binding for changing these modes based on calendar events.


I too use a Switch item containing my states. I then have some rules manipulate these states such as a presence rule that automatically switches to 'Away’l state. I also have other rules that check the current state such as a sunset trigger that turns on different lights depending on if the house is in ‘Home’ or ‘Away’ state.

I don’t like that the mapping is set in the sitemap (to me that is the GUI and shouldn’t be defining business logic). However with your state being an Item it is also something that can be changed via IFTTT (provided you setup up persistence of the item to my.Openhab.

1 Like

I don’t see the difference in having a two-position vs. multi-position switch in the UI – the user still wants to choose a mode, and there are usually more than two in OP’s scenario. All logic continues to live in rules in either case.

Thanks everyone. Some really useful insights here that will help me work out what I need to do.

1 Like