[HELP] Have I missed something in a Rule?

I made the change as suggested and this hasn’t made a difference. Sadly I’m not further forward. The Switch’s in the items file are something I need to clean up, but they aren’t causing any errors.

In the logfiles, do you have any astro events? In the openhab.log there should be something like

2018-03-09 00:00:30.254 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:local

once a day, at 30secs past midnight. Then, in the events log, there should be lots of these:

2018-03-09 00:00:30.271 [vent.ChannelTriggeredEvent] - astro:sun:local:morningNight#event triggered START
2018-03-09 06:15:00.006 [vent.ChannelTriggeredEvent] - astro:sun:local:astroDawn#event triggered START
2018-03-09 06:15:00.010 [vent.ChannelTriggeredEvent] - astro:sun:local:morningNight#event triggered END
2018-03-09 06:44:00.004 [vent.ChannelTriggeredEvent] - astro:sun:local:nauticDawn#event triggered START
2018-03-09 06:44:00.008 [vent.ChannelTriggeredEvent] - astro:sun:local:astroDawn#event triggered END
2018-03-09 07:14:00.003 [vent.ChannelTriggeredEvent] - astro:sun:local:nauticDawn#event triggered END

If these are not there, you problem isn’t the rule.

To filter all the other clutter try the following the linux commands in the log directory

grep astro openhab.log
grep astro events.log

Here’s a long shot… have you been modifying items files while OH is running? This can cause issues. I wanted to make a quick change recently to update an item (I knew I shouldn’t :roll_eyes:) and noticed all of my cron rules stopped firing. Astro uses the Quartz scheduler too, so those channels were probably not updating either. Does restarting change anything?

But first, add some logging into your rule, especially at the start of it, and monitor the openhab.log file after a restart to see if it fires.

What version of OH are you running? I thought this got fixed before the release of OH 2.2. I’ve not seen many if any new threads complaining about it.

The standard approach is to edit .items et al while OH is running. The only thing you shouldn’t edit while OH is running is the JSONDB files.

2.3.0 snapshot 1224. I was seeing the order of items changing in the UI, groups not being updated, bindings restarting, etc. so I stopped editing items while OH was running. It’s been a while, so this may all be fixed, at least in the snapshot. But my cron rules definitely stopped, so this might be a new issue. I commented in ESH issue #4130, in case this is related.

Hi Scott,

I’m currently running with OH2.1, having gone though the process of upgrading from 1.8.3. The Next step will be to move onto version 2.2 or 2.3, depending on timing.

I’m not changing items files all the time and have restarted OH a number of times and still the rule doesn’t work as expected. The run works fine at the restart and picks up the current time of day.

I’ll look at adding additional logging to see if that helps. Thanks.

Since we are on the topic of the rule running when "system started’ but then with changing time of day, no command is executed. I have a query related to the same.
My items file:

String Operating_Mode_Seminar	"[MAP(op.map):%s]"		<settings> 	//(All)
String Operating_Mode_Lab		"[MAP(op.map):%s]"		<settings> 	//(All)

Switch Night_Seminar			"Operating Mode is [MAP(mode.map):%s]"			//(All)
Switch Occupied_Seminar			"Operating Mode is [MAP(mode.map):%s]"			//(All)
Switch Vacant_Seminar			"Operating Mode is [MAP(mode.map):%s]"			//(All)
Switch Night_Lab				"Operating Mode is [MAP(mode.map):%s]"			//(All)
Switch Occupied_Lab				"Operating Mode is [MAP(mode.map):%s]"			//(All)
Switch Vacant_Lab				"Operating Mode is [MAP(mode.map):%s]"			//(All)

Number Set_AirTemp_Seminar_Heating	"Set seminar heating temp. [%.1f °C]"		<temperature_hot>	
Number Set_AirTemp_Lab_Heating		"Set lab heating temp. [%.1f °C]"			<temperature_hot>

My Rules:

rule "Initialize system values"
        	System started

