- Platform information:
- Hardware: _ Raspberry Pi 3 Model B Rev 1.2_
- OS: Raspbian GNU/Linux 8 (jessie)
- Java Runtime Environment: (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
- openHAB version: openHAB 2.3.0-1 (Release Build) / OH 2.4.0.M4
- Bindings:Astro, AVM, EXEC, MQTT, Network, NTP, Samsung, Sonos, Weather (binding-weather1 - 1.12.0), MapDB-Persitence
- Transformations: exec, Javascript, JSONPATH, Map, RegEx, Scale
On Startup the Rule below should run:
val String filename = "startup-rules"
rule "Look for Raspi_Office is online"
when
System started
then
logInfo (filename, "CPU TEMP " + "Line 1: " + CPU_RasPi_Temp_num ) // Test-Switch
logInfo (filename, "CPU TEMP " + "Line 2: " + CPU_RasPi_Temp ) // Test-Switch
end
/* createTimer(now.plusSeconds(180), [|
if (RasPi_online.state == OFF && CPU_RasPi_Temp_num.state != 0)
{
CPU_RasPi_Temp_num.postUpdate(0)
logInfo (filename, "Raspi ist offline " + ":" + " " + CPU_RasPi_Temp_num)
}
else {
logInfo (filename, "Raspi ist online oder 0 ")
}
logInfo (filename, "Raspberry-Status ist " + ": " + CPU_RasPi_Temp_num)
])
end
*/
I have marked out the tail of the Rule only to see how often the Rule is triggered on Start and when running. This Rule should look if another Raspberry is running and online and if not it should initialize the item"CPU_RasPi_Temp_num" with Zero. In this Version it only gives a LogInfo.
- Items related:
// System temperatures
Group Chart_Sys_Temp (Home)
//Number Chart_Sys_Temp_Period "Periode" (Home)
String CPU_Temp "OH2_CPU Temp-String [%s °C]" <temperature> (Chart_Sys_Temp) { channel="exec:command:cpu_temp:output"}
Number CPU_Temp_num "CPU-OH2-Pi Temperatur [%.1f °C]" <temperature> (Chart_Sys_Temp)
String CPU_RasPi_Temp "RasPi_CPU Temp-String [%s °C]" <temperature> (Chart_Sys_Temp) { channel="exec:command:cpu_raspi_temp:output"}
Number CPU_RasPi_Temp_num "CPU-Ras-Pi Temperatur [%.1f °C]" <temperature> (Chart_Sys_Temp)
- Scripts:
âcpu_temp.sh
#!/bin/bash
INPUT=$(/bin/cat /sys/class/thermal/thermal_zone0/temp)
TEMP=$(echo "scale=1; $INPUT / 1000" | bc)
echo $TEMP
âcpuRasPi_Office_temp.sh
#!/bin/bash
if [ -f /media/fritzbox-usb/CpuTempPi.txt ]
then
INPUT=$(/bin/cat /media/fritzbox-usb/CpuTempPi.txt)
echo $INPUT
else
INPUT="Fritz-Box nicht gemountet"
echo $INPUT
fi
Things-File:
Thing exec:command:cpu_temp "OH2-PI Temperatur" @ "Kinderzimmer"
[command="/bin/bash /etc/openhab2/scripts/cpu_temp.sh", interval=120, timeout=15, transform="REGEX((.*?))"]
Thing exec:command:cpu_raspi_temp "RasPi Temperatur" @ "Kinderzimmer"
[command="/bin/bash /etc/openhab2/scripts/cpuRasPi_Office_temp.sh", interval=120, timeout=15, transform="REGEX((.*?))"]
Logger Extract:
==> /var/log/openhab2/openhab.log <==
2018-09-27 00:59:39.028 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: CPU_RasPi_Temp_num (Type=NumberItem, State=NULL, Label=CPU-Ras-Pi Temperatur, Category=temperature, Groups=[Chart_Sys_Temp])
2018-09-27 00:59:39.038 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: CPU_RasPi_Temp (Type=StringItem, State=Fritz-Box nicht gemountet, Label=RasPi_CPU Temp-String, Category=temperature, Groups=[Chart_Sys_Temp])
==> /var/log/openhab2/events.log <==
==> /var/log/openhab2/openhab.log <==
2018-09-27 01:00:01.660 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: CPU_RasPi_Temp_num (Type=NumberItem, State=NULL, Label=CPU-Ras-Pi Temperatur, Category=temperature, Groups=[Chart_Sys_Temp])
2018-09-27 01:00:01.688 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: CPU_RasPi_Temp (Type=StringItem, State=Fritz-Box nicht gemountet, Label=RasPi_CPU Temp-String, Category=temperature, Groups=[Chart_Sys_Temp])
==> /var/log/openhab2/events.log <==
2018-09-27 01:00:09.436 [vent.ItemStateChangedEvent] - Schaltdose_Fritz_01_Power changed from 21.230 W to 24.580 W
==> /var/log/openhab2/openhab.log <==
2018-09-27 01:00:09.930 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: CPU_RasPi_Temp_num (Type=NumberItem, State=NULL, Label=CPU-Ras-Pi Temperatur, Category=temperature, Groups=[Chart_Sys_Temp])
2018-09-27 01:00:09.939 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: CPU_RasPi_Temp (Type=StringItem, State=Fritz-Box nicht gemountet, Label=RasPi_CPU Temp-String, Category=temperature, Groups=[Chart_Sys_Temp])
==> /var/log/openhab2/events.log <==
2018-09-27 01:19:37.884 [vent.ItemStateChangedEvent] - CPU_RasPi_Temp changed from Fritz-Box nicht gemountet to 55.8
2018-09-27 01:19:37.893 [vent.ItemStateChangedEvent] - Dummy changed from Datei nicht gefunden to 55.8
2018-09-27 01:19:37.965 [vent.ItemStateChangedEvent] - CPU_RasPi_Temp_num changed from NULL to 0
==> /var/log/openhab2/openhab.log <==
2018-09-27 01:19:37.968 [INFO ] [pse.smarthome.model.script.cpu-rules] - Fritzbox-Usb gemountet u. Raspi ist offline CPU_RasPi_Temp_num (Type=NumberItem, State=0, Label=CPU-Ras-Pi Temperatur, Category=temperature, Groups=[Chart_Sys_Temp])
==> /var/log/openhab2/events.log <==
2018-09-27 01:47:23.110 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'avm_fritz.items'
2018-09-27 01:47:33.342 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: CPU_RasPi_Temp_num (Type=NumberItem, State=0, Label=CPU-Ras-Pi Temperatur, Category=temperature, Groups=[Chart_Sys_Temp])
2018-09-27 01:47:33.351 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: CPU_RasPi_Temp (Type=StringItem, State=55.8, Label=RasPi_CPU Temp-String, Category=temperature, Groups=[Chart_Sys_Temp])
2018-09-27 01:57:55.012 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'avm_fritz.items'
2018-09-27 01:58:05.400 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 1: CPU_RasPi_Temp_num (Type=NumberItem, State=0, Label=CPU-Ras-Pi Temperatur, Category=temperature, Groups=[Chart_Sys_Temp])
2018-09-27 01:58:05.408 [INFO ] [smarthome.model.script.startup-rules] - CPU TEMP Line 2: CPU_RasPi_Temp (Type=StringItem, State=55.8, Label=RasPi_CPU Temp-String, Category=temperature, Groups=[Chart_Sys_Temp])
I donât understand that the Rule triggers three times at start and later when a .items-file is updated it fires too !!??. Does OpenHAB see a .items-change as a start ? The behavior occurs in both OH-Versions
Has anyone an idea or can explain me what happens there ?
Regards
Peter