What is wrong with my syntax?

I have a LED-lamp and the goal is to make it switch color depending on the outside temperature.
The color switching part works in Rule machine if I just do a simple rule that says change color when turning on the switch etc.

I'm guessing my IF syntax is wrong?

Any ideas? :slight_smile:

Looks like you're missing some ENDIFs. It's hard to tell what you want, I would suggest starting out with just one IF and when it works build from there.

Change the all fo the IFs after the first one to ELSE-IF instead. Then put an END-IF at the end.

Ahhh. Needed END-IF after every Set color.
Thank you. Working now!

You can also simplify your logic here...

For instance, if the first thing you check is temp <=4.99, on the next "ELSE-IF" you don't have to check that it is above that value because it has already been established (by failing the first "IF") that the temperature is above 4.99.

In other words, get rid of the first check all "AND"s in the "IF" statements.

I'm not sure how you got the ELSE there. Every IF has and END-IF so something looks malformed. Assuming temperature can be below 0, I'd structure the rule like this.

Required Expression
Temperature of Utetemperatur >= 0.0

Actions to Run
IF Temperature of Utetemperatur < 5.0 THEN
    Set color: WLED Green Level: 90
ELSE-IF Temperature of Utetemperatur < 10.0 THEN
    Set color: WLED Yellow Level: 90
ELSE-IF Temperature of Utetemperatur < 15.0 THEN
    Set color: WLED Orange Level: 90
ELSE-IF Temperature of Utetemperatur < 20.0 THEN
    Set color: WLED Red Level: 90
    Set color: WLED Blue Level: 90

^^^do this^^^
@pseudonym has fixed it perfectly

Additionally, consider changing the trigger to:

  • Temperature of utetemperatur (changed)

This way your rule triggers only if the temp has changed. It may alleviate a little load off your hub in the case that the temperature has not changed in several minutes. Why poll every minute even at times when there is nothing new to report?

1 Like

Thank you! I did try a lot of stuff and my main problem was that nothing happened so the rule got uglier and uglier over time. Now I can adjust the rule and make it pretty.

I will update the rule to support freezing temperatures. It is actually important for this project. I designed and 3D printed a "Christmas lamp" for my girlfriend and the temperature is often below zero where I live :slight_smile: