I've been using my Cx since mid 2018. I'm not a programmer by trade so everything I write I rely on examples and help from the community and ST classic documentation.
Being a noob at writing Hubitat App and Drivers (notice "App" is singular) I have a noob outlook on all things groovy/Hubitat. In addition, the coding I did learn was pre Object Oriented Programming, so I needed a shift in mind set.
What I learn by doing, reading and following I create notes for. By necessity these notes are more detailed that what is currently available. See an example below, yes I added some embellishment so others could understand it, and there maybe mistakes. However I feel if there was a User wiki I could add this explanation which I feel would be very helpful to the community. At least until the official documentation gets updating, or some writes a book " Advanced Hubitat for Dummy's"
Would others like such a resource? Is it practical for the Hubitat folks?
For instance I learned about creating a schedule
V1.0 (if found useful I expect there will be changes/corrections)
Goal:
I wanted to verify my automated valve was still communicating with Hubitat. I wanted to check this once a day. I found the schedule function was a good choice.
Schedule simply creates a kind of alarm in the Hubitat database. Each time the "alarm" goes off the referenced method will be run. In this example the schedule will run my "connectCheck" method.
The code to create a schedule is simply one line:
def updated(){
schedule("0 0 6 * * ?", connectCheck) // once every day at 6 AM
log.info "schedule created for checking valve"
}
The schedule command i.e. schedule("0 0 6 * * ?", connectCheck) needs to be run only once. It can be put anywhere you like as long as it runs to set the "alarms"
To remove a schedule simply use:
unschedule(connectCheck)
Method to be run in this example:
void connectCheck(){
// updates lastactivity so App "Device Activity Check App" will know its still communicating.
sendToDevice(zwave.basicV1.basicGet().format())
}
syntax:
schedule ( time as a cron constant, method to be run)
-
time as a cron constant. cron is a carryover timing format form UNIX. It's rough format is:
seconds (space) minutes (space) hours ....etc
There are a number of web pages that will convert whatever timing you wish to a cron string. Just google Cron String or cron timing etc. -
method to be run simply the name of the method that you want to run at the cron intervals.