Compare string variables with equals

Hello everybody,

i’m trying to compare two DateTime string variables. But it seems, that the rules engine doesn’t like the equals compare method.

Can anybody help?

Thanks in advance!

Marek

[ERROR] [.script.engine.ScriptExecutionThread] - Rule ‘sunrise’: An error occurred during the script execution: index=1, size=1

rule “sunrise"
when
Item CurrentTime received update
then
var String t1 = CurrentTime.state.format(”%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM")
var String t2 = SunriseTime.state.format("%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM")
logInfo(“print t1”,t1)
logInfo(“print t2”,t2)
if (t1.equals(t2)){
logInfo(“Start of Sunrise!”)
sendCommand(gEGShutter, UP)
logInfo(“sunrise”, “Shutter EG are UP”)
}
else
{
logInfo(“No sunrise…waiting!”, t1)
}
end

After changing your quotation marks from

“..."

to

"..."

it works.
Didn’t you use the SmartHome-Designer?
You can also use

if (CurrentTime.state.format("%1$tH:%1$tM") == SunriseTime.state.format("%1$tH:%1$tM")) {...

Seems a highly complicated not to mention resource intensive way of doing it. Use Astro binding, here’s my rule for sunset event triggering close of my hall blinds… (using sunset as an example here, because I have my blinds OPEN with a cron event, since I get up at the same time of the morning regardless of when sunrise is!)

rule "Close blinds Weekday Triggered at Sunset"
when
	Channel 'astro:sun:local:set#event' triggered START
then
	logInfo("blinds", "Hall blind close triggered")
    sendCommand(hallblindTrigger, OFF)
end

To expand on chimera’s suggestion:

Using String comparisons on a rule that triggers at least once a second is really really inefficient.