Thankâs for your hints. I just have a little problem to understand the âSystem startedâ-Trigger. So i made some tests.
- Created (changed) a Rule which starts when System starts/refresh. It should only count how often it will be fired.(IMHO only once)
val String filename = "startup-rules"
var Number count = 0
rule "Look for Raspi_Office is online"
when
System started
then
logInfo (filename, "CPU TEMP " + "Line 1: ")
logInfo (filename, "CPU TEMP " + "Line 2: " ) // Test-Switch
count= count + 1
logInfo (filename, "ZĂ€hler " + "Line 3: " + count)
if (count < 2) {
logInfo (filename, "ZĂ€hler ist ok " + "Line 4: " + count)
}else {
logInfo (filename, "ZĂ€hler ist viel zu hoch" + "Line 4: " + count)
}
- Stopped OH2
- Shutdown and Power off
- Power on, so System restarts.
- Looked into the Log and saw that my Startup-Rule (startup-rules) fired four times and after a refresh only once(see below):
2018-10-03 22:31:14.876 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astra_sun.items'
2018-10-03 22:31:15.239 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astra_moon.items'
2018-10-03 22:31:15.423 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'yahoo.items'
2018-10-03 22:31:15.675 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonoff.items'
2018-10-03 22:31:15.996 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'owm.items'
2018-10-03 22:31:16.204 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astro.items'
2018-10-03 22:31:16.390 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonos.items'
2018-10-03 22:31:16.787 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'system.items'
2018-10-03 22:31:16.977 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'castle.items'
2018-10-03 22:31:21.414 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'avm_fritz.items'
2018-10-03 22:31:22.191 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'network.items'
2018-10-03 22:31:23.070 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'mapdb.persist'
2018-10-03 22:31:26.143 [INFO ] [thome.model.lsp.internal.ModelServer] - Started Language Server Protocol (LSP) service on port 5007
2018-10-03 22:31:31.914 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'cpu.rules'
2018-10-03 22:31:35.059 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'castle.rules'
2018-10-03 22:31:37.154 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astro.rules'
2018-10-03 22:31:38.068 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'startup.rules'
2018-10-03 22:31:39.899 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'castle.sitemap'
2018-10-03 22:31:40.472 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'avm_fritz.things'
2018-10-03 22:31:40.874 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sample_ntp.things'
2018-10-03 22:31:40.902 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'cpu_tempPI.things'
2018-10-03 22:31:40.977 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'network.things'
2018-10-03 22:31:41.067 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'sonos.things'
2018-10-03 22:31:41.096 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'astro.things'
_2018-10-03 22:31:45.506 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: _
_2018-10-03 22:31:45.513 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:_
2018-10-03 22:31:45.704 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:local
2018-10-03 22:31:45.766 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled Positional job astro:sun:local every 300 seconds
_2018-10-03 22:31:46.169 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 1_
2018-10-03 22:31:46.219 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:moon:local
2018-10-03 22:31:46.243 [INFO ] [ding.astro.handler.AstroThingHandler] - Scheduled Positional job astro:moon:local every 300 seconds
2018-10-03 22:31:46.536 [INFO ] [thome.binding.astro.internal.job.Job] - Scheduled Astro event-jobs for thing astro:sun:stowing
2018-10-03 22:31:51.663 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'ntp:ntp:local' to inbox.
_2018-10-03 22:31:52.642 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist okLine 4: 1_
_2018-10-03 22:31:52.648 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: _
_2018-10-03 22:31:52.661 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:_
2018-10-03 22:31:52.692 [INFO ] [marthome.model.script.astro-rules_30] - Tagesphase Day_Phase (Type=StringItem, State=NIGHT, Label=Tagesphase, Category=sunmoon, Groups=[gAstro])
_2018-10-03 22:31:52.669 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 2_
_2018-10-03 22:31:52.729 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist viel zu hochLine 4: 2_
2018-10-03 22:31:56.285 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-10-03 22:31:56.953 [INFO ] [assic.internal.servlet.WebAppServlet] - Started Classic UI at /classicui/app
2018-10-03 22:31:57.064 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-10-03 22:31:57.164 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'samsungtv:tv:0d1cef01_00dc_1000_960f_90f1aac88a51' to inbox.
2018-10-03 22:32:00.449 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-10-03 22:32:00.457 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'peter'
_2018-10-03 22:32:08.592 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: _
_2018-10-03 22:32:08.624 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: _
_2018-10-03 22:32:08.631 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 3_
_2018-10-03 22:32:08.648 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist viel zu hochLine 4: 3_
_2018-10-03 22:32:17.236 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: _
_2018-10-03 22:32:17.240 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: _
_2018-10-03 22:32:17.248 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 4_
_2018-10-03 22:32:17.253 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist viel zu hochLine 4: 4_
2018-10-03 22:35:45.207 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'cpu.rules'
_2018-10-03 22:50:32.309 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'startup.rules'_
_2018-10-03 22:50:38.666 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: _
_2018-10-03 22:50:38.673 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: _
_2018-10-03 22:50:38.681 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 1_
_2018-10-03 22:50:38.689 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist ok Line 4: 1_
- Then i stopped a part of my cpu-rules
val String filename = "cpu-rules"
/*
rule "OpenhabPi Temperature String to Number"
when
Item CPU_Temp changed
then
CPU_Temp_num.postUpdate(Float::parseFloat(String::format("%s",CPU_Temp.state).replace(' ','')))
end
//===================================================================================
rule "RaspberryPi Temperature String to Number"
when
//Item Dummy2 changed to ON // Test-Switch
Item CPU_RasPi_Temp changed
then
if (CPU_RasPi_Temp.state != "Fritz-Box nicht gemountet" && RasPi_online.state == ON )
{
logInfo (filename, "Fritzbox-Usb gemountet " + RasPi_online.state) // this line for test only
CPU_RasPi_Temp_num.postUpdate(Float::parseFloat(String::format("%s",CPU_RasPi_Temp.state).replace(' ','')))
}
else if (CPU_RasPi_Temp.state != "Fritz-Box nicht gemountet" && RasPi_online.state == OFF )
{
CPU_RasPi_Temp_num.postUpdate (0)
logInfo (filename, "Fritzbox-Usb gemountet u. Raspi ist offline" + " " + CPU_RasPi_Temp_num)
}
else
{
CPU_RasPi_Temp_num.postUpdate (0)
logInfo (filename, "Fritzbox-Usb nicht gemountet " + " " + CPU_RasPi_Temp_num)
}
end
//===============================================================================
// RasPi_online
//===============================================================================
*/
rule "RaspberryPi switch off after shutdown"
when
//Item Dummy2 changed to ON //Testschalter
Item RasPi_online changed from ON to OFF
then
logInfo(filename, "Raspberry Office ist Offline und wird in 3 Minuten ausgeschaltet")
createTimer(now.plusMinutes(3), [|
Sonoff_socket_03.sendCommand (OFF)
logInfo(filename, "Raspberry Office {} wurde ausgeschaltet ",Sonoff_socket_03)
])
end
The Log shows that the startup-rules was fired twice:
2018-10-03 23:00:20.829 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1:
2018-10-03 23:00:20.834 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:
2018-10-03 23:00:20.842 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 1
2018-10-03 23:00:21.227 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist ok Line 4: 1
2018-10-03 23:00:23.857 [INFO ] [basic.internal.servlet.WebAppServlet] - Started Basic UI at /basicui/app
2018-10-03 23:00:24.599 [INFO ] [assic.internal.servlet.WebAppServlet] - Started Classic UI at /classicui/app
2018-10-03 23:00:24.771 [INFO ] [arthome.ui.paper.internal.PaperUIApp] - Started Paper UI at /paperui
2018-10-03 23:00:24.890 [INFO ] [g.discovery.internal.PersistentInbox] - Added new thing 'samsungtv:tv:0d1cef01_00dc_1000_960f_90f1aac88a51' to inbox.
2018-10-03 23:00:27.057 [INFO ] [penhab.io.transport.mqtt.MqttService] - MQTT Service initialization completed.
2018-10-03 23:00:27.062 [INFO ] [t.mqtt.internal.MqttBrokerConnection] - Starting MQTT broker connection 'peter'
2018-10-03 23:00:47.205 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1:
2018-10-03 23:00:47.210 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:
2018-10-03 23:00:47.216 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 2
2018-10-03 23:00:47.225 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist viel zu hochLine 4: 2
- I stopped the complete cpu-rules , stopped OH2, shutdown and restarted again, and the result was that these three commands of my startup-rules were not executed:
logInfo (filename, "ZĂ€hler " + "Line 3: " + count)
if (count < 2) {
logInfo (filename, "ZĂ€hler ist ok " + "Line 4: " + count)
The Log looks then
2018-10-03 23:56:25.425 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1:
2018-10-03 23:56:25.947 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:
2018-10-03 23:56:47.725 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1:
2018-10-03 23:56:47.757 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:
2018-10-03 23:56:47.766 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 2
2018-10-03 23:56:47.785 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist viel zu hoch Line 4: 2
2018-10-03 23:56:55.219 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1:
2018-10-03 23:56:55.227 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2:
2018-10-03 23:56:55.241 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler Line 3: 3
2018-10-03 23:56:55.248 [INFO ] [smarthome.model.script.startup-rules] - ZĂ€hler ist viel zu hoch Line 4: 3
The result is always different. I think there is a relation between the two rules(and maybe others), but i donât know which.
But the most curious case is that the startup-rules seems to have something like a loop, even if i canât see it.
https://www.openhab.org/docs/configuration/rules-dsl.html#system-based-triggers