Openhab2 and pool timer setup

Hi folks.

I’ve got openhab2 installed via openhabian on a Raspberry 3.

I’d like to have the pool pumps run according to a schedule and the schedule should also vary according to the seasons and weather.
It’s a small pool, approx 15kl with sun solar panels for heating. In winter it manages to stay above 20C…oh, I need to mention it is an outside pool but under a polycarb roof.
In the peak of summer, it could hit temperatures of 35C.

Anyways…it has 2x pumps…the normal filtering/circulating pump…the same pump/circuit pushes the water through the solar panels.
I have another slightly smaller pump. The one side of the pool has an infinity look/feel.
So water spilling over falls into a catch area.
In the catchup area, there is a municipal tap installed working on a ball valve.
So…effectively the water catchup area is being kept at a constant level. If water level drops, due to sun evaporation, it get’s filled automatically.
Real smart…ok…I didn’t design this…I inherited it when I bought the house some 3x years ago.
Now, the second pump pumps water from this catchup area back into the pool.
If it overfills…well…then it just runs back into the catchup area.

Now, let mew share you the rule I built to manage this.
After I explained above…you now will see why it makes sense that I run the 2nd pump only for 3x minutes at a time…nothing more needed.
This filling up cycle is referred to as “pool fountain” because when the water is pumped from the catchup area back into the pool it runs through/over a rock effect.

Here is the script and then I’ll explain what is wrong or problematic and where I need help.

//Rule to fill pool with water from reservoir
var Timer filltimer = null
var Timer wpooltimer = null
var Timer spooltimer = null
rule "Fill pool operations"
when
    Time cron "0 1 8 ? * * *" // runs everyday at 08:01
    or
    Time cron "0 1 17 ? * SUN,MON,TUE,WED *" // runs Sun/Mon/Tues/Wed/Thurs at 17:01
    or
    Time cron "0 1 18 ? * FRI,SAT *" // runs Fri/Sat at 18:01
    then
        GenericMQTTThing_SonoffTestCh2.sendCommand(ON)
        logInfo("Pool operations", "Pool fountain switched on!")
        filltimer = createTimer(now.plusMinutes(3))  [ |
   		GenericMQTTThing_SonoffTestCh2.sendCommand(OFF)
   		filltimer = null
        logInfo("Pool operations", "Pool fountain switched off!")  ]
end

//--------------------------------------

//Rule to run pool pump
rule "Run pool pump operations in winter"
when
    Time cron "0 02 9 ? * * *" // runs everday at 09:02
    then 
        if (LocalSun_Season_SeasonName.state.toString == "SPRING")  {
            GenericMQTTThing_SonOffTestCh1.sendCommand(ON)
            logInfo("Summer pool operations", "Pool pump switched on for 7.5 hours!")
            spooltimer = createTimer(now.plusHours(7.5))   [ |
            GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
            spooltimer = null
            logInfo("Summer pool operations", "Pool pump switched off!")  ]
        }
        else if (LocalSun_Season_SeasonName.state.toString == "SUMMER")  {
                GenericMQTTThing_SonOffTestCh1.sendCommand(ON)
                logInfo("Summer pool operations", "Pool pump switched on for 7.5 hours!")
                spooltimer = createTimer(now.plusHours(7.5))   [ |
                GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
                spooltimer = null
                logInfo("Summer pool operations", "Pool pump switched off!")  ] 
        }   
end

//Rule to run pool pump
rule "Run pool pump operations in summer"
when
    Time cron "0 02 10 ? * * *" // runs everday at 10:02
    then 
        if (LocalSun_Season_SeasonName.state.toString == "AUTUMN")  {
            GenericMQTTThing_SonOffTestCh1.sendCommand(ON)
            logInfo("Winter pool operations", "Pool pump switched on for 4.5 hours!")
            wpooltimer = createTimer(now.plusHours(4.5))   [ |
            GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
            wpooltimer = null
            logInfo("Winter pool operations", "Pool pump switched off!")  ]
        }
        else if (LocalSun_Season_SeasonName.state.toString == "WINTER")  {
                GenericMQTTThing_SonOffTestCh1.sendCommand(ON)
                logInfo("Winter pool operations", "Pool pump switched on for 4.5 hours!")
                wpooltimer = createTimer(now.plusHours(4.5))   [ |
                GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
                wpooltimer = null
                logInfo("Winter pool operations", "Pool pump switched off!")  ]
        }    
    end

//--------------------------------------

//Rule to stop pool pump
rule "Stop pool pump operations at 17:00"
when
    Time cron "0 00 17 ? * * *" // stops everday at 17:00 for extra precaution
    then 
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off at 17:00 as precaution")
    end

