[RELEASE] Date Time Parser driver (aka schedule_ur_garbage_cans)

Recent discussion on how to ID what day of the week it is in a rule prompted me to want a rule too... (in my case it was garbage cans).

Having already done some date/time work with my Meteorological Seasons driver, I wrote this driver this AM to allow me to parse values so I can easily control rules. Initially I was putting the variables list from PHP but then I learned that Java comes up... um. short. At least in pre-defined ways. Update - Fixed 0.2.2 I haven't determined the Pattern for the Leap year and DST booleans as well as non leading zero's on a few attributes. However this does cover a pretty wide swath.
I'm going to be moving my house over the next 10 days so responsiveness may be erratic from me. Update - Fixed 0.2.2 I intend to finish some basic icons, have HTML tiles (I use the fine Hubitat Android Dashboard) and I intend to make the schedule updates variable. Currently it is set for every 5 minutes. When those tasks are complete I'll add it to HPM ( Update - Fixed 0.2.2 * now in HPM). Thanks to @sburke781 for the basis I stole this from.

Besides the power this app is showing to me (well. I wrote it so.. yea.) I've just added an Even and Odd Week variable. so Folks scheduling garbage can pick ups... Tada! Point your rule and enjoy.
(in latest version, 0.2.3 on HPM)

** yet another update ** so come to learn that boolean values for custom attributes aren't supported in Rules. This is known since...well .. 2020 at least.. regardless - I've converted all booleans to strings and adjusted their names to be a bit more humanistic. Much MUCH thanks to @sburke781 who just is huge as a persona around here!
0.2.4 changed all boolean variables to text strings so comparators work.
0.2.5 Added Even/Odd text string variables for DayOfTheWeekNum.
0.2.6 Added Even/Odd text string variables for DayOfTheYearNum.
0.2.7 Fixed 24HrNoLead showing lead zero. Fixed debug switch check on update text line to log file

Do HPM Repair to get an immediate update to newest version of the driver.

I guess it would help some if I overview the steps -
Follow the link below to Github page. Copy the content.
On your hub, select Drivers Code (under developers).
Click New Driver in the top right.
Paste. Save.
Go to Devices and Add Device (again top right corner).
Select Virtual (under manually)
for Type* start typing Date and Select Date & Time Parser (under User heading)
ASsign device a Name and optionally a Label.
Save Device.
Select Refresh on the Device page and viola.
You can now use 'custom attributes' in rules to pick which variable value you wish to equate etc.

https://raw.githubusercontent.com/jshimota01/hubitat/main/Drivers/datetime_parser/dateTimeParser.groovy

Here is an Image of all Variables now available for use in Rules:

7 Likes

That's cool.

May I suggest a couple additions (that can be made by concatenation, but just cleaner to have it as an attribute):

ComparisonDate: 20220119
ComparisonTime: 1543
ComparisonDateTime: 202201191543

2 Likes

I was happy to see you are using Java's own date/time APIs. In my past professional life, the number of bugs found when people wrote their own date formatting or parsing logic was endless. You should add this to HPM!

People should use Import option. This allows them to update the driver by just clicking Import again (it remembers the URL).

Updated instructions:

On your hub, select Drivers Code (under developers).
Click New Driver in the top right.
Click the Import button (upper right).
Paste the github URL into the input box and click Import:
https://raw.githubusercontent.com/jshimota01/hubitat/main/Drivers/datetime_parser/dateTimeParser.groovy
Click Save

Go to Devices and Add Device (again top right corner).
Select Virtual (under manually)
For Type, start typing Date and Select Date & Time Parser (under User heading)
Assign device a Name and optionally a Label.
Save Device.
Select Refresh on the Device page and viola.

2 Likes

I would also like to (second the) request for the attribute "ComparisonDate".

The only addition I would make (not really... read on... ) is not one of mine and I could have missed it in your notes, but a selection of the time zone would also be useful to an admittedly small audience.

Otherwise, a great improvement on my driver. Removes the need for the user to know what format string they need. That said... :slight_smile:

I think including the format Preference Setting I had in my driver would round this out nicely, providing a formatted complete date value. I started by thinking you should include some nice user-friendly setting that references the attributes you have setup, but in the end it would arrive at a similar format to what Java already expects.... Best to leverage pre-existing work in my opinion....

Will certainly point people in this direction if I am asked. Nice work. No pressure.... Mission accomplished....for me.... :slight_smile:

image

Hi @sburke781 I went back and added your customizable date/time/TZ ... and on further thought it really didn't fit with what I envisioned this for. You already have created that fine tool for date/time so as to make it really nice to create tiles for other TZ's etc. I can see the intertwine but having the user able to affect the timezone makes for confusion as now I need to track the currdate/time as well as the userdefined effect and the 25+ variables... If I was a real programmer....

@hal9000 can you elaborate? I wanted to implement user requests before I start buttoning this, but I'm not clear on these items and how to derive from the date/time.

These formats are useful in comparing times, and the format was known as ComparisonTime in the old VMS operating system.

ComparisonDate is simply string concatenation of YearNum4Dig MonthNum DayofMonNum

ComparisonDateTime is simply string concatenation of YearNum4Dig MonthNum DayofMonNum TimeHour24Num TimeMinNum

Fair point, if it's a reasonable amount of work probably best to leave it until someone who needs it asks for it.

@hal9000 implemented!

1 Like

Released - Date Time Parser.

I was able to come up with simple methods to simulate some variables that I wanted in the Driver.
The driver now give a Boolean for Daylight savings Active, ObservesDST, and gives a detection on leapyear as well with a Boolean.
I straightened out some of the naming i was using, added Suffix for '1st' '2nd' both as an ordinal and as an individual attribute.
I added Comparison values as suggested by @hal9000.
I added the adjustable auto update interval on the refresh rate from 1- 59 minutes.

Because @sburke781 has already created a Date/Time Display driver that is great for making a nice simple tile (VERY useful for creating your OWN date format displays!) or of course the always under appreciated @bptworld Tile Master 2 - I removed all tile function I was considering. Why reinvent the horse?!

So - HPM is now distributing v 0.2.1 Hope it's useful to others in getting their garbage cans out on time! (or the kids schedule concerts, or your lights to change on DST, or if it's AM or PM, or ....)
Please click on image to zoom and see all the variables...

6 Likes

Awesome! Those formats also come in handy for sorting notifications, log entries, etc.

The minutes should be expressed as two digits, though (i.e. with leading zero).

1 Like

hi @hal9000 I create another variable to handle this - minutes with leading zero. should be good!

0.2.2 Released - includes fixes on scheduler, and switch case problem on suffix.

Almost .. all the values in the comparison strings would need leading zero for a string compare to work. That is, 9:06 PM last night would be 202201212106

Not sure what you see missing - my result after setting my system to the time of 9:06p last night is:
image
also - this isn't a string compare but a number... which I is working for me in Rules...

OK, I was looking at the results just a few comments above that showed

comparison

1 Like

all good! thanks for the insights.

1 Like

... and fun with Dashboards!!!!
image

HE Dashboard - with @sburke781 Date Time Display, @bptworld Tile Master 2 and generic tiles:

1 Like

Scooby says 'rutroh...'
So it turns out playing with your date/time settings for testing a date and time driver is a really bad thing!!! For-warned is for-armed. I blew up my WeatherUnderground, Alexa, and Google oauth and cookies! Once they 'expired' or went invalid they didn't just reset themselves - I needed to re-auth and re-obtain! a bit of a pain - watch your logfiles for clues.

Please be careful if you dink with date/time settings folks!

Download the Hubitat app