Hi, what am i missing in this rule? if i compare WtrScheduleDays.contains = “MONDAY” everythink is ok, but i want to compare it to a variable
rule "days"
when
.....
then
var String WtrScheduleDays = ""
if (WtrScheduleMonday.state == ON) { WtrScheduleDays = WtrScheduleDays + "MONDAY,"}
if (WtrScheduleTuesday.state == ON) { WtrScheduleDays = WtrScheduleDays + "TUESDAY,"}
if (WtrScheduleWednesday.state == ON) { WtrScheduleDays = WtrScheduleDays + "WEDNESDAY,"}
if (WtrScheduleThursday.state == ON) { WtrScheduleDays = WtrScheduleDays + "THURSDAY,"}
if (WtrScheduleFriday.state == ON) { WtrScheduleDays = WtrScheduleDays + "FRIDAY,"}
if (WtrScheduleSaturday.state == ON) { WtrScheduleDays = WtrScheduleDays + "SATURDAY,"}
if (WtrScheduleSunday.state == ON) { WtrScheduleDays = WtrScheduleDays + "SUNDAY,"}
var String NowDayofWeek = now.getDayOfWeek()
if (WtrScheduleDays.contains = NowDayofWeek){
}
end
rlkoshak
(Rich Koshak)
September 20, 2022, 2:16pm
2
Where did you come up with that syntax? .contains
is a function call. Functions are passed arguments.
if(WtrSchedudule.contains(NowDayOfWeek){
=
is an assignment. So what your original line said, in English: Assign the value of NowDayofWeek to WtrScheduleDays.contains.
Matze0211
(Matthias)
September 20, 2022, 2:25pm
3
In addition to Rich:
Add a log statement, so that you can see the content of your variable.
What you maybe really want (and your current script seems to be only a workaround) is to know if the item representing current day is switched on our off?
To get an item (and it’s state) based on a variable/string, maybe have a look here:
For a couple years now, I’ve been wanting/looking for a way to construct an item from its name as a string. There are other ways to do this, and the most popular requires the item to be in a group, which can have it’s challenges. I’ll keep this short and SWEET… I finally figured it out, and it is extremely simple!
For OH 2.x, you’ll need this import…
import org.eclipse.smarthome.model.script.ScriptServiceUtil
For OH 3.x, this import instead…
import org.openhab.core.model.script.ScriptService…
thank you both!. This rule is run fron crontab, so it will check the .states of the items when they are needed maybe it’s a workarround but it ok for me and my skills