I"m in the process of converting my rules from the Rules DSL to JSR223 usimng jython and have a couplde of things I can’t solve…
Firstly, I’m trying to convert this rule but can’t work out how to get the day of the week
ule "Packed Lunch Reminder"
when
Time cron "0 0 22 * * ? *"
then
var Number DayOfWeek = now.getDayOfWeek
if (DayOfWeek == 2) {
ECHOFRONTROOM_TTS.sendCommand("Good evening, don't forget that Joseph has packed lunch tomorrow")
}
end
The second thing is how to print a item state or variable value in a log message?
Joda is deprecated, but it won’t be removed from OH for a while. And you can always add it as a lib when using scripted automation. But if you prefer not to use Joda, just use Python…
from core.rules import rule
from core.triggers import when
@rule("Packed Lunch Reminder")
@when("Time cron 0 0 22 * * ? *")
def packed_lunch_reminder(event):
from datetime import date
day_of_week = date.today().weekday()
if day_of_week == 1:# Monday is 0
events.sendCommand("ECHOFRONTROOM_TTS", "Good evening, don't forget that Joseph has packed lunch tomorrow")