Page 1 of 1
Or Or Or optimized?
Posted: Tuesday 29 October 2019 19:54
by Solderbro
Hello,
trying to optimize and shorten programs here, but sometimes i'm out of ideas. Is it possible to shorten this script that raise up heating at 3 points in the week?
if heizpause == 'Heizen' then
print('Modus Bad aktualisieren')
if (t.matchesRule('at 04:45 on mon, tue, wed, thu, fri') or ('at 16:05 on mon, tue, wed, thu, fri') or ('at 06:30 on sat, sun')) then
spirit.updateMode('Heat')
end
end
Re: Or Or Or optimized?
Posted: Tuesday 29 October 2019 20:09
by Hydci
Hello I think you can do like that, maybe someone will have another idea
Code: Select all
return {
on =
{
timer = { 'at 04:45 on mon, tue, wed, thu, fri','at 16:05 on mon, tue, wed, thu, fri','at 06:30 on sat, sun'},
devices = {'heizpause'},
},
execute = function( dz, item)
if heizpause == 'Heizen' then
print('Modus Bad aktualisieren')
end
if item.isTimer then
spirit.updateMode('Heat')
end
end
}
Re: Or Or Or optimized? [Solved]
Posted: Wednesday 30 October 2019 20:30
by Solderbro
Uhm i just realized that such OR statements won't work at all. It seems not to be possible to optimize that, so every statement requires single elseif statement to run.
This one updates at 09:05 and 21:30.
if (t.matchesRule('at 09:05')) then
spirit.updateMode('Heat Eco')
elseif (t.matchesRule('at 21:30')) then
spirit.updateMode('Heat Eco')
end
print('Bad Sparmodus gesetzt')
end
While this one never update the mode, don't know if the line is malformed at all.
if heizpause == 'Heizen' then
print('Modus Kueche aktualisieren')
if (t.matchesRule('at 04:50 on mon, tue, wed, thu, fri') or ('at 15:15 on mon, tue, wed, thu, fri') or ('at 07:30 on sat, sun')) then
spirit.updateMode('Heat')
print('Küche Heizmodus gesetzt')
end
Conclusion: Never use Or statements?
Re: Or Or Or optimized?
Posted: Wednesday 30 October 2019 20:40
by waaren
Solderbro wrote: ↑Wednesday 30 October 2019 20:30
Conclusion: Never use or statements?
or... if you like short code:
Code: Select all
t.matchesRule = tm
if tm('at 04:50 on mon, tue, wed, thu, fri') or tm('at 15:15 on mon, tue, wed, thu, fri') or tm('at 07:30 on sat, sun') then