CalDAV Simple example to turn something ON and OFF?

@Björn,
Great work and big thanks.
Motivated by your great instructions I will give it another try on the weekend.

kind regards Martin

Hi Martin,
let me know if you succeded.
Cheers
Björn

I am trying to google calendar.
But I just do not see any reaction at all.
Also in openhab log file, there is no entry, no log, even when debug is switch on.

It looks as if the caldav.jar files are not loaded at all.

in the addon folder i have copied:
org.openhab.binding.caldav-command-1.8.0.jar
org.openhab.binding.caldav-personal-1.8.0.jar

These are my items:

String OfficeCalName0 “nächster Termin [%s]” { caldavPersonal=“calendar:martin type:ACTIVE eventNr:1 value:NAME” }
DateTime OfficeCalTime0 “Beginn [%1$tT, %1$td.%1$tm.%1$tY]” { caldavPersonal=“calendar:martin type:ACTIVE eventNr:1 value:START” }
String OfficeCalName1 “nächster Termin [%s]” { caldavPersonal=“calendar:martin type:UPCOMING eventNr:1 value:NAME” }
DateTime OfficeCalTime1 “Beginn [%1$tT, %1$td.%1$tm.%1$tY]” { caldavPersonal=“calendar:martin type:UPCOMING eventNr:1 value:START” }
String OfficeCalName2 “übernächster Termin [%s]” { caldavPersonal=“calendar:martin type:UPCOMING eventNr:2 value:NAME” }
DateTime OfficeCalTime2 “Beginn [%1$tT, %1$td.%1$tm.%1$tY]” { caldavPersonal=“calendar:martin type:UPCOMING eventNr:2 value:START” }

this is my configuration
################################### CalDAV IO Binding ###################################

Used to connect to Cal DAV. All parameters are required.

caldavio:martin:url=https://www.google.com/calendar/dav/xxxxx@googlemail.com/events
caldavio:martin:username=xxxxx@googlemail.com
caldavio:martin:password=the related password
caldavio:martin:reloadInterval=10
caldavio:martin:preloadTime=20000
#caldavio:timeZone=Europe/Berlin
#caldavio:martin:historicLoadTime=3000
caldavio:martin:disableCertificateVerification=true
caldavPersonal:usedCalendars=martin

Also setting disableCertificateVerification=false does not change anything.
Any idea?

I have also allowed access to less secure apps as documented in some other threat in this forum.

regards

Martin

Hi Martin,
pls
(1) also install org.openhab.io.caldav-version.jar
(2) comment out via # the “caldavio:martin:disableCertificateVerification=true” line
(3) comment out via # the “caldavio:timeZone=Europe/Berlin” line
(4) insert in cfg: "caldavCommand:readCalendars=martin"
Cheers
Björn
PS: First sentence in the Wiki.

@Björn. Your support is really excellent!!
I will tryout your advise this evening immediately.

@Björn: It is working now. Thanks for your support.

This posting is a life-saver because it presents a simple and concise example which works, and large bits of it ought to be converted into the official documentation of the CalDAV binding which is, honestly, quite awful.

I had a bit of trouble determining the exact URL to the particular calendar, but I found this page which details that for a few servers.

I have not clear how to determine “eventNr” in items.

Moreover, I would like to know if we can use some parameters in rules.
Eg. I can schedule an event to turn on and off the lights of the garden.
I have some rules that change that switch, but I want that in case I turned lights ON using the caldav event, those rules don’t have to run.

An example code can be:
rule1:
when light ON on caldav event set var=1
when light OFF on caldav event set var=0

on other rules:
if var = 1 then exit

Hi Alberto,
To help you I need to better understand what you indent to do:

You have an event definded in your calendar and syncronized to openhab via caldav which turns at a certain time over a certain period your garden light on/off. Correct?

You have also a rule defined which - in case your calendar entry triggers the switch to turn on or off - sets a variable to 1 or 0 respectively. Correct?

