Run Local Sun Rule only once a day

Good morning from Slovakia,
I am trying to implement opening up the Ikea Tradfri blinds depending on sun angle.

How can I run it only once a day?

rule "uhol_slnka_rolety"
//zahrnut teplotu von/dnu a svetlo - meteostanica
when
    Item LocalSun_Azimuth changed
then 
    if (LocalSun_Azimuth.state > 175| "°" && LocalSun_Azimuth.state < 178| "°") { //Juzne okna su 197deg. dat toleranciu 3stupne
    sendBroadcastNotification("Utekaj pozriet, ci uz je tien")
    logInfo("uhol_slnka_rolety.rules", "Sunblinds up when azimuth exceeds treshold" ) 
    } 
end

I tried it to run it only when sun is between 175 and 178 degrees, but sometimes it is running twice. I know I can tune it up with changing the Item interval (currently 300 sec), but I suppose it is not the greatest way how to do it…
It is currently in testing, I am trying to figure out the sun angle, so there is no sunblinds command actually.

hi there, why dont you use a bool, and set it true when blinds are operated? and set it false at midnight. then „ if bool = true and angle = xyz then …“

2 Likes

you could simply add a line before your IF:

if (Tradfri blinds.state == 100) { return; } // the 100 is just an example for the full up state of your blind.

The rule won´t continue to your current IF in case the blind is already up or was never down that day or put up manually before

You could consider to add Time of Day pattern to it so that the rule in generally only runs like in the afternoon and not every time LocalSun_Azimuth changes, which i suspect happens all day, right?

And all night :slight_smile: but running a rule doesn’t cost much, simplicity is good.

I think the trouble with basing a “do it” decision on existing state is that you won’t get the “once a day” effect. If someone manually closes the blinds, the rule may come along and open them again because it doesn’t know it’s already done it that day.

That´s correct. If i interpret the intention of @misko903 correctly, he wants the blinds that “potentially” are down go up based on the state of the sun in a short window of time. If yes, in my view he could even leave this rule as is and not worry the rule eventually fires 2 times during 175 - 178. the worse that happens is 2 log entries. If the blind get´s another command up and is already up, who cares… The compexity would start if the blinds go up, someone intentionally put them down again for whatever reason if still between 175-178 and a minute later or so it goes up again…, still in 175 - 178. Correct?

We should not forget that can happen twice each day, sun going up and coming down.

upps. right. more fun to think about a good rule and conditions. :slight_smile:

Oh wait, “twice a day” is tosh. Azimuth,not elevation. Only one period.

Thanks all, guys

I think the best solution would be to set the boolean to true, which will be reset on midnight.
This is what I am going to test now:

var boolean roletyIsliHore = true

rule "uhol_slnka_rolety"
//zahrnut teplotu von/dnu a svetlo - meteostanica
when
    Item LocalSun_Azimuth changed
then 
    if (LocalSun_Azimuth.state > 175| "°" && roletyIsliHore == false) { //Juzne okna su 197deg.
//        if (Sunblinds.state != UP) {sendCommand(Sunblinds, UP)}
    roletyIsliHore = true
    sendBroadcastNotification("Utekaj pozriet, ci uz je tien")
    logInfo("uhol_slnka_rolety.rules", "Sunblinds up when azimuth exceeds treshold" ) 
    } 
end

//nastavit roletyIsliHore = false o polnoci
rule "polnocny_reset_roletyIsliHore"
when
    Time is midnight
then
    roletyIsliHore = false
end

does not worked, the command comed up at midnight, as roletyIsliHore is reset to false
and
LocalSun_Azimuth.state > 175| "°" && roletyIsliHore == false

lets try it with
Time is noon

Don’t you want to test for more than X AND less than Y ?

1 Like

Is anyone guys using the blinds same way?
I want the blinds to stop the sun heating the house in summer.
My first idea is to measure temp outside, and when it is probabilty to heat the house, the blinds will be closed.
other than that, I want to have a nice view and blinds will be opened on the sunrise.

do you have another idea what to take into account? cloud coverage is not very good in our hilly country.

like this?
if (LocalSun_Azimuth.state > 175| "°" && LocalSun_Azimuth.state < 178| "°" && roletyIsliHore == false)
honestly, I thought about it, but i was afraid that there can be value lower and higher and then the rule is not triggered at all. But wait, I can open the interval more!
if (LocalSun_Azimuth.state > 175| "°" && LocalSun_Azimuth.state < 190| "°" && roletyIsliHore == false)

1 Like

I think my “twice a day” concern comes back here; the sun has an azimuth even when it is below the horizon.

You can make your conditions as complicated as you like, based on season, weather forecast, whatever. It’s just a bunch of true/false decisions.

Nope, look at the graph :slight_smile:

I will start probably with outside temp first. This will be the most important value to decide what to do with blinds.

I actually have something very similar - i partially close blinds if the sun is shining through the windows, mine looks like this:

rule "Stineni proti slunci"
when
    Item virtual_sun_azimuth received update or
    Item virtual_sunblock_toggle received command
then
    var status = OFF
    var noon_time = new DateTimeType(virtual_noon_end.state.toString)
    var azimuth = (virtual_sun_azimuth.state as Number).doubleValue
    var angle = (virtual_sun_angle.state as Number).doubleValue
    var tempOut = if (balcony_temperature.state == NULL) 0 else (balcony_temperature.state as Number).intValue
    var tempIn = if (livingroom_temperature.state == NULL) 0 else (livingroom_temperature.state as Number).intValue

    logDebug("Sunblock", "Noon: " + noon_time + ", azimuth: " + azimuth + ", angle: " + angle + ", tempIn: " + tempIn + ", tempOut: " + tempOut)

    if (virtual_sunblock_toggle.state == ON && virtual_day.state == ON && now.isAfter(noon_time.getZonedDateTime) && tempIn >= 23 && tempOut >= tempIn) {
        // if sun > 57 deg - too high, not shining in
        if(angle <= 55 && azimuth > 218) {
            // under 270 - next to building, height doesn't matter
            if(azimuth <= 270) {
                status = ON
            } else {
                // above building but only until 27
                if(angle >= 27) {
                    status = ON
                }
            }
        }
    }
    
    if (virtual_sunblock_active.state != status) {
        logInfo("Sunblock", status + " - Noon: " + noon_time + ", azimuth: " + azimuth + ", angle: " + angle + ", tempOut: " + tempOut + ", tempIn: " + tempIn)
        virtual_sunblock_active.postUpdate(status)
    }
end

And the rule that actually controls the blinds:

rule "Roleta obyvak - zatahnout proti slunci"
when
    Item virtual_sunblock_active changed
then
    if(virtual_sunblock_active.state == ON) {
        if(livingroom_blinds.state < 40) {
            livingroom_blinds.sendCommand(40)
        }
    } else {
        if(livingroom_blinds.state == 40) {
            livingroom_blinds.sendCommand(0)
        }
    }
end
1 Like

Thanks for the rule, I’ll try to get it…
Nice to see neighbours language on international forum :slight_smile: which blinds are you using? mine are IKEA.

I have motorized outdoor blinds which i wired to Fibaro Rollershutter 2. I also have that IKEA one but only close it at night.

What about the cloudiness? Did you thought about to integrate it? My idea is to do it so:
if there is a prediction of 30% cloudines until cca 13:00, the sunblinds will be open in the morning already. No matter the temperatures.

Yes I was thinking about it, but just weather prediction is not accurate enough for this kind of thing. I think it would need something like light sensor, but I didn’t found any which can measure direct sunlight. That rule with sun position and temperature seems to work good enough for me.

1 Like