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"
when
System started
then
Set_AirTemp_Seminar_Heating.sendCommand(15)
Set_AirTemp_Lab_Heating.sendCommand(15)
end
rule "Operation Control"
when
System started or
Time cron "0 0 6 * * ?" //(format "second minute hour day-of-month month day-of-week")
then
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)))
){
Operating_Mode_Seminar.sendCommand("OCCUPIED")
Occupied_Seminar.sendCommand(ON)
logInfo("rule", "Log: Occupied mode for Seminar started")
Set_AirTemp_Seminar_Heating.sendCommand(19)
Display_AirTemp_Seminar.postUpdate(Set_AirTemp_Seminar_Heating.state.toString)
Thread::sleep(100)
Operating_Mode_Lab.sendCommand("OCCUPIED")
Occupied_Lab.sendCommand(ON)
logInfo("rule", "Log: Occupied mode for Lab started")
Set_AirTemp_Lab_Heating.sendCommand(19)
Display_AirTemp_Lab.postUpdate(Set_AirTemp_Lab_Heating.state.toString)
}
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(11).plusMinutes(0).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(14).plusMinutes(0)))
{
Operating_Mode_Seminar.sendCommand("VACANT")
Vacant_Seminar.sendCommand(ON)
logInfo("rule", "Log: Vacant mode for Seminar started")
Set_AirTemp_Seminar_Heating.sendCommand(15)
Display_AirTemp_Seminar.postUpdate(Set_AirTemp_Seminar_Heating.state.toString)
Thread::sleep(100)
Operating_Mode_Lab.sendCommand("VACANT")
Vacant_Lab.sendCommand(ON)
logInfo("rule", "Log: Vacant mode for Lab started")
Set_AirTemp_Lab_Heating.sendCommand(15)
Display_AirTemp_Lab.postUpdate(Set_AirTemp_Lab_Heating.state.toString)
}
if (now.isAfter(now.withTimeAtStartOfDay.plusHours(20).plusMinutes(0).millis) && now.isBefore(now.withTimeAtStartOfDay.plusHours(6).plusMinutes(0)))
{
Operating_Mode_Seminar.sendCommand("NIGHT")
Night_Seminar.sendCommand(ON)
logInfo("rule", "Log: Night mode for Seminar started")
Set_AirTemp_Seminar_Heating.sendCommand(20)
Display_AirTemp_Seminar.postUpdate(Set_AirTemp_Seminar_Heating.state.toString)
Thread::sleep(100)
Operating_Mode_Lab.sendCommand("NIGHT")
Night_Lab.sendCommand(ON)
logInfo("rule", "Log: Night mode for Lab started")
Set_AirTemp_Lab_Heating.sendCommand(20)
Display_AirTemp_Lab.postUpdate(Set_AirTemp_Lab_Heating.state.toString)
}
end
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.