[SOLVED] Sunrise/set not triggering a rule

Hello, I like to use the astro binding for triggering a rule

here is my things

Thing astro:sun:astro_sun_smarthome  [ geolocation="xxxxx", interval=60 ]
Thing astro:moon:astro_moon_smarthome  [ geolocation="xxxxxx", interval=60 ]

Here my rules

rule "set number_openhab2operatingmodus sunrise"
when
    Channel "astro:sun:astro_sun_smarthome:rise#event" triggered START
then
    if ((number_openhab2operatingmodus.state as Number) > 0){ 
        number_openhab2operatingmodus.postUpdate(3)
        logInfo("set number_openhab2operatingmodus sunrise", number_openhab2operatingmodus.state.toString())
    }
end

rule "set number_openhab2operatingmodus day"
when
    Channel "astro:sun:astro_sun_smarthome:rise#event" triggered END
then
    if ((number_openhab2operatingmodus.state as Number) > 0){ 
        number_openhab2operatingmodus.postUpdate(1)
        logInfo("set number_openhab2operatingmodus day", number_openhab2operatingmodus.state.toString())
    }
end

rule "set number_openhab2operatingmodus sunset"
when
    Channel "astro:sun:astro_sun_smarthome:set#event" triggered START
then
    if ((number_openhab2operatingmodus.state as Number) > 0){ 
        number_openhab2operatingmodus.postUpdate(4)
        logInfo("set number_openhab2operatingmodus sunset", number_openhab2operatingmodus.state.toString())
    }
end

rule "set number_openhab2operatingmodus night"
when
    Channel "astro:sun:astro_sun_smarthome:set#event" triggered END
then
    if ((number_openhab2operatingmodus.state as Number) > 0){ 
        number_openhab2operatingmodus.postUpdate(2)
        logInfo("set number_openhab2operatingmodus night", number_openhab2operatingmodus.state.toString())
    }
end

and here my sitemap/item

Switch item=number_openhab2operatingmodus label="Operating Modus" icon="line" mappings=[0="Holiday", 1="Day", 2="Night", 3="Sunrise", 4="Sunset"]

Number number_openhab2operatingmodus "Operating Modus"

But the rule is not triggerd can someone help me what is wrong???

You have defined two Things, but have you also defined the channels? Because that is what you are waiting for, for the Event Channel to trigger a START or END.
Please see the examples here:

Next point, in general, are you always sure the rule isn’t triggered? It might also be related to your if statement.
So could you add a logInfo() directly after each then?

1 Like

I thought I need to things formoon and sun?

I added now the channels

Thing astro:sun:astro_sun_smarthome  [ geolocation="xxxxx", interval=60 ] {
    Channels:
        Type start : rise#start [
            offset=0
        ]
        Type end : rise#end [
            offset=0
        ]
        Type start : set#start [
            offset=0
        ]
        Type end : set#end [
            offset=0
        ]
}

Thing astro:moon:astro_moon_smarthome  [ geolocation="xxxxxx", interval=60 ]

How do you know? Note that none of your rules do anything if that Number item is not > 0. I suspect it is NULL after startup (and so not > 0)

I hav a sepcial startup routine

rule "Set switch_systeminit"
when
    System started
then
    switch_systeminit.postUpdate(OFF)
    createTimer(now.plusSeconds(10), [ | switch_systeminit.postUpdate(ON) ])
    number_openhab2operatingmodus.postUpdate(1)
    logInfo("Set switch_systeminit", switch_systeminit.state.toString())
end

and i tested the rule with a switch before used the event

Did you notice the rangeEvent Channel in the link I provided in my previous post?
Because this:

Channel "astro:sun:astro_sun_smarthome:rise#event" triggered START

Doesn’t match with this

Thing astro:sun:astro_sun_smarthome  [ geolocation="xxxxx", interval=60 ] {
    Channels:
        Type start : rise#start [

That channel definition gives you "astro:sun:astro_sun_smarthome:rise#start", not "astro:sun:astro_sun_smarthome:rise#event".
And importantly, the former is not an event that will trigger a START or END

Yes,and I was to fast and mixing both…

sorry

Thing astro:sun:astro_sun_smarthome  [ geolocation="48.6910697,9.1607886,17", interval=60 ] {
    Channels:
        Type rangeEvent : rise#event [
            offset=0
        ]
        Type rangeEvent : set#event [
            offset=0
        ]
}

sounds better now?

Yeah that looks better. Now just wait to test it :slight_smile:

Just kidding, you can trigger the START and END manually via the console/Karaf:
smarthome:things trigger astro:sun:astro_sun_smarthome:rise#event START
smarthome:things trigger astro:sun:astro_sun_smarthome:rise#event END

How can I start or connect to the karaf console If i have openhab in a “normal” raspbian Stretch installed???

No experience with Raspberry Pi or Linux, but does this help?

1 Like