Syntax error in a textual rule

Hi everyone,
Could anybody help me with my code for a rule, please?
I have created a rule for my cooler which has a PWM controlled pump via Arduino.
The lowest value where the pump works is 40 and the highest is 100.
The idea is to keep the inside temperature arround 22,5°C. If the temperature is 22,5 set the value of the cooler to 40. If it is lower, set the cooler to 0(stop). If the temperature is higher then 22,5. increase the cooler value by 5. At the same time it is comparing the current temperature with the previous.
If the previous is higher then the current => decrease the cooler value by 5. If the previous is lower then the current temperature => increase the cooler value by 5.
This is my syntax

rule "Zem.Vym.- Rýchlosť čerpadla zemného výmenníka leto" 
when
    Item lowestTemperature changed
then
    // Get the previous temperature
    var previousTemperature = lowestTemperature.lastChangedBy.state

    // If the temperature is 22.5, set the cooler to 40
    if (lowestTemperature.state == 22.5) 
    {
        MQTTZemnyVymennikCerpadlo_ZemnyVymennikArduino.postUpdate(40)
    }
    // If the temperature is higher than 22.5, adjust the cooler value
    else if (lowestTemperature.state > 22.5) 
    {
        // Calculate the cooler value based on the current temperature
        var coolerValue = (lowestTemperature.state - 22.5) * 5 + 40

        // If the previous temperature was higher, decrease the cooler value by 5
        // If the previous temperature was lower, increase the cooler value by 5
        coolerValue = previousTemperature > lowestTemperature.state ? max(coolerValue - 5, 40) : min(coolerValue + 5, 100)
        // Update the cooler value
        MQTTZemnyVymennikCerpadlo_ZemnyVymennikArduino.postUpdate(coolerValue)
    }
    // If the temperature is lower than 22.5, set the cooler to 0
    else 
    {
        MQTTZemnyVymennikCerpadlo_ZemnyVymennikArduino.postUpdate(0) 
    }
end

If I load this code to openhab, I get the following in my log:

2022-12-17 20:06:20.433 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘MQTT.rules’ has errors, therefore ignoring it: [279,69]: no viable alternative at input ‘?’

[279,96]: mismatched input ‘:’ expecting ‘}’

[282,5]: mismatched input ‘}’ expecting ‘end’

Any ideas, please?

It does not like the syntax here, stumbles at the “?”.
Correct syntax for DSL

The errors are gone so far. Many thanks for the hint. We’ll see if everything works fine in summer :slight_smile:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.