Please advise what you what to achieve with this and why do you not set that variable directly via caldav and an event in your openhab calendar as described afore.

Cheers
Björn

You are right. A solution can be trigger a variable via caldav that allow me to know if a particular rule must be skipped when an item is turned on or off using caldav binding. The “problem” is that is not practical.

I explain my case:
I have a relay that turn on garden lights.
I have also few rules that automatically turn the lights on and off: when I open the garage, turn on lights for 120sec, after 20sec that the garage is close, it turn lights off.

Suppose I have friends for dinner: I schedule an event on my calendar to turn on the lights when they arrive and turn them off when they leave.
If someone open the garage, the light will be turned off before they leave. If I can set a variable, I will skip the rule of the garage and have a correct behaviour of the garden lights.

Hi Alberto,
ok understood.
Then create a dummy item in the item.file for the calendar event, e.g.:
Number CalendarSwitch “CalendarSwitch [%.0f]”

Use calendar event to set it to 1 or 0.

Build up a rule in rule.file:

rule "caldavcheck"
when
light changed from ON to OFF
then
if (CalendarSwitch.state == 1) {

}
else if (CalendarSwitch.state == 0) {

}

Does this help?
Cheers
Björn

You are absolutely right!

That can solve the problem. In my opinion, this way to use the calendar is for “geek” audience.
I think that a more easy to use binding should be more easy like:

I add an event in my calendar that contain the word “dinner”, then I should be able to set a rule that will be triggered on begin and another one at the end of the event that contain that word.

In this way, also the non-geek users will be able to use this very interesting feature of openhab. Anyway, I really thanks who developed the binding… I think that all contributors to this project are great and passionate people.

@aniimsaj: Hi Marko,

the radicale server seems to be a very lightweight server, thanks for mentioning it!
Would you mind sharing the server URL format you configured in openhab?
The documentation says: http://localhost:5232/user/calendar.ics/ but that URL is not working for me.
Maybe you could also add the configuration to the CalDAV binding wiki page?

Hi,
for me the URL of my calendar on my radicale server is like this:
caldavio:udo:url=http://192.168.2.15:5232/udo
BR,
Udo

Thanks for your URL. I already tried that: caldavio:command:url=http://localhost:5232/openhab
But I still get this error in the log files:

2016-04-25 09:37:26.917 [ERROR] [o.o.i.c.i.job.EventReloaderJob] - error while loading calendar entries: Unexpected response
com.github.sardine.impl.SardineException: Unexpected response

I tried an owncloud calendar before and the binding was working, but I cannot get the radicale server working :frowning:

Maybe it’s authentication?! I use plain authentication with a simple username and password. No other options are configured.

Have you activated caldavCommand for you calendar?
caldavCommand:readCalendars=udo

Another setting that made my calendar readings not work in the beginning was this setting:

caldavio:timeZone=Europe/Berlin

After I disabled the timeZone under my calendar settings it worked for me.

Thank you for your suggestions!
I don’t have any time zone set and caldavCommand:readCalendars is set properly. The problem I have is that I cannot connect to the radicale server. I checked the binding source code (EventReloaderJob.java) and debugged the snippet for connecting to the server:

SardineImpl sardine = new SardineImpl(“openhab”, “openhabpassword”);
List listing = sardine.list(“http://localhost:5232/openhab”, 1, false); // here the exception is thrown

Exception in thread "main" com.github.sardine.impl.SardineException: Unexpected response (500 Internal Server Error)
	at com.github.sardine.impl.handler.ValidatingResponseHandler.validateResponse(ValidatingResponseHandler.java:48)
	at com.github.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:40)
	at com.github.sardine.impl.handler.MultiStatusResponseHandler.handleResponse(MultiStatusResponseHandler.java:35)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:218)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160)
	at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:962)
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:417)
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:409)
	at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:386)

The radicale server log shows a single entry:

