DateTime Protocol

evasmolders edited this page Jan 15, 2017 · 4 revisions
Clone this wiki locally

The DateTime protocol can be used to display date/time on the console or you can use certain DateTime events to trigger rules.

The protocol also includes a sunrise/sunset calculation which needs your locations longitude, latitude and timezone to perform it's calculations. Longitude and latitude are entered as decimals and the timezone has to be the Java identifier eg. Europe/Berlin.

The following commands are available in the moment:

  • date (returns a date/time as string depending on the given formatter)
  • sunrise (returns the sunrise time as string depending on the given formatter)
  • sunset (returns the sunset time as string depending on the given formatter)
  • minutesUntilSunrise (returns an integer with the minutes until sunrise)
  • minutesUntilSunset (returns an integer with the minutes until sunset)
  • isDay (returns a boolean string)
  • isNight (returns a boolean string)

OpenRemote Online Designer

Now, let's create some screen in OpenRemote Designer. OpenRemote Designer already supports Date/Time protocol, so all you need is account to log into it.

Our task will be to print the date on a page and also if it's day or night.

Create new Device

In "Building Modeler", create new device New>New Device

DateTime Protocol - 1

Create commands

Still in "Building Modeler", select device that was created in step 1 and click on New>New Command Specify name and select "DateTime Protocol" as protocol.

DateTime Protocol - 2

DateTime specific settings:

  • Latitude - The latitude of your location as decimal value
  • Longitude - The longitude of your location as deciaml value
  • Timezone - The Java identifier for your timezone. This is needed todo time corrections since the sunrise/sunset calculations are based on UTC-0
  • What should be calculated - The identifier of the function. This must be one off the commands wich are mentioned above
  • Formatting - A Java formatter string to convert the date/time into a string.

Here you can find some examples and the valid identifiers for the formatter string:

Since we are going to configure second command that will calculate day or night, click on "Submit and continue". This will store our current settings, but preserver filled-in values. We can then easily update settings without the need to re-enter all the values again.

DateTime Protocol - 3

In this command, we need to provide longitude and latitude, since the "isDay" command is based on sunrise/sunset calculation. We also need the timezone for time corrections. Since we are not going to add any other command, click on "Submit".

The DateTime protocol has been slightly improved in the OpenRemote Designer, starting with version 5.2

The UI has been reviewed to shorten labels and add detailed information as additional text revealed when you hover above the different fields.

Supported commands are now selected from a dropdown box, so users don't need to type them anymore.

A new parameter has been added: "Polling interval". It defines the rate at which the resulting value is updated, the default value being 1 minute. Using this last parameter requires Controller Pro version 1.0.11 or above.

DateTime Protocol - DateTime_Command

Create sensors

Now we will create the sensors, that will use previously created commands to access values of our DateTime protocol.

Click on "New>New Sensor"

DateTime Protocol - 4

We will call our first sensor "DisplayDate Sensor". Select command "Display Date" and choose type "custom". You don't need to specify any custom state items. This way the string that comes from the command is displayed as is.

When all values are entered, click on "Submit" to save the sensor.

Again, click on "New>New Sensor" to create the sensor for our "isDay" command.

DateTime Protocol - 5

Name of this sensor will be "DateTime isDay Sensor". We use the "DateTime isDay" command for this sensor. Type is custom again and no items.

Submit this dialog to save the sensor. We are done in the Building Modeler and have created all commands and sensors.

DateTime Protocol - 6

Use sensor in UI Designer

To display our sensor values in a panel, you have to create a label for each and select the appropriate sensor. This example also includes 2 extra labels two describe our fields.

DateTime Protocol - 7


Here you can see the result of our work.

DateTime Protocol - 8