Skip to content
PekawayPekaway
Time and timer

Time and timer

In this tutorial we will look at how we can switch relays automatically and how we can get the correct time into our system.

Time

The easiest way to get the time is of course if the system has an existing Internet connection. A public NTP (Network Time Protocol) server is then automatically queried and the operating system can keep the time synchronized. The prerequisite for this is that "Network Time Sync" is active.

This switch simply turns the Debian service "systemd-timesyncd.service" on or off. Status Timesync checks once when Node-RED is restarted whether the service is actively running in the background.

Fun fact: The function "client time in toolbar" was previously called "system time in toolbar". However, since there is some JavaScript behind it that is loaded in the browser of the end device, the time of the browser or the end device is ultimately displayed there.

If the system does not have an active internet connection there are several ways to set the correct time.

Option 1 Touch display:

A real time clock (RTC) is built into the touch display. As long as the touch display is connected, we get the time from there. However, this becomes difficult if you are in a different time zone, as the RTC does not get that.

Option 2 Console:

A simple command in the following format is enough to set the current time via the console: "sudo date -s 'yyyy-mm-dd hh:mm:ss'"

Option 3 HTTP API:

The new VanPi OS version (v1.1.0) provides an HTTP endpoint to set the time. To do this, send a PUT request to <RPI-IP>:1880/attime with the parameters date, time and gmt in a specific format:

/attime?date=yy/mm/dd&time=hh:mm:ss&gmt=+04

(Headers: "Content-Type: text/html; charset=utf-8")

date and time are self-explanatory, the parameter after gmt stands for the time zone's deviation from Greenwich Mean Time. 15 minute intervals are always specified, and values ​​from -48 to +48 can be set here. +04 stands for 4x15min, i.e. one hour. Finally, the command mentioned in option 2 is then executed in the background.

We have implemented option 3 so that the time can be set later via the smartphone app. The IoT bridge will query the current time via the cellular network and then send it to the Raspberry.

Please note that as long as Network Time Sync is active and there is an active Internet connection, manually set times will be overwritten very quickly.

timer

One of the most important timer functions is certainly the option to operate the heating on a timer-controlled basis. To do this, we can simply specify in the dashboard when the heating should come on, when it should go off again and on which days of the week this should happen. To activate, simply switch on the "Timer On/Off" switch.

In addition to the heating, it is also possible to control the relays over time. In the Config menu, under the Switches item, there is a button called "Switch Scheduler". You can set your times there.

The first column "Auto Turn Off" is independent of the system time. Each time the corresponding relay is switched, the selected time value is waited for and the corresponding relay is switched off.

In addition, we find similar setting options as with the heating; relays can be switched on or off at a specific time, again depending on the system time.

Of course, the whole thing also works with the dimmers and WiFi relays, so you could, for example, have the dimmers slowly turn down over a certain period of time. Or turn them up when you get up.

While the relays and WiFi relays only have the option of switching them on or off, we have implemented a free text field for the dimmers in which values ​​from 0-100 can be entered in order to achieve the desired brightness. (true or false correspond to the values ​​100 or 0 respectively)

///Addendum

The pins for the standard RPI RealTimeClock (ds3231) are already provided on the relay board. (J9) You can simply plug it in and have the time offline even without a display.

You can find a tutorial on how to set it up here:

https://www.raspberry-pi-geek.de/spenden/rpg/2015/03/echtzeituhr-modul-ds3231-sorge-fuer-genaue-zeitbaren/2/

We try to set the necessary settings in the normal image, then you only have to plug/solder the clock on.

Leave a comment

Your email address will not be published..

more tutorials

Open Source needs support

become Patron now

More projects, more tutorials and more supported devices. Our community is growing and would appreciate your support. So become a patron now to always receive the latest content and support the VAN PI project at the same time.

Become a Patron
Cart 0

Your cart is currently empty.

Start Shopping