//--------------------------------------

//Rule to stop pool pump
rule "Stop pool pump operations when poor weather"
when
    Channel "LocalWeatherAndForecast_Current_Rain#event" triggered
    or
    Channel "LocalWeatherAndForecast_Current_Cloudiness#event" triggered
    then 
        if(LocalWeatherAndForecast_Current_Rain.state as Number > 75) {
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off due to rain") }
        else if(LocalWeatherAndForecast_Current_Cloudiness.state as Number > 75) {
            GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
            logInfo("Pool operations", "Pool pump switched off due to clouds") }
    end 

The first portion is where I ensure the pool is always kept full by pumping from the catchup area back into the pool.

The second and third portion is the normal running of the filter pump and here you can see how I check on the seasons to determine how long I want the pump to run for the day. In winter for much shorter time since I don’t swim for leisure in water in less than 26C.

The fourth portion is just precaution to ensure the pool pump will never run after hours.

Now…to get to my current problem…or perhaps my wish…
And this is what is seen in the last/5th portion…
what Im trying to achieve here is to stop the filter pump to run when potentially bad weather is being experienced…such as raining…or dark low clouds.
Because this effects the solar heating and things like this would rather cool down the pool water.

My understanding is the following:
I’m looking at 2x parameters:

  1. Rain - this i think is the rain figure, so either in mm or perhaps in %,
  2. cloudiness - this I think is the cloud density also I think in %…not sure.

So from the script, you would see that I set both for 75, which I interpret as 75%.
Once these are exceeded, then the pump shutdown for the day.

But, they are not working.
I’ve got the OPENWEATHERMAP binding installed and working 100%.
But from the script you will noticed that I used the LOCALWEATHER function of openhab. This of course is configured with the correct location info etc.

Could anyone suggest how to perform this or what is wrong with above?

The first thing you need to do is confirm that these Items are storing the data in the units that you think they are. You also need to confirm how they get updated. It does you no good if the Rain Item is storing the amount of rain that has fallen in the past hour or something like that.

Luckily, this sort of stuff is almost always documented in the binding docs.

There is nothing “build in” to openHAB for weather. There are only bindings which provide weather information. You are using the OpenWeatherMap binding. And you seem to have a confusion between Items and Channels. If OpenWeatherMap supported event triggers, which it doesn’t, the Channel ID you would use in the Rule trigger would look something like openweathermap:weather-and-forecast:gleneagle:current#cloudiness. You appear to be trying to use an Item as if it were an event Channel.

You need to look at your OpenWeatherMap Things. Then you need to create and Link Items to those Channels that you care about. Then you need to trigger your Rule when the Cloudiness Channel changes (the rain channel is no good to you as it only shows how much has fallen in the past hour, not whether or not it is raining now).

Hi Rich.

Thank you for above…

After some more trawling of the communities and also checking “openweathermap.org” site…
I came up with the following updated script…this seems to work for me…
I tested this by updating the state value of the weather item…but will keep my eye on actual weather and see if anything different.

//Rule to stop pool pump
rule "Stop pool pump operations when poor weather"
when
    Item Weather_OWM_Condition changed 
    then 
        if (Weather_OWM_Condition.state.toString.contains ("thunderstorm")) {
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off due to " + Weather_OWM_Condition.state) }
        else if (Weather_OWM_Condition.state.toString.contains ("drizzle")) {
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off due to " + Weather_OWM_Condition.state) }
        else if (Weather_OWM_Condition.state.toString.contains ("rain")) {
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off due to " + Weather_OWM_Condition.state) }
        else if (Weather_OWM_Condition.state.toString.contains ("snow")) {
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off due to " + Weather_OWM_Condition.state) }
        else if (Weather_OWM_Condition.state.toString.contains ("overcast clouds")) {
        GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
        logInfo("Pool operations", "Pool pump switched off due to " + Weather_OWM_Condition.state) }
   end 

Thanks for posting the code. For readability, it is considered standard to indent any time you create a new context (i.e. {). Also, by convention, the closing } is usually placed on it’s own line and not indented.

        if (Weather_OWM_Condition.state.toString.contains ("thunderstorm")) {
            GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
            logInfo("Pool operations", "Pool pump switched off due to " + Weather_OWM_Condition.state) 
        }
        else if (Weather_OWM_Condition.state.toString.contains ("drizzle")) {
            GenericMQTTThing_SonOffTestCh1.sendCommand(OFF)
            ...

This makes is much easier to tell which lines go with which context.