[SOLVED] Rollershutter rule with Astro and Latest

Hi there,

I’m wondering why this rule doesn’t trigger …

// THINGS
astro:sun:a-homeX "Astro: Sun-homeX"    [ geolocation="5y.xxxx,8.xxxxx,10", interval=60 ] {
    Channels:
        Type rangeEvent : set#event [
            latest="17:00"
        ]
    }
// ITEMS
DateTime    astro_sun_a_homeX_set_end               "Sonnenuntergang X Ende [%1$tH:%1$tM]"            <dastrosunset>          (gM,Gastro)          {channel="astro:sun:a-homeX:set#end"}
// RULE
rule "Rollladen AZD schliessen"                                               
    when
        Channel 'astro:sun:a-homeX:set#event' triggered END
    then    
        if (EG_az_r_SwitchDimmer.state < 100 && EG_az_r_MeterWatts.state < 20) {
            EG_az_r_SwitchDimmer.sendCommand(ON)
        }
        else {
            return
        }
end

Approach: The rollershutter should close when sunset ends (which is today at 21:08). Due to the latest statement in the channel definition it should trigger earlier today.

The condition EG_az_r_SwitchDimmer.state < 100 && EG_az_r_MeterWatts.state < 20 is used in order to avoid the rule firing when the rollershutter has already been closed or there is movement due to pushing the physical rollershutter switch.

Unfortunately the rule doesn’t work :frowning:

Log for manual start of the rollershutter:

Item 'EG_az_r_SwitchDimmer' received command ON
 EG_az_r_SwitchDimmer predicted to become ON
 EG_az_r_SwitchDimmer changed from 0 to 100
 EG_az_r_MeterWatts changed from 0 to 114
 EG_az_r_SwitchDimmer changed from 100 to 10
 EG_az_r_SwitchDimmer changed from 10 to 20
 EG_az_r_SwitchDimmer changed from 20 to 30
 EG_az_r_SwitchDimmer changed from 30 to 40
 EG_az_r_SwitchDimmer changed from 40 to 50
 EG_az_r_SwitchDimmer changed from 50 to 60
 EG_az_r_SwitchDimmer changed from 60 to 70
 EG_az_r_SwitchDimmer changed from 70 to 80
 EG_az_r_SwitchDimmer changed from 80 to 90
 EG_az_r_MeterWatts changed from 114 to 1
 EG_az_r_MeterWatts changed from 1 to 0
 EG_az_r_SwitchDimmer changed from 90 to 100

As one can see, EG_az_r_SwitchDimmer and EG_az_r_MeterWatts were both 0.

But something must be wrong …

I can’t find out why, but have you tried to use START instead of END in your rule as trigger?

I did another test with a more simple rule and START as trigger.
(In order to make sure that the the condition EG_az_r_SwitchDimmer.state < 100 && EG_az_r_MeterWatts.state < 20 is not causing the problem.)

// THINGS
 astro:sun:a-homeX "Astro: Sun-homeX"    [ geolocation="5y.xxxxx,8.xxxxx,10", interval=60 ] {
    Channels:
        Type rangeEvent : set#event [
            latest="18:12"
        ]
    }
// ITEMS
DateTime    astro_sun_a_homeX_set_start             "Sonnenuntergang X Start [%1$tH:%1$tM]"            <dastrosunset>          (gM,Gastro)          {channel="astro:sun:a-homeX:set#start"}
DateTime    astro_sun_a_homeX_set_end               "Sonnenuntergang X Ende [%1$tH:%1$tM]"            <dastrosunset>          (gM,Gastro)          {channel="astro:sun:a-homeX:set#end"}

// RULE
rule "Rollladen AZD schliessen"                                               
    when
        Channel 'astro:sun:a-homeX:set#event' triggered START
    then    
        EG_az_r_SwitchDimmer.sendCommand(ON)
end

This setup doesn’t work too :frowning:

Check events.log, does the event appear ?
Insert a debug statement at the beginning of the rules. Does it show up in openhab.log ?
Does your astro thing show up e.g. in Karaf console ?
Try creating another astro thing in PaperUI and trigger upon that.

My thing-file:

astro:sun:Weekend [ geolocation="xx.yy,xx.yy", altitude=300, interval=600 ]
{
	Channels:
		Type rangeEvent : rise#event [
            offset=-20,
            earliest="09:00"
        ]
        
		Type rangeEvent : set#event [
            offset=10, 
            latest="22:00"
        ]
}

my rule:


rule "Astro rollershutter down weekend"
    when
        Channel 'astro:sun:Weekend:set#event' triggered START                
    then
       some code here

What’s the time your astro_sun_a_homeX_set_end -Item shows ?
And include a logInfo in your Rule as @mstormi said.

Example:

rule "Stowing1_Set200_Start Test"
    when 
            Item Dummy1 changed to ON or
            Channel 'astro:sun:stowing1:set#event' triggered START
    then
        logInfo("astro-rules" + '_Test', " Set_200 Event. START")
        //EG_EG_Kind2_Licht.sendCommand(ON)
