Unable to perform correct string comparison


i am trying to create a simple rule: Determine if it is Summer

From the Astro binding i created the following item:

String Season_Name "Season [%s]" (Astro) {channel="astro:sun:home:season#name"}

My rule is pretty simple and for testing gets evaluated every minute:

rule "Summer"
    // every day at 6 am
    // s m h dom m dow y(optional)
    // Time cron "0 0 6 1/1 * ? *" or
    Time cron "0 * * 1/1 * ? *" or
    System started
    logInfo('astro.rules', Season_Name.toString())
    if (Season_Name == 'SUMMER') {
        logInfo('astro.rules', "Es ist Sommer")
    } else {
        logInfo('astro.rules', "Es ist Frühling, Herbst oder Winter")

Today it is summer for sure, but the log yields:

2020-09-01 09:46:35.666 [INFO ] [e.smarthome.model.script.astro.rules] - Season_Name (Type=StringItem, State=SUMMER, Label=Season, Category=null, Groups=[Astro])
2020-09-01 09:46:35.666 [INFO ] [e.smarthome.model.script.astro.rules] - Es ist Frühling, Herbst oder Winter
2020-09-01 09:46:35.668 [ome.event.ItemCommandEvent] - Item 'knx_es_ist_sommer' received command OFF
2020-09-01 09:46:35.669 [nt.ItemStatePredictedEvent] - knx_es_ist_sommer predicted to become OFF

Why doesn’t the string comparison work correctly?

if (Season_Name.state == 'SUMMER') {
1 Like

Try it with:

if (Season_Name.state == 'SUMMER') {
1 Like

Thats it, i tried Season_Name.State before but got an error. Didn’t know its small letters. Thank you!

One more thing, where can i find the syntax highlighting guide for this forum software? (Tried to highlight my code postings but couldn’t find the help page).

Note that the icons shown on that post have disappeared in the forum, but you can still click in the relevant spaces, or wait for the tooltip to appear when you hover over the space.

In general, just use three backticks:

your code here

1 Like

Considering your log showed

I would say you guessed correctly. Ideally the log would show the correct capitalisation! :man_shrugging: