Another rule not triggering with astro

Tags: #<Tag:0x00007f173b535418> #<Tag:0x00007f173b535350>

Hi, please don’t kill i all ready read some problem like mine, but i can’t see the error in my rule. I know the rule is not triggering son the problem must be in the wehn section.

 Channel 'astro:sun:casa:civilDawn#event' triggered START or
 Channel 'astro:sun:casa:civilDusk#event' triggered START

I’m trying to copy “Design Pattern: Time Of Day”, just simplfied for my needs.
Also i define my astro channel by file.

astro:sun:casa  "Sol"  @ "Casa"[ geolocation="number,numbers", interval=43200 ]

Also, i define some item in .items

DateTime    Amanecer_civil  "Astro: Amanecer Civil [%1$tH:%1$tM]" <time> { channel="astro:sun:casa:civilDawn#end" }
DateTime    Atardecer_civil "Astro: Atardecer Civil [%1$tH:%1$tM]" <time> { channel="astro:sun:casa:civilDusk#start" }

I don’t use them so I will delete them.

Finally before i use to start the rule with:

Channel 'astro:sun:casa:civilDawn#end' triggered on or
Channel 'astro:sun:casa:civilDusk#start' triggered on

This second option also doesn’t work.
So i’m little lost, i belive the problem is in the astro channel definition with the #start end eevent option but i’m not sure how.
Thanks

Hi Martin,

What does your log say? If there are errors, your log will tell you when you save the file.

I’m betting that it says something like this:

Configuration model 'astro.things' has errors, therefore ignoring it: [1,46]: mismatched character '<EOF>' expecting '"'

And that’s because you’re missing a quotation mark in your thing, after "numbers,numbers. openHAB sees the first quotation mark on Line 1 at Column 46, but it doesn’t see another to close it.

This is on the assumption that you didn’t accidentally delete the quotation when you replaced your coordinates with "numbers,numbers. If that’s the case, the thing should work and the problem is elsewhere.

It worries me that you would say this, because I personally wouldn’t want anyone to feel unwelcome in this community, or give others the impression that the people here are mean-spirited.

When you’re working with things, items, and rules, the answer is often in the log file. Save the file, then immediately look at the log to see if there’s a problem. If you’re using VS Code with the openHAB extension, it can tell you there’s a problem before saving (often just with colour coding). By following this process, you can eliminate a lot of issues that arise from coding errors.

Look in your events.log to see if the binding generates the events that you expect.

Did they get populated with the times that you expected?

The start and end Channels are the ones that you can link to an Item to see the DateTime. The event Channel is the one you need to use to trigger your Rule.

As the example in the ToD Rule show:

Channel 'astro:sun:home:rise#event'    triggered START or

Yes you are rigth, i delete it accidentally.

the don’t kill was a joke i fell welcome and recibe a lots of help. that is why i continue asking.
Thanks
Finally there are no vs Code error, neither in the logs, the rule is not triggering.

There are no errors logs in events.log neither openhab.log. In the rule i place manual log entry to test where was the error, and nothing appears.
The the item show the correct date and time.

Yes fisrt i tried both now my rule use the first pair, the ones with #event in it.
I copy them from the ToD rule.

In one question on the side. Is there a way to test the rule with out changing the time on the server and without waiting for thtat time of the date?

to repeat

You can trigger the Rule by adding a dummy Item as a trigger and sending a command to that Item. But that doesn’t really tell you whether or not the Channel is triggering which is what you are after here. I know of no way to force the Astro binding to generate the events though short of changing the clocks on the machine. And unfortunately this is the part that is apparently not working.

As rossko57 says, you will see the Astro Trigger Channel events in events.log so you can see there whether or not the binding generates the event.

Yes they are, the start and the end of both. And the other that i don’t care too.

Here i copy the beginnig of the rule:

val logName = "Momento del Dia"
rule "Dia y Noche"

when
    System started or
    Channel 'astro:sun:casa:civilDawn#event' triggered START or
    Channel 'astro:sun:casa:civilDusk#event' triggered START  or    
    Time cron " 0 0 0/1 1/1 * ? * "

then

maybe the other tiggers are interfering.

thanks is now working, i don’t change anything so it must be a type mistake o the servr needs reboot.
I will continue with another question in another post, thanks

1 more things, before leaving, whrn the rule trigger with the civil dawn event it run but it end with Night (noche) option, if i run it one minute later it will arribe to the correct conclusion that is day (Dia) time. So my conclusion is that run so fast that the time pass not enough to make the time calculation ok.
I tried to add a time of 1 minute to the rule but everything stopped working.
I leave the whole rule, to see what is the error.

val logName = "Momento del Dia"
rule "Dia y Noche"

when
    System started or
    Channel 'astro:sun:casa:civilDawn#event' triggered START or
    Channel 'astro:sun:casa:civilDusk#event' triggered START
    //Time cron " 0 0 0/1 1/1 * ? * "

then
  Thread::sleep(1000)
  logInfo(logName, "Calculando...")
  
val amanecer = new DateTime(Amanecer_civil.state.toString)
val atardecer = new DateTime(Atardecer_civil.state.toString)
Thread::sleep(1000)
  var curr = "UNKNOWN"
switch now {
    case now.isAfter(amanecer)  && now.isBefore(atardecer):  curr = "Dia"
  	case now.isAfter(atardecer) || now.isBefore(amanecer): curr = "Noche"
}
logInfo(logName, "El momento del dia es " + curr)
dia.sendCommand(curr) 


end

I discovered that in order to trigger the rule, I could use this command from the openhab console.

openhab> smarthome:things trigger astro:sun:casa:civilDawn#event START
1 Like

I’m not very convinced about using switch-case in that way. Isn’t it going to compare datetime now with case true or case false, and never match?

I must admit that I copied the rule without fully understanding it and try to adapt it to my needs based on trial and error. So any knowledge is welcome. For example I don’t understand Why do I have to convert the time variables to string in order to compare them?

if ( now.isAfter(amanecer) && now.isBefore(atardecer) ) {
   curr = “Dia”
} else {
   curr = “Noche”
}

Yes that is something i understant, but then i will add more moments to the day. I don’t know yet if in the same rule or not. I’m still in the discovery and design phase.
Also, why is the comparison done from string?

Reference