end

and use a Dummy-Item for Testing-purposes (not to wait until the Event happens :wink:). So you can see if the Rule works indeed.

Test-Item:

Switch      Dummy1  "Testschalter Dummy1 [%s]"  (gPower)

Cheers
Peter

EDIT:
Sorry Markus: Wrong Reply-Link. Of course @Selter was meant

Today it’s:

Sonnenuntergang X Start = 21:05
Sonnenuntergang X Ende = 21:10

I don’t know your exactly position, but I think your Start- and End-Times are the “normal ones”, not with offset , as you have no channels defined in your Things-File.

You have to define your Things-File with the several channels for sunset-start, sunset-end and of course for sunset-event in corresponding way, as in my example below. For event Triggers you don’t need an item at all.
Things-Example:

Thing astro:sun:stowing1   "Offset 200"     [geolocation="48.887211,9.8709123,502", interval=300]{
  Channels:
    Type rangeEvent : noon#event [
      offset=200,
      earliest="13:00"
    ]
    Type rangeEvent : set#event [
      offset=90,
      earliest="20:10"
    ]
    Type start : rise#start [
      offset=90,
     earliest="09:00"
    ]
    Type end : rise#end [
      offset=90
    ]
    Type start : set#start [
      offset=90,
      earliest="21:00"
    ]
    Type end : set#end [
      offset=90,
      latest="21:50"
    ]
  }

You can see in my example that there are different parameters (offset and earliest) for the sunset (start, end and event). In my case that means (my sunset time is 20:48) that at the moment my rule will trigger at 22:18 (trigger-event = sunset + 90 Minutes Offset).

In your case this means your Things-File should look like:

astro:sun:a-homeX "Astro: Sun-homeX"    [ geolocation="5y.xxxxx,8.xxxxx,10", interval=60 ] {
    Channels:
        Type rangeEvent : set#event [
            latest="18:12" //  Trigger-Time Time for the Rule you are using
        ]
    Type start : set#start [
      latest="18:12"    // or whatever time you will see in your item
    ]
    Type end : set#end [
      latest="18:12"     // or whatever time you will see in your item
    ]
}

Screenshot:


When looking into my .things-file you can see the meanings of “offset, earliest and latest” as the start-time of the sunset is after the end-time, as marked in the screenshot.

I think your rule triggers at 18:12(17.00) if the condions are correct? so use the “logInfo” to cheque and for testing the Dummy-Switch. Hope this can help you. If you need mor Input, don’t hesitate to ask.

Cheers,
Peter

EDIT:
As the Astro-Binding will recalculate normally only at midnight you can force it to restart via the karaf-console (openhab-cli console).

First look for the bundle-Id with the command:

openhab> bundle:list | grep -i astro
212 x Active   x  80 x 0.11.0.oh250M1         x Eclipse SmartHome Astro Binding

Then restart it with the command:

openhab> bundle:restart 212

The result you can see in the logger:

2019-05-12 12:56:15.261 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:stowing2
2019-05-12 12:57:41.777 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:local
2019-05-12 12:57:41.805 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled Positional job astro:sun:local every 300 seconds
2019-05-12 12:57:41.898 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:local
2019-05-12 12:57:41.945 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled Positional job astro:sun:local every 300 seconds
2019-05-12 12:57:41.956 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:moon:local
2019-05-12 12:57:41.981 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled Positional job astro:moon:local every 300 seconds
2019-05-12 12:57:42.078 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:moon:local
2019-05-12 12:57:42.092 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled Positional job astro:moon:local every 300 seconds
2019-05-12 12:57:42.127 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:minus90
2019-05-12 12:57:42.249 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:stowing
2019-05-12 12:57:42.381 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:stowing1
2019-05-12 12:57:42.483 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:stowing2
1 Like

Thanks for the explanation!

I think this was the problem - I was just too impatient.
I’ll try it tomorrow (with log entries).

Another question rises up - just for understanding:
When (e.g.) sunset starts at 20:00 and ends at 20:15 - what is the purpose of the event channel? I assume that the event is from 20:00 to 20:15 …

No problem at all. :+1: Always my pleasure.

Cheers,
Peter

So if you’re using the event Trigger, you can trigger on START or on END like in the below example:

//===============================================================================
rule "Civil Dusk Ende"
    when
        Channel 'astro:sun:local:civilDusk#event' triggered END
    then
        logInfo("astro-rules" + '_08'," Civil Dusk END")
        //Sonoff_Basic_03.sendCommand(ON)
end
//===============================================================================
rule "Nautik Dusk Start"
    when
        Channel 'astro:sun:local:nauticDusk#event' triggered START
    then
        logInfo("astro-rules" + '_09'," Nautik Dusk Start. START")
        //Sonoff_Basic_03.sendCommand(ON)
end

//===============================================================================

That’s it :wink: