Hi I believe i have a similar problem to this https://community.openhab.org/t/openhab-rule-java-lang-number-problem/30734/4 but I can’t work out how to fix it I have a rule for presence detection copied from another user. Unfortunately i havent been successful in contacting the original author of the rule script for a solution.
The error I get is
Error during the execution of rule Wifi Detection: java.lang.Number
the rules in use are
rule "Wifi Detection"
when
Time cron "30 * * * * ?"
then
var Number now_ms = now.millis
var Number Person_1_Wifi_LastSeen_Millis = (Person_1_Wifi_LastSeen_Seconds.state as Number) * 1000
var Number Person_2_Wifi_LastSeen_Millis = (Person_2_Wifi_LastSeen_Seconds.state as Number) * 1000
logInfo("Wifi Detection", "Millis since last seen P1: "+(now_ms - Person_1_Wifi_LastSeen_Millis))
logInfo("Wifi Detection", "Millis since last seen P2: "+(now_ms - Person_2_Wifi_LastSeen_Millis))
if ( (now_ms - Person_1_Wifi_LastSeen_Millis) > 4*60*1000 ) {
logInfo("Wifi Detection", "Person_1 not here")
Person_1_Wifi.setState(OFF)
}
if ( (now_ms - Person_2_Wifi_LastSeen_Millis) > 4*60*1000 ) {
logInfo("Wifi Detection", "Person_2 not here")
Person_2_Wifi.setState(OFF)
}
end
rule "Wifi Detection Person_1"
when
Item Person_1_Wifi_LastSeen_Seconds received update
then
var Number now_ms = now.millis
var Number Person_1_Wifi_LastSeen_Millis = (Person_1_Wifi_LastSeen_Seconds.state as Number) * 1000
logInfo("Wifi Detection", "Millis since last seen P1: "+(now_ms - Person_1_Wifi_LastSeen_Millis))
if ( (now_ms - Person_1_Wifi_LastSeen_Millis) < 4*60*1000 ) {
logInfo("Wifi Detection", "Person_1 still here")
Person_1_Wifi.setState(ON)
}
end
rule "Wifi Detection Person_2"
when
Item Person_2_Wifi_LastSeen_Seconds received update
then
var Number now_ms = now.millis
var Number Person_2_Wifi_LastSeen_Millis = (Person_2_Wifi_LastSeen_Seconds.state as Number) * 1000
logInfo("Wifi Detection", "Millis since last seen P2: "+(now_ms - Person_2_Wifi_LastSeen_Millis))
if ( (now_ms - Person_2_Wifi_LastSeen_Millis) < 4*60*1000 ) {
logInfo("Wifi Detection", "Person_2 still here")
Person_2_Wifi.setState(ON)
}
end
rule "Wifi Event Person_1"
when
Item Person_1_Wifi_Event received update
then
if ( Person_1_Wifi_Event.state == ON ) {
logInfo("Wifi Detection", "Person_1 came home (Wifi Event)")
Person_1_Wifi.setState(ON)
}
if ( Person_1_Wifi_Event.state == OFF ) {
logInfo("Wifi Detection", "Person_1 left (Wifi Event)")
Person_1_Wifi.setState(OFF)
}
end
rule "Wifi Event Person_2"
when
Item Person_2_Wifi_Event received update
then
if ( Person_2_Wifi_Event.state == ON ) {
logInfo("Wifi Detection", "Person_2 came home (Wifi Event)")
Person_2_Wifi.setState(ON)
}
if ( Person_2_Wifi_Event.state == OFF ) {
logInfo("Wifi Detection", "Person_2 left (Wifi Event)")
Person_2_Wifi.setState(OFF)
}
end
All my items have a status of NULL, and I understand that they are in uninitialised state but how do I change this if this is the problem.
This is the link for the original authors work.
https://github.com/dersimn/OpenWRT-Presence-Detector-over-MQTT
Thanks in advance
Tim