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!


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

rule “sunrise"
Item CurrentTime received update
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”)
logInfo(“No sunrise…waiting!”, t1)

After changing your quotation marks from




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"
	Channel 'astro:sun:local:set#event' triggered START
	logInfo("blinds", "Hall blind close triggered")
    sendCommand(hallblindTrigger, OFF)

To expand on chimera’s suggestion:

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