I already read a lot from you in other threads. I´m glad that you support me!
My actual target is visualizing calendar entries (date + text) on HABPanel. In this calendar I make entries for maintenance task, e.g. when I cleaned the ventilation outlets, replaced the filter from the cistern, oiled the parket, repainted the wall and so and and so force.
This task I could realize by importing the calendar as ical from my Nextcloud, converting it to json and reading that in Grafana. Grafana puts the entries in a table which I show on a HABPanel page.
rule "Convert the maintenance calendar from ical in json for visualization in Grafana"
Time cron "0 0 0 * * ?" or
Time cron "0 0 12 * * ?"
// 1. Import calendar as ical from Nextcloud
var String ics = executeCommandLine(Duration.ofSeconds(10), "curl", "-s", "https://.../remote.php/dav/calendars/openHAB/wartung?export", "-u", "username:password")
//logInfo ("ics-String", ics)
// 2. Remove ";" and "=" from "VALUE=DATE" date so that it shows it properly in Grafana
ics = ics.replace(";VALUE=DATE", "")
// 3. Save ical in file
var String response_speichern = executeCommandLine(Duration.ofSeconds(1), "bash", "/openhab/conf/scripts/write_to_file_ics.sh", ics)
//logInfo ("ics-String speichern", response_speichern)
// 4. Convert ical to json konvertieren
var String responce_ics2json = executeCommandLine(Duration.ofSeconds(1), "ical2json", "/openhab/userdata/cache/wartung.ics")
//logInfo ("ics in json konvertieren", responce_ics2json)
// 5. Upload file to Nextcloud, from there it gets loaded by Grafana
var String response_upload = executeCommandLine(Duration.ofSeconds(5), "curl", "-u", "username:password", "--upload-file", "/openhab/userdata/cache/wartung.json" ,"https://.../remote.php/dav/files/openHAB/wartung.json")
//logInfo ("json-String upload", response_upload)
The above works very well for about a year and satisfies my needs. The whole thing requires the little tool ical2json which I found in the internet (GitHub - adrianlee44/ical2json: A simple node package to convert ical data to json). As stated on its GitHub page, it can be installed by “npm install -g ical2json”. However, by trying it out, it told me that npm is not available. Following to that I found “curl -sL https://deb.nodesource.com/setup_lts.x | bash -” and “apt-get install -y nodejs” to resolve this issue.
Honestly I don´t always exactly know what I´m doing. I have a target and try to resolve it in which I typically succeed sooner or later .
Coming to an end with this introduction, I could solve the task by installing ical2json with following lines in the docker container:
docker exec -it openHAB3.4 bash
curl -sL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
npm install -g ical2json
The only drawback of the whole thing is, that I have to reinstall the above packages after re-creating the docker container. Although this is not a big deal as I update openHAB only once or twice per year, I thought now about trying to automize it after I recently forgot to re-install it after upgrading to 4.0.
I hoped that I could just paste the above lines in the cont-init.d script, except of the docker exec line of course. But it already failed with installing setup_lts.x. Even more I was happy after I could resolve this challenge by the following adaptation:
wget -O - https://deb.nodesource.com/setup_lts.x > /openhab/setup_lts.sh
But as mentioned, now I struggle with installing nodejs (or npm) which I need for finally installing ical2json.
To answer your questions:
- I pull the docker image by “openhab/openhab:latest”. Therefore I assume I have the default Debian version. I think that confirms it:
- I tried to install “npm install -g ical2json” in the folder /openhab/conf/automation/js outside docker on the base system according your recommendation. But also here I get the failure message that npm is missing.
- How to build my own docker image I don´t know. I haven´t digged into that. I would like to keep it simple and stay with using the standard version available.
- As stated, I tried to run apt-get update and apt-get uprade before installing nodejs. But that didn´t help. This time I was able to cache the log about it. Actually this is quite tricky. It looks to me that the script gets re-started over and over when it fails and the start of the container stucks at this position. Can this never-ending restarting of the script be somehow avoided? Especially for trouble-shooting it is a drawback as it masses up the log.
By the way, I operate another container (Nextcloud) by which I simply can install additional packages by defining an ENV variable:
As far as I found, something like that is not possible with the openHAB docker, or?