[SOLVED] Two rules firing at same time

Hello!!
It appear that earliest an latest in the astro binding is not working as expected… so I made this little work around… It works flawlessly when sunrise in before than the “earliest” (7.20) (and I expect that it would work without problem also if it is after, we will see in a week or so…)
The problem arise in this days, the two rules fired practically simultaneously and none of the two opened the rollershutter leaving also the two control variable in ON state…

Is there a clever way to overcome this behavior?? (the simplest way that I’m thinking is adding an else and fire the same rule a minute or so later…but, meh…)

grep "IsInBoundaryTime" /var/log/openhab2/events.log
2019-10-08 07:20:00.009 [ome.event.ItemCommandEvent] - Item 'IsInBoundaryTime' received command ON
2019-10-08 07:20:00.012 [vent.ItemStateChangedEvent] - IsInBoundaryTime changed from OFF to ON

grep "IsSunrise" /var/log/openhab2/events.log
2019-10-08 07:20:00.009 [ome.event.ItemCommandEvent] - Item 'IsSunrise' received command ON
2019-10-08 07:20:00.013 [vent.ItemStateChangedEvent] - IsSunrise changed from OFF to ON



//*****************************************************************************
//Sunrise open rollershutter
//se IsInBoundaryTime ON (>7:20)
rule "Apri le tende se alba > di cron"
when Channel "astro:sun:home:rise#event" triggered START
then
    IsSunrise.sendCommand(ON)
    if (IsInBoundaryTime.state == ON) {
        gTende_generalePT.sendCommand(UP)
        gTende_generale.sendCommand(UP)
        IsSunrise.sendCommand(OFF)
        IsInBoundaryTime.sendCommand(OFF)
    }
end
//*****************************************************************************

//*****************************************************************************
//7:20 MON to FRI open rollershutter only if already sunrise
rule "Apri le tende alle 7:20 infrasettimanali"
when Time cron "0 20 7 ? * MON-FRI"
then
    IsInBoundaryTime.sendCommand(ON)
    if (IsSunrise.state == ON) {
        gTende_generalePT.sendCommand(UP)
        gTende_generale.sendCommand(UP)
        IsSunrise.sendCommand(OFF)
        IsInBoundaryTime.sendCommand(OFF)
    }
end

First thing is you could change the sendCommand to postUpdate for IsSunrise and IsInBoundaryTime as I assume that they have no bindings attached. That would execute faster.

What’s happening here is that you have two rules running in parallel and acting and checking on the same items so you end up having conflicts. This will happen only twice a year by the way.
A simple solution would be to change the cron time to 10 20 7 ? * MON-FRI
This way the second rule would trigger 10 seconds later and the timing conflict is gone.

I must be missing something. Why would the sunrise and sunset event channels not work for you? They are built in to the astro binding.

They work, is the Earliest/Latest that, when configured in a things file, shows at the correct time in sitemap but fires at sunrise/sunset anyway…
At least is what I found trying and searching in the community post…

Thankyou!! That seem simple and easy :sweat_smile:
I didn’t know that postUpdate is faster than sendCommand

You must separately specify offsets in Things for state (displayable) channels and for event channels.

Can you elaborate this a bit further please? Because in the Astro page there are those example:

astro:sun:home [ geolocation="52.5200066,13.4049540,100", interval=60 ] {
    Channels:
        Type rangeEvent : rise#event [
            offset=-10,
            latest="08:00"
        ]
}

and:

Channels:
    Type start : rise#start [
        offset=5
    ]

as in text:
sun#set earliest=18:00, latest=20:00

And I remember I tried some of this… one give me the date correct but triggered in the non offset time(if I remember correctly the rangeEvent), the other gave a configuration error…

What’s the difference between

Type rangeEvent : rise#event
Type start : rise#start

Thankyou!!

This is an event channel. You cannot link this to an Item, you cannot inspect what it is calculated to be as a datetime because it is an event.
You can trigger rules from this kind of event.

This is a state channel. You would normally link that to a datetime Item, which you can display or compare etc.
But you can’t trigger rules from that datetime because it only changes at midnight when this day’s value is calculated.

offset/earliest/latest are applied only to channels you specify, and not to other possibly related channels.

Another way to look at it - rise#start , rise#event are completely separate “things”, though they are both related to sunrise.
They happen to be a different kind of “thing” as well.

2 Likes

Thank you!!
I’m going to change my things and rules!!