I want to show the event and the event time of a sensor in one place.
I have a motion sensor (Fibaro - FGMS-001) with e.g. temperature, lux and motion sensors
In the basicui sitemap, near the motion alarm event I want to show the event time
(instead of the current 2 fields that are shown seperatly, e.g. Fibaro1 Alarm Motion, Fibaro1 Alarm Motion Time - see note2)
See the items, rules, sitemap files in note1
The reason I want to consolidate the 2 items in a single field are:
- I have multiple sensors, so having twice as many fields is messy
- The renderring of the fields in the sitemap is sometimes shifted around (is there a way to fix the rendering order in basicui?)
Thanks
p.s. My installation is OH2 official release.
--------------------------------------------
---- note1
cat /etc/openhab2/items/fibaro.items
Group gFibaro1Sensors (All)
Group gFibaro1SensorsTime (All)
Number Fibaro1Lux "*Fibaro1 [%.2f Lux]" <sun> (gFibaro1Sensors) { channel="zwave:device:02710de3:node6:sensor_luminance" }
Number Fibaro1Temp "Fibaro1 Temp [%.1f C]" <temperature> (gFibaro1Sensors) { channel="zwave:device:02710de3:node6:sensor_temperature" }
DateTime Fibaro1Temp_LastUpdate "Fibaro1 Temp time [%1$tm/%1$td %1$tH:%1$tM]" <clock> (gFibaro1SensorsTime)
Switch Fibaro1AlarmMotion "Fibaro1 Alarm Motion [%s]" <fire> (gFibaro1Sensors) { channel="zwave:device:02710de3:node6:alarm_motion" }
DateTime Fibaro1AlarmMotion_LastUpdate "Fibaro1 Alarm Motion time [%1$tm/%1$td %1$tH:%1$tM]" <clock> (gFibaro1SensorsTime)
cat /etc/openhab2/rules/fibaro.rules
import org.openhab.core.library.types.DateTimeType
rule "Records when device was last seen"
when
Item Fibaro1AlarmMotion received update or
Item Fibaro1Temp received update or
Item Fibaro1Lux received update
then
logInfo("RULE", "--> Fibaro1_LastUpdate executed...")
// Get the updated event
Thread::sleep(100)
val haveHistory = gFibaro1Sensors.members.filter[l|l.lastUpdate("mapdb") != null]
logInfo("Test", "There are " + haveHistory.size + " items that have a last update")
gFibaro1Sensors.members.filter[s|s.lastUpdate("mapdb") != null].forEach[ sensor1 |
gFibaro1SensorsTime.members.filter(dt|dt.name == sensor1.name+"_LastUpdate").head.postUpdate(new DateTimeType)
]
end
cat /etc/openhab2/sitemaps/default.sitemap
sitemap default label="My home automation" {
Frame label="Fibaro FGMS-001" {
Text item=Fibaro1AlarmMotion
Text item=Fibaro1AlarmMotion_LastUpdate
}
}
note2