[SOLVED] TimeOfDay used in rule: "The name 'EVENING' cannot be resolved to an item or type"


I created a rule for “TimeOfDay” which is basically the Design Pattern that was posted. I have verified that the item ‘vTimeOfDay’ gets calculated correctly, but when I use it in a rule with my motion sensor, I get the error in the subject line. Here is my rule:

rule "Master bedroom motion sensor ON"
Item Sensor_Motion_GF_BdrmMaster_Presence changed from OFF to ON
logDebug(log_BdrmMaster,"DEBUG: Lights Rules")
logInfo(log_BdrmMaster,"Item 'Sensor_Light_GF_BdrmMaster_Illuminance': "+Sensor_Light_GF_BdrmMaster_Illuminance.state.toString)
logInfo(log_BdrmMaster, "Item 'gLights_GF_BdrmMaster_Bedside': "+gLights_GF_BdrmMaster_Bedside.state.toString)
logInfo(log_BdrmMaster, "Item 'vTimeOfDay': "+vTimeOfDay.state.toString)
if (gLights_GF_BdrmMaster_Bedside.state == OFF && (vTimeOfDay.state !== EVENING || vTimeOfDay.state !== BED))
    logInfo(log_BdrmMaster,"Not dark enough; leaving lights off")
if (motionTimer === null && gLights_GF_BdrmMaster_Bedside == ON)
    logInfo(log_BdrmMaster,"Light was already on")

motionBdrmMaster = true

if (motionTimer === null)
    motionTimer = null
    logInfo(log_BdrmMaster,"Motion detected; lights on")
    motionTimer = null
    logInfo(log_BdrmMaster,"Motion detected; timer deleted")

and here is the log output when I trigger the motion sensor:

2019-05-12 11:23:20.273 [ome.event.ItemCommandEvent] - Item 'Sensor_Motion_GF_BdrmMaster_Presence' received command ON
2019-05-12 11:23:20.290 [nt.ItemStatePredictedEvent] - Sensor_Motion_GF_BdrmMaster_Presence predicted to become ON
2019-05-12 11:23:20.308 [vent.ItemStateChangedEvent] - Sensor_Motion_GF_BdrmMaster_Presence changed from OFF to ON
2019-05-12 11:23:21.482 [INFO ] [marthome.model.script.Master Bedroom] - Item 'Sensor_Light_GF_BdrmMaster_Illuminance': 0.9997697679981565
2019-05-12 11:23:21.487 [INFO ] [marthome.model.script.Master Bedroom] - Item 'gLights_GF_BdrmMaster_Bedside': OFF
2019-05-12 11:23:21.492 [INFO ] [marthome.model.script.Master Bedroom] - Item 'vTimeOfDay': DAY
2019-05-12 11:23:21.498 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Master bedroom motion sensor ON': The name 'EVENING' cannot be resolved to an item or type; line 32, column 77, length 7
2019-05-12 11:23:21.662 [ome.event.ItemCommandEvent] - Item 'Sensor_Motion_GF_BdrmMaster_Presence' received command OFF
2019-05-12 11:23:21.673 [nt.ItemStatePredictedEvent] - Sensor_Motion_GF_BdrmMaster_Presence predicted to become OFF
2019-05-12 11:23:21.686 [vent.ItemStateChangedEvent] - Sensor_Motion_GF_BdrmMaster_Presence changed from ON to OFF

As you can see, the TimeOfDay at the time is “DAY”. The rule should go to to the section that “Not dark enough” then exit, but it just gives the error and does not go further in the rule, so I would suspect that even if I create additional “If” conditions, they would not be triggered.

Your advise and guidance, as always, is greatly appreciated.

EVENING would be a variable or other object. I expect you meant to compare with the string “EVENING” ?

To make the answer of @rossko57 more explicit, change the above into:

if (gLights_GF_BdrmMaster_Bedside.state == OFF && (vTimeOfDay.state !== "EVENING" || vTimeOfDay.state !== "BED"))

If you compare something to OFF, ON, OPEN and so on, you have to keep in mind that those are predefined constants. Normally you would just be comparing a state to a numerical or string value.

I missed using quotes, of course! That did the trick. Thanks! :slight_smile: