Klover Triggers - Part 2: Smart Parking Example with Scheduled Triggers

August 15, 2017

In this article, we will learn more about using Klover’s Scheduled Triggers by implementing a Smart Parking “Surge Pricing” solution using them. It is the second in a multi-part series describing how to use Klover Triggers to implement user-defined rules and execute Actions. If you missed the initial article, you can come up to speed on basic Trigger concepts, before diving into Scheduled Triggers here: Klover Triggers - An Introduction

Concepts in the article include:

- Jobs, Schedules (e.g., Scheduled Triggers), and Actions
- Creating a Job with multiple Scheduled Triggers that run at exact date/times
- Configuring an Action to invoke a pre-defined Process from the Scheduled Triggers
- Property binding of values from a Scheduled Trigger to Process Instance variables.
- Basic coverage of RestServiceTasks, JavaScriptTasks and Things APIs

Scheduled Trigger

We will be using Scheduled Triggers today. Scheduled Triggers provide extensibility within the Klover Smart Transportation Platform by allowing non-technical, business users to define business logic in the form of Actions that execute at a specific date/time or interval, similar to Linux cron tabs. Klover provides a user-friendly interface to define and manage your Scheduled Triggers, because who wants to write expressions like this all day!?

30 08 10 06 * /home/jason/executeCoolKloverStuff

A good time to use a Scheduled Trigger is when you want to perform the same logic at each interval. For instance, with Klover you can create a Scheduled Trigger to run every 2 minutes with an Action that will update a dynamic message sign (DMS) with the latest trip travel time for a route.

Another time to use Scheduled Triggers is when you want to perform some logic at an exact time in the future. Today, we will focus on this type of Scheduled Trigger. In our fictional example, a Smart City manages parking prices based on demand. When the local NFL team has a home game, parking ramps should implement “Surge Pricing” to collect higher fees for high-demand parking lots around the stadium. Each gameday, this involves telling drivers the current price and ensuring the parking management software charges the correct rate.

We’ve already designed our BPMN 2.0 (Business Process Modeling Notation) process flow to execute when the Scheduled Trigger runs (Figure 1). It is called “Implement Surge Pricing” and it takes a single process variable called “price” that is required to run the process instance.

Surge Price Process Diagram
Figure 1: Process to Implement Surge Pricing

As you can see in Figure 2, the diagram has two steps. The first step in the flow is a RestServiceTask. RestServiceTasks can be configured in Klover to call any REST API. The step “Set Pricing for Event” uses REST to inform a 3rd Party parking management system of the new price to charge for the game.

The second step in the flow is a JavaScriptTask that uses the price to update DMSes in the parking lots with a new message. When the Things.save() API is called, Klover updates the new message on the DMSes in the parking lots. Our Things API shelters you from the low-level, IoT communications protocols required to make this happen. All you have to do is call save!

Setting Thing Messages With JavaScriptTask
Figure 2: JavaScriptTask to Update Pricing on all Signs

Working with the Job Scheduler

Our "Implement Surge Pricing" process needs to be started for each NFL home game, so we need to create a Job with a Scheduled Trigger per game. Let’s see how to create our Surge Pricing Job and Scheduled Triggers.

Add a Job

Under Manage > Job Scheduler, you can click the FAB (+) and enter a new Job.  We will give it a Job Key called “price” with datatype of “Number”. This will hold the price we want to have set each time the job is triggered. Each Scheduled Trigger could set a different value for the Job Key "price" when it runs, but for our purposes it will always be the same.

We also ensure the Job is “Enabled = True”. You can toggle “Enabled = False” anytime you want to pause a Job. This is a handy way to stop it from running, while keeping it around to easily re-start it again later. You could always delete it, but then you'd have to re-create it and all of it's schedules again. Depending on the Job, that may be a lot of work.

Define the Job for the Scheduled Triggers
Figure 3: Define the Job for the Scheduled Triggers

Define the Schedules for the Job

Next, we will define the Job's Scheduled Triggers that will run at set times. A Job can have one or more Scheduled Triggers. By clicking on the Schedules tab (Figure 4), we are presented with a form where we can enter a Schedule name, how often it will repeat, when to start and stop running. Imagine you have the NFL home game schedule for your team in front of you. At this point, you will follow the NFL home game schedule and enter each home game as a different schedule that will fire only once. Since we defined a Job Key called “price”, it shows up in the Schedule UI for us to enter a value. We enter $15.00 for this, meaning parking will be $15.00 / hour during the game.

Enter Job Schedule
Figure 4: Enter a Schedule and Set the Surge Price for the Game

After entering two weeks from the NFL home game schedule, we see the Schedules starting to list under the Schedules tab (Figure 5). Each home game would be entered in a similar way to execute the Surge Pricing logic for each game.

List Schedules
Figure 5: List of Scheduled Triggers

Define an Action

Last but not least, we will define an Action that will be executed each time a Scheduled Trigger is fired (Figure 6). We click on Actions tab for the Job, then Add Action button, and choose a Process Action. We intend to invoke the “Implement Surge Pricing” process flow that was pre-defined for us. Each process can have zero to many process variables. If you remember, there was a process variable called "price" in our flow. When the process flow is chosen, the UI will show the process variables that are required to run the process flow. Klover’s property binding makes it easy to map the Job Key “price” value to the process variable “price”. After we do this, each time the Scheduled Trigger runs, it will pass a value of $15.00 into the “Implement Surge Pricing” process.

Add ProcessAction To Job
Figure 6: Adding the ProcessAction

You can execute multiple Actions each time a Scheduled Trigger is fired. For instance, instead of calling the two step process flow, we could have easily created two Actions instead - one JavaScriptAction to set the price in the 3rd Party parking management software and another JavaScriptAction to update the signs. This allows for quick prototyping and ease of use for minor Actions like sending a quick email or SMS. However, process flows help users to visualize the logic step-by-step and they are recommended for more complex processes where there are multiple steps involved.

Conclusion

There you have it! We used Klover Smart Transportation Platform’s Schedule Triggers feature to implement a Smart Parking solution that allowed parking lots to charge a premium or “Surge Pricing” during NFL home games. In a real world solution don't forget to set parking prices back to normal levels after the game! This can easily be done using the same Scheduled Triggers features to pass in the lower price after each game is over.

Interested in Klover?

We'd love to show you how Klover can be an integral part of your smart transportation solutions. Request a demo or call us at 720-770-8009

Subscribe for updates