rule "Operation Control"
		System started or
		Time cron "0 0 6 * * ?" //(format "second minute hour day-of-month month day-of-week")
		if ((now.isAfter(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(0).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(11).plusMinutes(0)))
			|| (now.isAfter(now.withTimeAtStartOfDay.plusHours(14).plusMinutes(0).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(0))) 
			logInfo("rule", "Log: Occupied mode for Seminar started")
			logInfo("rule", "Log: Occupied mode for Lab started")
		if (now.isAfter(now.withTimeAtStartOfDay.plusHours(11).plusMinutes(0).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(14).plusMinutes(0)))
			logInfo("rule", "Log: Vacant mode for Seminar started")
			logInfo("rule", "Log: Vacant mode for Lab started")
		if (now.isAfter(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(0).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(0))) 
			logInfo("rule", "Log: Night mode for Seminar started")
			logInfo("rule", "Log: Night mode for Lab started")

So on every restart of openHAB, the Rule “Operation control” runs and based on the “if statement” the respective mode of operation is activated. So based on the above timings, here is the log:

2018-03-12 14:31:28.988 [ItemCommandEvent          ] - Item 'Set_AirTemp_Seminar_Heating' received command 15
2018-03-12 14:31:28.988 [ItemCommandEvent          ] - Item 'Set_AirTemp_Lab_Heating' received command 15
2018-03-12 14:31:28.989 [ItemStateChangedEvent     ] - Set_AirTemp_Seminar_Heating changed from 19 to 15
2018-03-12 14:31:28.989 [ItemStateChangedEvent     ] - Set_AirTemp_Lab_Heating changed from 19 to 15
2018-03-12 14:31:28.992 [ItemCommandEvent          ] - Item 'Operating_Mode_Seminar' received command OCCUPIED
2018-03-12 14:31:28.992 [ItemCommandEvent          ] - Item 'Occupied_Seminar' received command ON
2018-03-12 14:31:28.992 [INFO ] [.eclipse.smarthome.model.script.rule] - Log: Occupied mode for Seminar started
2018-03-12 14:31:28.993 [ItemCommandEvent          ] - Item 'Set_AirTemp_Seminar_Heating' received command 19
2018-03-12 14:31:28.994 [ItemStateChangedEvent     ] - Set_AirTemp_Seminar_Heating changed from 15 to 19
2018-03-12 14:31:29.095 [ItemCommandEvent          ] - Item 'Operating_Mode_Lab' received command OCCUPIED
2018-03-12 14:31:29.095 [INFO ] [.eclipse.smarthome.model.script.rule] - Log: Occupied mode for Lab started
2018-03-12 14:31:29.096 [ItemCommandEvent          ] - Item 'Occupied_Lab' received command ON
2018-03-12 14:31:29.097 [ItemCommandEvent          ] - Item 'Set_AirTemp_Lab_Heating' received command 19
2018-03-12 14:31:29.101 [ItemStateChangedEvent     ] - Set_AirTemp_Lab_Heating changed from 15 to 19

So why doesn’t my rule from the other “if statements” get activated when the time of day is changed.
FYI: For simulation purpose, I did change the timings in the other “if” blocks, to my current time and tried if it changed the mode of operation and it does change but only when “system started”.
What do I need to do here? has this anything to do with persistence?
I have been through the “Design Pattern: Time of day” but I found the above written rule to be useful.
Any thoughts?
Thanks in advance.

Which version of OH are you running?

Oops I forgot to mention.

Its openHAB 2.1 build #858

Your rule only triggers on System started and at 06:00. Unless you happen to restart OH during one of those other times of day those if statements will never execute because the rule only gets triggered at the one time of day.

OK. So I found the error. As you said, I had only one Cron which would trigger at 6 AM.
So I included this Cron expression
(the timings are changed to the current time)

    System Started or
    Time cron "0 35 17 * * ? *" or
    Time cron "0 37 17 * * ? *" or
    Time cron "0 39 17 * * ? *"
    -------/do the if statements/-------

But when I combined that Cron into one expression, it worked like a charm. All the 3 modes of operation.

    System Started or
    Time cron "0 45,47,49 17 * * ? *"
     -------/do the if statements/-------

So I guess that multiple cron is solved in 2.2 version and not in 2.1
Or It should work but I am unable to do it for some reason??
Anyways my rule works, I am happy.

That is correct. Multiple cron triggers was solved in 2.2

Any further suggestions of where I should look to try and resolve my issue? Or is it a case of working towards upgrading to OH2.2?

How do the log files look like, are the ChannelTriggered events even there?

If not and you’re trying to debug the rule you are looking at the wrong place. The it would be the setup of the binding or the binding itself. If yes you should add logging the steps of the the rule, say every couple of lines, to see where it fails.

There is nothing in the events.log at all related to the triggers. So I’m guessing that it’s not the rule or syntax causing the issue.

The Astro binding seems to be configured correctly as I get my sun rise and sun set times.

Searching around, there are issues with this reported for 2.1 that should be fixed in 2.2. Don’t see the hardware you’re running on, but if pi consider testing this with a second SD card with 2.2 on it, and only the astro binding to see if it schedules the triggers.

I’m running OH on a VM, so no need for swapping SD cards around. I was already planning on migrating my configuration to 2.2 after I got it all working in 2.1, looks like I’ll have to bring those plans forward.

Thanks for your help.

@rlkoshak as you can see I have 3 modes of operation. What I want to understand is, if a mode say OCCUPIED received command ON, does it mean that the system considers the other 2 modes as “OFF” by default.
What I want to ask is, will the system hold the state of the other modes as “OFF” or not, without receiving a command “OFF”?

And most importantly can I use that default “OFF” state as a trigger in another rule?
Such as

rule "Manual Mode Operation - Seminar"
		Item Occupied_Seminar received command OFF or
		Item Vacant_Seminar received command OFF or
		Item Night_Seminar received command OFF
		if(Occupied_Seminar.state !=ON && Vacant_Seminar.state !=ON && Night_Seminar.state !=ON) {

Just want to understand if what I am thinking is possible or not.

I’m not sure I fully understand the question.

Rules are triggered by events. So the above Rule will run when Occupied_Seminar receives an OFF command, or Vacant_Seminar receives an OFF command, or Night_Seminar receives an OFF command. No two events are ever likely to occur at the same time, which is why it doesn’t make sense to have an and in the when clause of a Rule. That covers the Rule trigger.

Your if statement is using && so the body of the if statement will only execute if all three Items are OFF. An Item stays in whatever state it last was in until it receives a command or update that puts it into a different state, or OH has restarted or re-read in a .items file in which case all the Items get defaulted to NULL. If you have persistence set up, the Items will be updated to the most recently saved value in the database.

Sorry if my question was a bit confusing. I understood both your explanations perfectly well.
I did not realize about the when part. In my head I was thinking “and”, but I understand now that it is not possible to do like that.

I will tinker a bit on this for now.
Thanks for the info.
Sometimes the obvious things goes right out of the mind :disappointed:
and Sorry for deviating from the main topic by the OP.