When Time CRON x, THEN if problem

I have a logic problem that is likely easy to workaround but after searching for the past day I can’t solve it…

rule "A.Work.AM"
when
Time cron "0 45 02 1/1 * ? *"
then
if (F_A_Work_AM == 1.0) {
Main_Light_DEN.sendCommand(ON))
end

… returns an log entry of “Error during the execution of rule A.Work.AM: An error occurred during the script execution: Cannot assign a value in null context.”

F_A_Work_AM shows a value of 1.0 while I run this…

I want this to run at 0245 but only if F_A_Work_AM is on (value 1.0), else do nothing.

I’ve tried quotes, direct channel entries, etc. I’ve thrown several Hail Mary’s hoping something would work but I’m stuck.

Is there no way to have something fire at a certain time ONLY IF a Flag/Switch is on?

Thanks.

You probably need something like:

if (F_A_Work_AM.state == 1.0)

What item type is F_A_Work_AM? If of type number, the if clause should be

if((F_A_Work_AM.state as DecimalType).intValue == 1)

or

if((F_A_Work_AM.state as DecimalType).floatValue == 1.0)

If of type string, you will have to use

if(F_A_Work_AM.state.toString == "1.0")
1 Like

Thanks!

As it was defined as a number, the first clause worked. I was not familiar with DecimalType but now it makes sense.

Dave