rule Radio61
when
Item Radio_6102 received update
then
time_change_61.postUpdate( Radio_6102.state.toString + " dB @ " + now.toString(“HH:mm”) +" on "+ now.toString(“dd/MM/yyyy”))
end
=====================================================
rule “Check Time”
when
Time cron “18 * * * * ?”
then
var Number HF = now.getHourOfDay()
var Number MF = now.getMinuteOfHour()
TimeofDayMinutes.sendCommand (HF*60+MF)
My scenario is a bit different than this thread is talking about.
I’ve been getting these on every clean startup of OH since I started working with OH (2.3 and 2.4).
NOW does work but sometimes, I have to push the rules file again after it starts up. The bottom line it’s a timing issue.
Is there a more elegant way to catch the issue on startup to have it try to re-initialize local rule variables tied to NOW when this happens below? It’s more of a nuisances remembering I have to re-push the rule file again.
2019-08-22 10:14:13.842 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'default.rules'
2019-08-22 10:14:27.855 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currMonth' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.getMonthOfYear': The name 'now' cannot be resolved to an item or type; line 93, column 28, length 3
2019-08-22 10:14:27.858 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currDay' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.getDayOfMonth': The name 'now' cannot be resolved to an item or type; line 94, column 27, length 3
2019-08-22 10:14:27.860 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currDayofWeek' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.getDayOfWeek': The name 'now' cannot be resolved to an item or type; line 95, column 31, length 3
2019-08-22 10:14:27.871 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currHourVariable' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.getHourOfDay': The name 'now' cannot be resolved to an item or type; line 96, column 33, length 3
2019-08-22 10:14:27.880 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currMonthString' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>::format(<XStringLiteralImpl>,<XFeatureCallImplCustom>)': The name 'String' cannot be resolved to an item or type; line 98, column 34, length 6
2019-08-22 10:14:27.886 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'currDayString' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>::format(<XStringLiteralImpl>,<XFeatureCallImplCustom>)': The name 'String' cannot be resolved to an item or type; line 99, column 33, length 6
2019-08-22 10:14:27.889 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'Cal_Date0' on rule file 'default.rules' cannot be initialized with value 'now': The name 'now' cannot be resolved to an item or type; line 102, column 29, length 3
2019-08-22 10:14:27.891 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'Cal_Date1' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.plusDays(<XNumberLiteralImpl>)': The name 'now' cannot be resolved to an item or type; line 103, column 29, length 3
2019-08-22 10:14:27.900 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'Cal_Date2' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.plusDays(<XNumberLiteralImpl>)': The name 'now' cannot be resolved to an item or type; line 104, column 29, length 3
2019-08-22 10:14:27.908 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'Cal_Date3' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.plusDays(<XNumberLiteralImpl>)': The name 'now' cannot be resolved to an item or type; line 105, column 29, length 3
2019-08-22 10:14:27.920 [WARN ] [me.internal.engine.RuleContextHelper] - Variable 'Cal_Date4' on rule file 'default.rules' cannot be initialized with value '<XFeatureCallImplCustom>.plusDays(<XNumberLiteralImpl>)': The name 'now' cannot be resolved to an item or type; line 106, column 29, length 3
Correct and I do have that delay below. These NOW errors in the Starting Rule starts even before it starts processing the actually System Started rule. It’s basically once the rule file is loaded, it happens immediately since the VAR’s are sitting at the top before the System Started rule gets hit.
Thread::sleep(20 * 5000) // let persistance finish restoring
Ah. You can’t use functions outside a rule. Instead, you have to use a rule to update the var.
jwiseman
(Mr. Wiseman (OH 4.2 Snapshot on Pi4))
13
So I just remove the functional stuff from those variables like this?
var Number currMonth
var Number currDay
var Number currDayofWeek
var Number currHourVariable
var String currMonthString // Used for 2 digit Month
var String currDayString // Used for 2 digit Day
var String TodaysDateTime_String
var DateTime Cal_Date0
var DateTime Cal_Date1
var DateTime Cal_Date2
var DateTime Cal_Date3
var DateTime Cal_Date4
I’m assuming setting NULL and basic strings are OK or am I wrong?
var String HIKSwitchFrontDoor = 'N' // Camera motion switch to slow down rule
var String HIKSwitchGarageDoor = 'N' // Camera motion switch to slow down rule
var HSBType Blacklight = ("63,3,0") // Black - catch all
var String DummyImageURL = "http://192.168.0.230:8080/static/images/noimage.jpg"
var String DummyTrack = "Nothing Queued Up"
Assigning functions to globals is generally pointless, as they get evaluated once at load time only. You’d usuaĺly be more interested in e.g. “now” at rule execution time, which might be days later.
jwiseman
(Mr. Wiseman (OH 4.2 Snapshot on Pi4))
15
I do have that logic in place everywhere; I check to see if those variables aren’t null/NULL then I update them before using them everywhere in my RULE file.
Example of it
if (systemStarted.state != ON && currHourVariable !== null && currHourVariable != NULL && currHourVariable != UNDEF && currHourVariable != '' && gInternet.state == ON) {
currHourVariable = now.getHourOfDay
currHour.postUpdate(currHourVariable)
currDayofWeek = now.getDayOfWeek
currMonth = now.getMonthOfYear
currDay = now.getDayOfMonth
currMonthString = (String::format("%02d", currMonth)) // Used for 2 digit Month TRIGGERED by Rule
currDayString = (String::format("%02d", currDay)) // Used for 2 digit Day TRIGGERED by Rule
}