Rule: if month=1,2,3 then

Hi,

i want to make a rule, whioch makes different things when a specific month is at that time:

Rule for jalousie/blinds:

If it is summer, then only open jalousie a little bit in the morning (only moving the angel of the lamellas)
if it is winter, open the whole jalousie - so that i can use sun heating

How can i do that? I know i can do that on top of the rule in the “when…”-part.

But can i do that on the “if-part” as well?

Here is my actual rule:

// Rollos morgens Astro hoch - wenn nach xx Uhr
rule "Rollos Astro hoch"
when
    Item Rollos_astro_up received update ON
then
    sendCommand(Rollos_is_day, ON)
    if (SunriseLimit.state == ON) {
        sendCommand(Rollos, UP)
	sendCommand(Lamellen, 0)
    }
end

Is something like this also working?

// Rollos morgens Astro hoch - wenn nach xx Uhr
rule "Rollos Astro hoch"
when
    Item Rollos_astro_up received update ON
then
    sendCommand(Rollos_is_day, ON)
    if (SunriseLimit.state == ON) {
        sendCommand(Rollos, UP)
	if month=4-8
            sendCommand(Lamellen, 0)
        if month=9-3
            sendCommand(Jalousie, 0)
    }
end

Hello Halloween

I have same rules implemented. I use the weather and astro binding for it.
When the outside temp is below X and weather != sunny open blinds completly, otherwise only a bit.

With this implemention the blinds also open when its raining in summer.

I know that, but i don´t want to use weather binding. I sometimes get wired things from this, not like the weater is on my place at this moment. And sometimes weather changes very fast.

So i want to do that with month or time of year.

Can you post your rule?

I made a proxy-switch-item for shading: Beschattung_Proxy

rule

// Beschattung ja
rule "Beschattung ja"
when
    Time cron "* * * ? 5-9 *"
then
    sendCommand(Beschattung_Proxy, ON)
end

// Beschattung nein
rule "Beschattung nein"
when
    Time cron "* * * ? 10-4 *"
then
    sendCommand(Beschattung_Proxy, OFF)
end    


// Rollos morgens Astro hoch - wenn nach xx Uhr
rule "Rollos Astro hoch"
when
    Item Rollos_astro_up received update ON
then
    sendCommand(Rollos_is_day, ON)
    if (SunriseLimit.state == ON) {
        sendCommand(Rollos, UP)
		if (Beschattung_Proxy == ON) {
			sendCommand(Lamellen, 0)
		}
		if (Beschattung_Proxy == OFF {
			sendCommand(Jalousien, UP)
		}
    }
end

I think it is workin now.

Can i do this in a better way? Maybe remove one of the rules?

rule "Jalousie auf am Morgen"
when
	Item Sunrise_Event received update
then
	//das Bad dreht am Morgen nur ein wenig auf
		Jal_Bad.sendCommand(UP)
		Thread::sleep(500)						//Aufdrehen, 0.7s
		Jal_Bad.sendCommand(STOP)
	
	//wenn die Wettervorhersage sonnig Storen ostseitig nur aufgedreht
	if(Current_Clouds.state <= 50) { 
		if ((Temp_Max_0.state > 15) && (Temp_Max_0.state < 28)) {
			//Nach einer Pause das Büro
			Jal_Buerau.sendCommand(UP)
			Thread::sleep(200)						//Aufdrehen, 0.3s
			Jal_Buerau.sendCommand(STOP)
			
			if (AnasSleep.state == OFF) {
				Jal_Kinderzimmer.sendCommand(UP)
				Thread::sleep(200)
				Jal_Kinderzimmer.sendCommand(STOP)
			}
		}
		// wenn die Aussentemperatur höher als 30° ist, bleiben die Storen ganz zu
		if (Temp_Max_0.state > 28) {
			
		}
	}
	if (Current_Clouds.state > 50) {
		Jal_Buerau.sendCommand(UP)
		if (AnasSleep.state == OFF) {
				Jal_Kinderzimmer.sendCommand(UP)
		}
	}
end

Ultimately I recommend implementing something like this:

Actually you can’t as far as I’m aware.

This is the proper place to implement it.

The idea is right but the syntax is wrong.

    val currMonth = now.getMonthOfYear
    if(currMonth >= 4 || currMonth >= 8) Lamellen.sendCommand(0)
    else if(currMonth <= 3 || currMonth >= 9) Jalousie.sendCommand(0)

This is actually pretty close to the Design Pattern I posted above. To make it a little more human readable and a little more flexible (i.e. have other rules that change their behavior based on the seasons) I would change your Proxy Item to a String and create a rule that populates that String with the season. Then in your rule:

if(Beschattung_Proxy.state == "summer") sendCommand(Lamellen, 0)
else sendCommand(Jalousien, UP)

This way you can actually get the calculation for when the season starts and stops very precisely if you want, and you can add new seasons or states if desired with minimal extra work.

I’ve found that when you set up a state Item like this you start to think of new ways you can use it.

The idea with the proxy-item was no good idea, i got log entrys every second with proxy-item=0ff

Also it was not working. Jalousie and lamellas stayed closed both in the morning.

Now i changed to your first example and hope that it is working tomorrow in the morning.

Maybe i change this to a proxy item again, when i have to set up my shading rule for next summer.


EDIT:

I changed a typo ( < instead of > ) in the first if-part

        val currMonth = now.getMonthOfYear
        if(currMonth >= 4 || currMonth <= 8) Lamellen.sendCommand(0)
        else if(currMonth <= 3 || currMonth >= 9) Jalousien.sendCommand(UP)

I think there is an error in the rule? Last else if is always false i think?

currMonth can´t be <=3 and >=9 at the same time?!?!?!

“||” is used as “and” in this rule?
Do i have to change this “||” to “or”? Whats the sign for “or” to use in the rule?

“||” means or
“&&” means and

So if(currMonth <=3 || currMonth >= 9) means if currMonth is less than or equal to 3 or currMonth is greater than or equal to 9.

So the error is actually in the first part of the if.

if(currMonth >= 4 && currMonth <= 8)

Hi,
can i use this with all time-areas?

Can i use currDay, currHour, currMinute as well?

If i use currHour - it will work with 24-time format? Like this?

if(currHour >= 10 && currHour <= 14)

EDIT:

Not working, i get the following error in the log:

[.script.engine.ScriptExecutionThread] - Rule 'Licht Eingang EG ein': An error occured during the script execution: The name 'currHour' cannot be resolved to an item or type.

Is there a way to get this working? Other way i have to do this with a proxy item and cron job i think? But it would be much better, if i can do it this way.

To get it working, you need a variable (or an item) for your currDay, currHour …

val currDay = now.getDayOfWeek() 
val currHour = now.getHourOfDay()

Andreas

1 Like

Oh, i looked into my rule for the blinds and you are right…

Thanks!

Why do you write brackets at the end () ?

I don´t use this in my blinds-rule and it is working. Is there a need for this?

Maybe just got confused because programming in C at the moment…