[SOLVED] Trying to nest logic within Expression
-
I'm working on moving from Reactor to MSR, but I'm having a hard time converting this expression.
(For context, this expression is a part of my thermostat automation, and is designed to convert the outdoor temperature into a standard value from 1-6, which in turn tells the thermostat if we should be heating or cooling and to what degree)
Within Vera, this is my expression that's working perfectly:
if(TodayAvg<=33, 1, if(TodayAvg>33 and TodayAvg<=55, 2, if(TodayAvg>55 and TodayAvg<=65, 3, if(TodayAvg>65 and TodayAvg<=74, 4, if(TodayAvg>74 and TodayAvg<=80, 5, if(TodayAvg>80, 6, null))))))
I've successfully converted the first piece of that expression within MSR, with both of these configurations running successfully:
if TodayAvg <= 33 then 1 endif
TodayAvg <= 33 ? 1 : null
But as soon as I try to nest the logic, it breaks. (This code is not successful)
if TodayAvg <= 33 then 1 else if TodayAvg > 33 and TodayAvg <= 55 then 2 endif
Would love some advice on how to successfully convert this into a format that MSR accepts.
Thanks all!
-
Off the top of my head, without trying it, the
else if
is starting anotherif
block, so you need:if TodayAvg <= 33 then 1 else if TodayAvg > 33 and TodayAvg <= 55 then 2 endif endif
If you use some spacing and newlines, it starts to become more clear:
if TodayAvg <= 33 then 1 else if TodayAvg > 33 and TodayAvg <= 55 then 2 endif endif
-
I'm working on moving from Reactor to MSR, but I'm having a hard time converting this expression.
(For context, this expression is a part of my thermostat automation, and is designed to convert the outdoor temperature into a standard value from 1-6, which in turn tells the thermostat if we should be heating or cooling and to what degree)
Within Vera, this is my expression that's working perfectly:
if(TodayAvg<=33, 1, if(TodayAvg>33 and TodayAvg<=55, 2, if(TodayAvg>55 and TodayAvg<=65, 3, if(TodayAvg>65 and TodayAvg<=74, 4, if(TodayAvg>74 and TodayAvg<=80, 5, if(TodayAvg>80, 6, null))))))
I've successfully converted the first piece of that expression within MSR, with both of these configurations running successfully:
if TodayAvg <= 33 then 1 endif
TodayAvg <= 33 ? 1 : null
But as soon as I try to nest the logic, it breaks. (This code is not successful)
if TodayAvg <= 33 then 1 else if TodayAvg > 33 and TodayAvg <= 55 then 2 endif
Would love some advice on how to successfully convert this into a format that MSR accepts.
Thanks all!
@apocalypsehobby you could try something like this:
TodayAvg <= 33 ? 1 : (TodayAvg > 33 && TodayAvg <= 55) ? 2 : (and so on...)
-
@toggledbits & @tunnus thank you both, your suggestions both worked beautifully. I especially like the spacing & newlines... much clearer
Pat, I will say on a side note, I thought the transition from Vera/Reactor to HA/MSR would take FOREVER but it's been moving along pretty quickly so far, partially due to the Import tool. Thanks for making that. I still have a long way to go, but I'm making good progress.
-
Coming to a future version:
case when TodayAvg <= 33: 1 when TodayAvg <= 55: 2 else 3 end
-
Coming to a future version:
case when TodayAvg <= 33: 1 when TodayAvg <= 55: 2 else 3 end
@toggledbits I liked this!
Already looking for ideas for use, and looking at the rules that I have today for how to simplify.
-
T toggledbits locked this topic on