- Platform information:
- Hardware: Raspberry 3b
- OS: openhabian w
- Java Runtime Environment: I think 11 32bit
- openHAB version: 3
- Issue of the topic:
Hi,
I would like to estimate my rollershutter positions according to the time they moved up / down.
I know that this is not 100% accurate, but I need this only for the wind sensor to see if they are already on top resp how far they roughly have to move up till they are on the upper most position.
I read a bit about design patterns and thought first best idea is to set for each shutter a timestamp if the UP-relay is switched on / off or DOWN-relay is switched on /off, and calculate the time between these events.
My switch items are called
Shutter1_UP,
Shutter2_UP,
Shutter3_UP,
Shutter1_DW,
Shutter2_DW,
Shutter3_DW.
So, i defined in my rules file the variables:
//Times shutters need to move completely up
val Shutter1_UP_Zeit = 25.0 | s
val Shutter2_UP_Zeit = 25.0 | s
val Shutter3_UP_Zeit = 25.0 | s
...
//Times shutters need to move completely down
val Shutter1_DW_Zeit = 25.0 | s
val Shutter2_DW_Zeit = 25.0 | s
val Shutter3_DW_Zeit = 25.0 | s
...
//start times when shutters were set to on
var long Shutter1_UP_Startzeit
var long Shutter2_UP_Startzeit
var long Shutter3_UP_Startzeit
var long Shutter1_DW_Startzeit
var long Shutter2_DW_Startzeit
var long Shutter3_DW_Startzeit
...
//End times when shutters were set to off
var long Shutter1_UP_Endzeit
var long Shutter2_UP_Endzeit
var long Shutter3_UP_Endzeit
var long Shutter1_DW_Endzeit
var long Shutter2_DW_Endzeit
var long Shutter3_DW_Endzeit
and wanted to use a rule something like
rule "start Timer when shutter begins to move"
when
Member of gShutters changed to ON
then
{
postUpdate(triggeringItem.name+"_Startzeit" = now.toEpochSecond())
}
end
rule "end Timer when shutter stops to move"
when
Member of gSonoffShutters changed to OFF
then
{
if(previousState == ON)
{
postUpdate(triggeringItem.name+"_Endzeit", now.toEpochSecond())
gRollershutterItem.members.forEach[ RollershutterItem rs |
//here goes the for each
val EndzeitName = rs.name+"_Endzeit"
val Endzeit = ScriptServiceUtil.getItemRegistry.getItem(EndzeitName)
val StartzeitName = rs.name+"_Startzeit"
val Startzeit = ScriptServiceUtil.getItemRegistry.getItem(StartzeitName)
if (Endzeit.State <> Startzeit.state
{ //Todo: update estimation
}
]
}
}
end
Unfortunately, I found out that postUpdate function does not work in this way for global variables, and use Number items for them did anyhow did not work either.
So I further searched around, and found out that there is already a rather convenient way to get the timestamp of a modify by simply adding the items
DateTime Shutter1_DW_TimeStamp "Timestamp" <clock> (gtestItems, gTimestamp) {channel="mqtt:topic:Shutter1:Power2" [profile="timestamp-update"]}
So i wanted to map this via a rule of âMember of gTimestamp changedâ to the items
DateTime Shutter1_Startzeit "Startzeit" (gtestItems, gTimestampStart)
DateTime Shutter1_Endzeit "Endzeit" (gtestItems, gTimestampStop)
, But there I stuck again in not knowing how to get the time in s resp. ms between these events.
So, to.make a long story short:
- is there a way to index via a string a global âvarâ like postUpdate for items?
- is there a more easy way to determine the time between 2 events?
- is my approach of the design patterns made correctly or is all I am doing here bullshit?
As I am struggling around now since a couple of days without real success, I would be really pleased if someone can point me to the correct direction how this task should be done in OpenHab, as I am unfortunately still a bloody beginner in OpenHab and itâs rules and methods, and⊠To be honest⊠In general, and would like to learn more from some more experienced usersâŠ
Thanks in advance,
Edizius