Sorry for the late reply.
I ended having a few more issues with receiving the date/time message from Tasker. I realized I didn’t think about Tasker needing me to decide when I want to send my alarm time to OH. Since my OH server can only be accessed on LAN, this also means Wifi has to be on when my smarthphone sends the message. I don’t think I want to have my Wifi to turn-on automatically, send the message, then turn-off. I am very particular about adding on tasks and services to my phone since I really like its battery life, so the only automation task I am fine with is having it send messages at 3am and at every 6 hours periods This also means I will keep wifi on manually, but I am OK with that. (Until I decide to add vpn functionality that is.)
The next problem was the Tasker message is not really a standard UTC format. I am using the AutoAlarm plugin for Tasker. The plugin extracts the alarm time into variables %month , %day, %year, %hour, %min. Prior to using Tasker, the simple way I was parsing a generic message was by concatenating the datetime variables (%month%day%year%hour%min), then reading the first two values into a variable, then the next two, then the next four, next two, and the last two. However, the main problem was these variables don’t have a fixed number of digits (except for the year). For example, an alarm for 6:04 am would have %hour= 6, and %min =4. I attempted the workaround of making a DateTimeFormatter/DateTimeFormat class to look for this specific format, but ultimately this was unsuccessful.
The next approach was to pass the full message ( %month.%day.%year.%hour.%min ) as a string and parse it to different variables using the String.split() method. That was also bad, after recently learning of another limitation: OH has no primitive String array support. I even attempted using the ArrayList/List/Hash features that may be available, but again I was unsuccessful.
After wasting time and feeling frustrated about being constrained with the intricacies of an Xtend/Java language and the limited native OH toolsets available, I ran into a workaround that can solve both my parsing the received message problem, and the processing of it into the DateTime object. I don’t think it is a very good workaround since alot of code is repeated, but hey it works lol, and I am glad no more time is wasted on this.
Also, I wanted to update that I am no longer interested in having a default alarm time set. I realized that this would not be helpful for days that I have work-off, or for days I am away from home traveling. Perhaps I will have to reconsider extending the rules-file to disable timers for specific day intervals. Nevertheless here is my current fully-working solution.
import java.lang.Integer
import org.openhab.model.script.actions.*
import org.joda.time.*
var Timer thermostatTimer = null
var Timer lightTimerBR = null
var Timer lightTimerLR = null
var Timer MornTimerOff = null
var int iMonthOff
var int iDayOff
var int iYearOff
var int iHourOff
var int iMinOff
var DateTime dtAlarmBias
// Main
rule "Set M-F Morning Routine"
when
Item Str_Alarm_Time changed
then
var String sRaw = Str_Alarm_Time.state.toString
//Hyphen (') stays on cmd1 and cmd5. Python script handles that and trims it.
var String cmd1 = "python@@/home/pi/Documents/Code/OpenHAB/configurations/scripts/DateRaw_1Val.py@@'" + sRaw + "'@@1"
var String cmd2 = "python@@/home/pi/Documents/Code/OpenHAB/configurations/scripts/DateRaw_1Val.py@@'" + sRaw + "'@@2"
var String cmd3 = "python@@/home/pi/Documents/Code/OpenHAB/configurations/scripts/DateRaw_1Val.py@@'" + sRaw + "'@@3"
var String cmd4 = "python@@/home/pi/Documents/Code/OpenHAB/configurations/scripts/DateRaw_1Val.py@@'" + sRaw + "'@@4"
var String cmd5 = "python@@/home/pi/Documents/Code/OpenHAB/configurations/scripts/DateRaw_1Val.py@@'" + sRaw + "'@@5"
logInfo("AlarmTime.Received","HTTP message received. sRaw="+sRaw)
iMonthOff = new Integer(executeCommandLine(cmd1, 2000))
iDayOff = new Integer(executeCommandLine(cmd2, 2000))
iYearOff = new Integer(executeCommandLine(cmd3, 2000))
iHourOff = new Integer(executeCommandLine(cmd4, 2000))
iMinOff = new Integer(executeCommandLine(cmd5, 2000))
var DateTime dtAlarm = new DateTime(iYearOff, iMonthOff, iDayOff, iHourOff, iMinOff)
logInfo("AlarmTime.Received","New wake-up alarm: "+dtAlarm.toString() )
while( dtAlarm.isBeforeNow() )
{
dtAlarm = dtAlarm.plusDays(1)
logInfo("AlarmTime.InPast","Warning: This time is in the past, setting new alarm time: "+dtAlarm.toString() )
}
if(thermostatTimer != null) { thermostatTimer.cancel }
dtAlarmBias = dtAlarm.minusMinutes(bias1)
thermostatTimer = createTimer(dtAlarmBias)
[|
// turn on the thermostat
logInfo("AlarmTime.TS1.Heat","Turning TStat Heat On. Warm-wake up :).")
HVAC_HeatSetPoint.sendCommand("85")
HVAC_HeatSetPoint.sendCommand("85") //send again in cases of error
HVAC_HeatSetPoint.sendCommand("85") //send again in cases of error
HVAC_HeatSetPoint.sendCommand("85") //send again in cases of error
HVAC_Mode.sendCommand("1")
HVAC_Mode.sendCommand("1") //send again in cases of error
HVAC_Mode.sendCommand("1") //send again in cases of error
// reset timer var
thermostatTimer = null
]
if(lightTimerBR != null) { lightTimerBR.cancel }
lightTimerBR = createTimer(dtAlarm)
[|
// turn on the BR lights
logInfo("AlarmTime.TS0BR1","Setting TStat Off + BR Lights On... Now go take a shower :).")
BR.sendCommand("ON")
BR.sendCommand("ON") //in case of low LOS
BR.sendCommand("ON") //in case of low LOS
// turn off TStat (reset set points first)
HVAC_HeatSetPoint.sendCommand("71")
HVAC_HeatSetPoint.sendCommand("71") //send again in cases of error
HVAC_HeatSetPoint.sendCommand("71") //send again in cases of error
TStatAll.sendCommand("OFF")
// reset timer var
lightTimerBR = null
]
if(lightTimerLR != null) { lightTimerLR.cancel }
dtAlarmBias = dtAlarm.plusMinutes(bias2)
lightTimerLR = createTimer(dtAlarmBias)
[|
// turn on the LR lights
logInfo("AlarmTime.LR1","Setting LR Lights On... You are doing well :).")
LR1.sendCommand("ON")
LR1.sendCommand("ON") //in case of low LOS
LR1.sendCommand("ON") //in case of low LOS
// reset timer var
lightTimerLR = null
]
if(MornTimerOff != null) { MornTimerOff.cancel }
dtAlarmBias = dtAlarm.plusMinutes(bias3)
MornTimerOff = createTimer(dtAlarmBias)
[|
// turn all Things off
logInfo("AlarmTime.AllOff", "Turning everything off...")
MasterOff.sendCommand("OFF")
// reset timer var
MornTimerOff = null
logInfo("AlarmTime.End", "Morning routine complete. Now go to work!")
]
end
So the workarounds included calling a python script to essentially perform the string-spltting, one at a time. Then populating each output to a set of integers. The DateTime object can also be created with an integer set of date/time parameters as its arguments, so I went in that direction. If someone has more experience with using the executeCommandlLine(), it seems the escape characters are being added to the month and min values. Currently I let python trim these out, but I would say proper usage is the better solution. I will say however I did borrow this line from another page where the person noted the line worked flawlessly with no escape character issues.
As for other details, I have made some rules that essentially act as master-off switches. These are called via the TStatAll and the MasterOff items. The actions in TStatAll are a subset of MasterOff (since this turn all Things off), but it also turns all lights off, and I didn’t mind the redundancy check.
Tasker was also giving me a problem that the message received was an alarm time that was set for 1 day before the current time. To solve this issue (and to provide some error handling when a message date/time is in the past), I push the the messaged date to the present + 1 day so that it can actually create the timers.
This rules-file, plus all supporting files written to meet my objectives, pretty much cover the fundamental stuff I wanted out of an open-source HA implementation for my 1br apartment. So now its matter of exploring what else people are using OH for, considering investing in more HA devices, and thinking of new ideas for automating stuff at home, which will make me that much more lazy lol, but at least more satisfied with my home, and more energy efficient for that matter.