2016-04-26 08:49:36,052 - INFO: PROPFIND request at /openhab received

If I use Thunderbird Lightning to access the calendar (which works), the log contains:

2016-04-26 08:52:03,012 - INFO: PROPFIND request at /openhab/calendar.ics/ received
2016-04-26 08:52:03,030 - INFO: Checking rights for collection owned by openhab
2016-04-26 08:52:03,032 - INFO: openhab allowed

So my first guess was that I don’t use the correct URL, but you said it’s working for you. Now I think authentication might not be configured properly. How did you configure your radicale server?
Here is my config:

[server]
hosts = 0.0.0.0:5232
daemon = True

[encoding]
request = utf-8

[acl]
type = htpasswd
htpasswd_filename = /etc/radicale/users
htpasswd_encryption = plain

[storage]
filesystem_folder = /var/lib/radicale/collections

[logging]
config = /etc/radicale/logging

Ok, I made some progress: if I dont’ start the server as a daemon but simply by calling it in the console, the exception does not occur any more. So apparently the radicale server configuration as a daemon is causing the error.

Edit: my radicale server config did contain the option daemon = True AND I started it via /etc/init.d/radicale, which caused the server to not function properly. After setting daemon = False, the server works as expected :smiley:

Btw, my url is different: caldavio:command:url=http://localhost:5232/openhab/commands.ics/

Hi!

Sorry to revive this topic, but this is the closest I got to my problem. I am trying to connect to my nextcloud calendar, but the openhab.log shows that there seems to be a problem.

Do I guess correctly that there is a problem with my SSL certificate for my nextcloud? This would be very strange as it is not a self-signed certificate…

javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid cert$
        at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) [?:?]
        at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1949) [?:?]
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:302) [?:?]
        at sun.security.ssl.Handshaker.fatalSE(Handshaker.java:296) [?:?]
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1509) [?:?]
        at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:216) [?:?]
        at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979) [?:?]
        at sun.security.ssl.Handshaker.process_record(Handshaker.java:914) [?:?]
        at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062) [?:?]
        at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375) [?:?]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403) [?:?]
        at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387) [?:?]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:275) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:254) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.conn.HttpClientConnectionOperator.connect(HttpClientConnectionOperator.java:123) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:318) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:363) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:219) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:195) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:86) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:108) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:184) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:72) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:214) [211:org.openhab.io.caldav:1.11.0]
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:160) [211:org.openhab.io.caldav:1.11.0]
        at com.github.sardine.impl.SardineImpl.execute(SardineImpl.java:962) [211:org.openhab.io.caldav:1.11.0]
        at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:417) [211:org.openhab.io.caldav:1.11.0]
        at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:409) [211:org.openhab.io.caldav:1.11.0]
        at com.github.sardine.impl.SardineImpl.list(SardineImpl.java:386) [211:org.openhab.io.caldav:1.11.0]
        at org.openhab.io.caldav.internal.job.EventReloaderJob.loadEvents(EventReloaderJob.java:246) [211:org.openhab.io.caldav:1.11.0]
        at org.openhab.io.caldav.internal.job.EventReloaderJob.execute(EventReloaderJob.java:137) [211:org.openhab.io.caldav:1.11.0]
        at org.quartz.core.JobRunShell.run(JobRunShell.java:202) [115:org.eclipse.smarthome.core.scheduler:0.10.0.b1]
        at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) [115:org.eclipse.smarthome.core.scheduler:0.10.0.b1]
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requeste$
        at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387) ~[?:?]
        at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292) ~[?:?]
        at sun.security.validator.Validator.validate(Validator.java:260) ~[?:?]
        at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324) ~[?:?]
        at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229) ~[?:?]
        at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124) ~[?:?]
        at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491) ~[?:?]
        ... 28 more

Thank you very much for your help!

Hi again,

It’s working now, I had to disable ssl verification. But since it is a Let’s Encrypt certficate I wonder why it is not working…