hey all,
im having a small problem with with a small bit of this code. otherwise this works well but still needs more tweaking
the 1st small issue im having is
val Number distancesec = distance/30
im using this in a timer but the timer never runs as long as it is meant to. some times it will be close. others only a small amount of time passes.
2nd issue im had before i got rid of it until i made it stableish was a is device coming closer or is it going check but never worked out how to do it right.
thanks for the help in advanced
rule "Jess's iPhone Home"
when
Item icloud_device_30e37292_69c0eba5_location changed or
Item network_pingdevice_192_168_0_37_online changed from ON
then
val PointType phone_location = icloud_device_30e37292_69c0eba5_location.state as PointType
var int distance = phone_location.distanceFrom(home_location).intValue()
val Number epoch = (icloud_device_30e37292_69c0eba5_locationLastUpdate.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
val timenow = now.millis
//************************************************************************
val Number distancesec = distance/30
if (network_pingdevice_192_168_0_37_online.state != ON){
if ((timenow - epoch) > 15000){
logInfo("FILE", "time is over 15s (jess)")
createTimer(now.plusSeconds(8))[
logInfo("FILE", "over 15s refresh (jess)")
icloud_device_30e37292_69c0eba5_location.sendCommand("REFRESH")
]
}
if ((timenow - epoch) < 15000){
logInfo("FILE", "time is under 15s (jess)")
if (distance >500 ) {
logInfo("FILE", "timer started for jess for " + distancesec /60 + " minutes")
//**************************************************************************************************
createTimer(now.plusSeconds(distancesec.intValue))[
logInfo("FILE", "distance refresh (jess)")
icloud_device_30e37292_69c0eba5_location.sendCommand("REFRESH")
]
}
else if ((distance > 100) && (distance < 500) && (network_pingdevice_192_168_0_37_online.state != ON)) {
logInfo("FILE", "Jess's iPhone is opening garage.")
dmx_dimmer_c60bb925_brightness.sendCommand("90")
}
else if ( distance < 100) {
logInfo("FILE", "Jess's iPhone is at Home.")
}
logInfo("FILE", "(jess) current distance " + distance)
}
}
end
rule "Jess's iphone in refresh"
when
Item icloud_device_30e37292_69c0eba5_location received command "REFRESH"
then
val PointType phone_location = icloud_device_30e37292_69c0eba5_location.state as PointType
logInfo("FILE", "REFRESH received starting timer for 30secs (jess)")
createTimer(now.plusSeconds(30))[
if (icloud_device_30e37292_69c0eba5_location.state as PointType == phone_location){
logInfo("FILE","timeout refresh (jess)")
icloud_device_30e37292_69c0eba5_location.sendCommand("REFRESH")
}
]
end