openHAB Presence Simulation Google Calendar Scheduler

openHAB Presence Simulation Google Calendar Scheduler

Today’s Smart Home Training post deals with the openHAB presence simulation in your Smart Home. It’s time to use the Google Calendar Scheduler binding.  It offers you automatic recordings. You specify which items you want recorded using a specific group. The automatic recording may be used to run a presence simulation later on.  The presence simulation can be activated with a central switch and the recording will be played back.  In turn, you can automatically activate this switch via presence recognition. If you are using your own calendar for recording apart from your time-controlled switching, you really don’t have to worry about anything anymore. Simply great!

openHAB Presence Simulation – Install Google Calendar API

First, you have to create a project in the Google APIs. For this, log into the Google Developer Seite.

The first time you might get the following window to update the terms of service. Mark the checkbox (1) choose an Email option (2) and accept (3).

openHAB-Prescene-Simulation-api

Choose Select a project (1) and in the next window NEW PROJECT (2).

openHAB-Prescene-Simulation-create-project-1

Enter a name for the projekt (1) and click create (2).

openHAB-Prescene-Simulation-create-project-2

Now you need to consent. Choose OAuth-consent screen (1). Enter a a product name (2), scroll down and save .

openHAB-Prescene-Simulation-oauth-consent2

Now click on credentials (1), Create credentials (2) and Choose OAuth (3)

openHAB-Prescene-Simulation-create-credentials-oauth-1

In the folder login credentials click login details to create your login. Choose the entry OAuth-Client-ID.

Smart-Home-openHAB-2-Google-Calendar-OAuth

For the ClientID choose others (1), enter a name (2) and click create (3).

openHAB-Prescene-Simulation-create-credentials-oauth-client-id

You will now receive the client-ID and the client key. Copy both into a text document and save it.

openHAB-Prescene-Simulation-oauth-client-key

Got to the API Library

openHAB-Prescene-Simulation-google-calendar-api

Search for calendar (1) and open the Google Calendar API (2).

openHAB-Prescene-Simulation-google-calendar-api-2

Finally, enable the calendar API in the library.

openHAB-Prescene-Simulation-google-calendar-api-enable

openHAB Presence Simulation – Create a exclusive Google Calendar

You will need to create a Calendar in your Google Calendar that will be used exclusive for the purpose of presence simulation. I will not describe how to do this, because this a straight forward and there are different resources how to set up a calendar. You might use the following video as a guide.

YouTube

By loading the video, you agree to YouTube’s privacy policy.
Learn more

Load video

PGlmcmFtZSB0aXRsZT0iSG93IHRvIGNyZWF0ZSBzaGFyZWQgR29vZ2xlIENhbGVuZGFycyIgd2lkdGg9Ijg0MCIgaGVpZ2h0PSI0NzMiIHNyYz0iaHR0cHM6Ly93d3cueW91dHViZS1ub2Nvb2tpZS5jb20vZW1iZWQvU0xqYjlOWHZNak0/ZmVhdHVyZT1vZW1iZWQiIGZyYW1lYm9yZGVyPSIwIiBhbGxvdz0iYWNjZWxlcm9tZXRlcjsgYXV0b3BsYXk7IGVuY3J5cHRlZC1tZWRpYTsgZ3lyb3Njb3BlOyBwaWN0dXJlLWluLXBpY3R1cmUiIGFsbG93ZnVsbHNjcmVlbj48L2lmcmFtZT4=

openHAB Presence Simulation – Install Google Calendar Scheduler Binding

Prerequisite for further implementation is the Installation of openHAB 2. After the installation call up the Paper UI. If your do not know basic stuff about openHAB 2, I recommend enrolling in my openHAB Smarthome Training. If you already familiar with openHAB 2, go on.

Choose addons (1), persistence (2) and click install for the Google Calendar Presence Simulator (3).

Smart-Home-openHAB-2-Google-Calendar-Presence-Simulator

Now choose Misc (2) and install the Google Calendar Scheduler (3).

Smart-Home-openHAB-2-Google-Calendar-Scheduler

 

Open VS Code now. If you don’t have any idea of how to use it, read the post openHAB 2 VS Code.

openHAB Presence Simulation – Configure Google Calendar Scheduler Binding

Open the folder services (1). Following that, open gcal-persistence.cfg (3). Under calendar_name enter the calendar for the recording. This is your calendar you have created using Google Calendar WebApp. Everything else is optional. The item activities in the group are saved with a delay of 14 days. It means that you need to have the binding running actively for 14 days before the presence simulation kicks in for the first time. You can change this via Offset.

openHAB-Presence-Simulation-gcal-persistence

Now open gcal.cfg (1) and enter the copied client-ID (2) at client_id and the client key at client_secret (3). Furthermore, enter the calendar at calender_name (4).

openHAB-Presence-Simulation-gcal-config

If not already created create a file in the persistence folder that is called gcal.persist (1) in the folder persistence. Now create a simple strategy for your Items that shall be persisted for presence simulation (2).

openHAB-Presence-Simulation-gcal-persist

You may also simply copy the following coding. I have named the group gPreSim. The rule defines that every change of item from the group gPreSim will be entered into the calendar.

Now restart openHAB 2. Wait until openHAB 2 is up and running and then check the installation folder for openhab.log. Another way is to call your host/ip followed by port 9001 (e.g. openhabianpi:9001) to open the log viewer if you are using a  Raspberry Pi and openHABian. If your installation was successful, you should find the following entries:

Follow the instructions. In addition, open this internet site https://www.google.com/device and enter the code from the line with # 2. in the next screen.

openHAB-Presence-Simulation-connect-device

In the next steps you have to allow openHAB 2 to connect to your calendar. Simply click trough the next steps and you are done.

openHAB 2 Presence Simulation –  Google Calendar Scheduler Item Configuration

The configuration of the items for the recording is really simple now. You simply create a group item in your items file.

Assign the items you want to use for the recording to the group.

Open Google Calendar in your browser to check. Use your UI to switch one of the items you have added to the group on and off. When I do this, the switching automatically appears in the calendar after 10 – 20 seconds. Don’t leave the calendar just yet.

If this worked, define another item to activate the presence simulation. By default, this is defined as follows. The item must be named PresenceSimulation

Integrate the item into your sitemap and switch the simulation on. What you might do now for testing is open the calendar again and change the calendar items you have just entered (on/off) to the current day and current time + 2 minutes.

How do you handle your presence simulation? Let us know and leave a comment. If you like the post, please share.

Thomas has build its own Smarthome in 2010. In 2016 he started a German blog about Smarthome to share his knowledge. 2017  he started consulting customers that needed help setting up their own Smarthome. In 2018 the first German course about cloudless Smarthome was launched at Udemy. This course became one of the top rated Smarthome courses. This Smarthome course is now also available in English.

We will be happy to see your thoughts

      Leave a reply