Hallo,
ich würde gerne ein paar Infos meines TVHeadend Servers in Openhab darstellen.
Besonders wichtig wäre mir zu wissen, welche nächsten aufnahmen geplant sind. Damit ich die Suchtimer einfacher im Auge behalten kann.
Ich bin auf dieses Projekt gestoßen. Leider ist es mit Copy & Pate und ein paar Anpassungen nicht getan und der Code übersteigt mal wieder meinen Horizont.
in /etc/openhab2/scripts/shell habe ich folgende jsonpathtransform.sh angelegt
Bash
#!/bin/sh
USER=meinuser
PASS=meinpasswort
SERVER=http://syno:9981
API=$1
JSONPATH=$2
curl -s -u $USER:$PASS $SERVER$API | jq -M -c $JSONPATH | paste -sd, | sed 's/"//g'
Alles anzeigen
Code: tvheadend.things
Thing exec:command:TVH_VERSION_THING "TVH_VERSION" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/serverinfo .sw_version",interval=150]
Thing exec:command:TVH_SUBSCRIPTION_COUNT_THING "TVH_SUBSCRIPTION_COUNT" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/status/subscriptions?limit=0 .totalCount",interval=150]
Thing exec:command:TVH_FAILED_COUNT_THING "TVH_FAILED_COUNT" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/dvr/entry/grid_failed?limit=0 .total",interval=150]
Thing exec:command:TVH_FINISHED_COUNT_THING "TVH_FINISHED_COUNT" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/dvr/entry/grid_finished?limit=0 .total",interval=150]
Thing exec:command:TVH_UPCOMING_COUNT_THING "TVH_UPCOMING_COUNT" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/dvr/entry/grid_upcoming?limit=0 .total",interval=150]
Thing exec:command:TVH_RECORDING_STATE_THING "TVH_RECORDING_STATE" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/dvr/entry/grid_upcoming?limit=1000 .entries[]|select(.sched_status==\"recording\")|.uuid",interval=150]
Thing exec:command:TVH_SUBSCRIPTION_STATE_THING "TVH_SUBSCRIPTION_STATE" @ "TVH" [command="/etc/openhab2/scripts/shell/jsonpathtransform.sh /api/status/subscriptions?limit=1000 .entries[].start",interval=150]
Alles anzeigen
Code: getUpcomingRecordsTVH.js
(function(x){
var json = JSON.parse(x);
var i;
var iLength = json.entries.length;
var earliestscheduled = -1;
var earliestscheduled_idx = -1;
var latestrunning = -1
var latestrunning_idx = -1
for (i = 0; i < iLength; i++) {
if (json.entries[i].sched_status=="scheduled" && (json.entries[i].start_real<earliestscheduled || earliestscheduled==-1))
{
earliestscheduled=json.entries[i].start_real;
earliestscheduled_idx=i;
}
if (json.entries[i].sched_status=="recording" && (json.entries[i].stop_real>latestrunning || latestrunning==-1))
{
latestrunning=json.entries[i].stop_real;
latestrunning_idx=i;
}
}
return latestrunning_idx+","+earliestscheduled_idx;
})(input
Alles anzeigen
Code: getUpcomingRecordsTVH.js
(function(x){
var json = JSON.parse(x);
var i;
var iLength = json.entries.length;
var earliestscheduled = -1;
var earliestscheduled_idx = -1;
var latestrunning = -1
var latestrunning_idx = -1
for (i = 0; i < iLength; i++) {
if (json.entries[i].sched_status=="scheduled" && (json.entries[i].start_real<earliestscheduled || earliestscheduled==-1))
{
earliestscheduled=json.entries[i].start_real;
earliestscheduled_idx=i;
}
if (json.entries[i].sched_status=="recording" && (json.entries[i].stop_real>latestrunning || latestrunning==-1))
{
latestrunning=json.entries[i].stop_real;
latestrunning_idx=i;
}
}
return latestrunning_idx+","+earliestscheduled_idx;
})(input
Alles anzeigen
Code: tvheadend.items
String TVHE_VERSION "version [%s]" <info> {channel="exec:command:TVH_VERSION_THING:output"}
String TVHE_SUBSCRIPTIONS_COUNT "subscriptions [%s]" <info> {channel="exec:command:TVH_SUBSCRIPTION_COUNT_THING:output"}
String TVHE_FINISHED_COUNT "finished [%s]" <info> {channel="exec:command:TVH_FINISHED_COUNT_THING:output"}
String TVHE_FAILED_COUNT "failed [%s]" <info> {channel="exec:command:TVH_FAILED_COUNT_THING:output"}
String TVHE_UPCOMING_COUNT "upcoming [%s]" <info> {channel="exec:command:TVH_UPCOMING_COUNT_THING:output"}
String TVHE_RECORDING_STATE {channel="exec:command:TVH_RECORDING_STATE_THING:output"}
String TVHE_SUBSCRIPTION_STATE {channel="exec:command:TVH_SUBSCRIPTION_STATE_THING:output"}
DateTime TVHE_UPCOMING_NEXT_START "next recording [%1$td.%1$tm %1$tH:%1$tM]" <next>
DateTime TVHE_UPCOMING_CURR_STOP "currently until [%1$td.%1$tm %1$tH:%1$tM]" <record>
// virtual items managed by rules
Number TVHE_FINISHED_SIZE "TVH Finished size [%.1f MB]" (gRestoreOnStartup,gPersistNumber)
Number TVHE_LIVETV_COUNT "Viewing TV [%d]" <kodi>
Number TVHE_RECORDING_COUNT "Recording TV [%d]" <record>
String TVHE_LIVETV_0_DESCRIPTION " [%s]" <kodi>
String TVHE_LIVETV_1_DESCRIPTION " [%s]" <kodi>
String TVHE_LIVETV_2_DESCRIPTION " [%s]" <kodi>
String TVHE_LIVETV_3_DESCRIPTION " [%s]" <kodi>
String TVHE_LIVETV_4_DESCRIPTION " [%s]" <kodi>
Switch TVHE_LIVETV_0_VISIBLE
Switch TVHE_LIVETV_1_VISIBLE
Switch TVHE_LIVETV_2_VISIBLE
Switch TVHE_LIVETV_3_VISIBLE
Switch TVHE_LIVETV_4_VISIBLE
String TVHE_RECORDING_0_DESCRIPTION " [%s]" <recording>
String TVHE_RECORDING_1_DESCRIPTION " [%s]" <recording>
String TVHE_RECORDING_2_DESCRIPTION " [%s]" <recording>
String TVHE_RECORDING_3_DESCRIPTION " [%s]" <recording>
String TVHE_RECORDING_4_DESCRIPTION " [%s]" <recording>
Switch TVHE_RECORDING_0_VISIBLE
Switch TVHE_RECORDING_1_VISIBLE
Switch TVHE_RECORDING_2_VISIBLE
Switch TVHE_RECORDING_3_VISIBLE
Switch TVHE_RECORDING_4_VISIBLE
Alles anzeigen
unter /etc/openhab2/transform
habe ich die folgenden Dateien angelegt
Code: getLatestRecordTVH.js
(function(x){
var json = JSON.parse(x);
var i;
var iLength = json.entries.length;
var index = -1;
var latest = -1;
for (i = 0; i < iLength; i++) {
if(json.entries[i].stop_real > latest)
{
index = i;
latest = json.entries[i].stop_real
}
}
return "" + index + "";
})(input)
Alles anzeigen