Best way to find the right trigger in rule

I have a rule, which starts with two trigger:

rule "Rollladen schliessen"
when
    Time cron "0 0 19 1/1 * ? *" or
    Channel "astro:sun:local:civilDusk#event" triggered START
then
    [...]
end

The goal is to close the roller shutter in winter early when it is dark (before 7.00pm) and in summer not later than 7.00pm). The rule works fine but now I want to extend and close other roller shutter only with the civilDusk event. So I had to found out, if the cron time is the trigger or the civilDusk event. I found in the documentation a code example

    switch(receivedEvent.getEvent()) {
        case "START": {
            Light.sendCommand(ON)
        }
    }

Can this work when not the civilDusk was the trigger? I could compare again my time comparison but perhaps there is another elegant way to check this?

It’s very easy to test it out for yourself. But the answer is no, you’ll get an error on the cron trigger because receivedEvent will not exist.

Set the “Latest” time on the Astro dusk event Channel to 7 pm. That will cause the event to trigger at 7pm even if the actual dusk is after 7pm. When the event is before 7pm the event will trigger at the actual dusk event.

It’s very easy to test it out for yourself.

Not really. I understand what you mean, but think about the women acceptation factor. The rule is working in the moment. I would like to avoid another comment “You and your smart home”. :wink:

Set the “Latest” time on the Astro dusk event Channel to 7 pm.

This wasn’t good for my intention. Two should shutdown latest at 7.00pm, but the rest should shut down with the real civilDusk event. I will check again with my calculated comparison like before.

So you create a test rule that doesn’t do anything but generate a log. They call it computer science because you have to constantly be doing experiments to find out what works and what doesn’t. It’s almost always going to be faster than posting a question to the forum.

That’s what that setting does. If dusk is after 7pm, the event will occur at 7pm instead. If dusk is before 7pm, the event will occur at the actual dusk.

The rule will never run later than 7pm.

And this would be the problem. Today civilDusk was 8.10pm. And this is the time i want for the other roller shutters.

That’s not what you were saying.

In that case, set the earliest to 7pm on the Astro Channel and if dusk occurs before 7pm, the event will trigger the rule at 7pm. If dusk occurs after 7pm, the event will trigger the rule at actual dusk (e.g. 8:10 pm).

There are lots of women who are far more capable with technology than I’ll ever be, including members of this community. It’s fine to say that your partner has an acceptance factor, but I’d ask that we not reinforce demeaning stereotypes and make this a boy’s club.

Why not just create two separate rules?

Your idea is nice, but if I understand this right, I overwrite the civilDusk time. I am not sure, If I want this. But this are the type of ideas, I hoped for this with my post. Thank you.

I am not interested in opening such a discussion, but for short, I was talking about my partner, who is a woman.

I want to avoid that two rules have the same trigger.

Understood, and I don’t want to make an issue of it either. I just feel that language choices matter when it comes to stuff like this, and I can only read “women” as a plural generalization. I’ve seen others refer to it as “partner acceptance factor”, but the reality is that if we’re referring to our wives/husbands/children/etc, then that’s what we should say (and you did do that). No big deal.

No, it only changes when the event that triggers the rule is generated. If you care about the actual time (i.e. linked the start or end Channel to a DateTime Item), that DateTime Item will have the real time of dusk, not the modified earliest time on the event Channel.

All four of these Channels represent some aspect of Civil Dusk. The first three can only be linked to an Item. The last one can only be used to trigger a rule. The “earliest” property is only a property on that last Channel. It has no impact on the other three.

If you need an event for actual dusk to drive some other rule, you can use one of the other dusk set of Channels (you have astro, civic, or nautical to choose from and for a home automation purpose they are all close enough together) or you can create a second Astro Thing without the earliest set on the dusk event Channel.

Or you can deploy something like Time Based State Machine [3.2.0;3.4.9] and break your day up into all sorts of little named chunks to drive things.

Why, there’s nothing wrong with that. But I think Jim’s suggestion is that the two rules would have two different triggers, one for 7 and the other one from the Astro channel event.

This whole thread though is dangerously close to an XY Problem. It just so happens that the most efficient way to implement this also answers your original question. But this is not the only want to do it. You could do something like ignoring what caused the rule to trigger. When the rule runs check to see if now is after the state of a DateTime Item linked to the dusk start Channel. If it is close the blinds. If it’s before do nothing. But ultimately this is far more complicated because it requires an extra Item and a lot more logic than just setting the earliest time on the dusk event Channel which handles everything and all your rule has to do is send the command to the roller shutter.

I like to talk about the “home automation users.” It is more comprehensive and it forces you to think beyond immediate family. Consider your house guests too. :slight_smile:

1 Like
rule "Rollladen schliessen 7pm"
when
    Time cron "0 0 19 1/1 * ? *" or
    Channel "astro:sun:local:civilDusk#event" triggered START
then
    GroupFor7pmShutters.sendCommand(CLOSE)
end

rule "Rollladen schliessen Dusk"
when
    Channel "astro:sun:local:civilDusk#event" triggered START
then
    GroupForDuskShutters.sendCommand(CLOSE)
end

1 Like