openHAB 連携
ここでは、スマートホームでごみ収集情報をかんたんに扱えるよう、openHAB への組み込み方法を説明します。
依存関係のインストール
接続には 2 つのものが必要です。1 つ目は HTTP Binding、2 つ目は(データ処理用の)JSONPATH Data Transformation Service です。 HTTP Binding (新しいタブで開きます) / JSONPATH Data Transformation (新しいタブで開きます).
Thing の作成
HTTP Thing を作成し、次のように設定します(コード参照)。ヘッダーにはウムラウトや特殊文字を送信できないのでご注意ください。たとえば「ü」の代わりに「ue」と記述してください。
UID: http:url:xxxxxxx
label: Binable
thingTypeUID: http:url
configuration:
authMode: BASIC
ignoreSSLErrors: false
baseURL: https://binable.app/api/fetch
delay: 0
stateMethod: POST
refresh: 21600
commandMethod: POST
contentType: text/plain
timeout: 6000
bufferSize: 2048
headers:
- "X-Address-Street=XXX"
- "X-Address-HouseNumber=XXX"
- "X-Address-Zip=XXX"
- "X-Address-City=XXXX"
- "X-Address-Country=DE"
channels:
- id: residual_waste_last
channelTypeUID: http:datetime
label: Restmüll (letzte)
description: ""
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.residualWaste.last
- id: residual_waste_next
channelTypeUID: http:datetime
label: Restmüll (nächste)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.residualWaste.next
- id: residual_waste_next_days
channelTypeUID: http:number
label: Restmüll (nächste) relative
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.residualWaste.nextDays
- id: paper_last
channelTypeUID: http:datetime
label: Papier (letzte)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.paper.last
- id: paper_next
channelTypeUID: http:datetime
label: Papier (nächste)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.paper.next
- id: paper_next_days
channelTypeUID: http:number
label: Papier (nächste) relative
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.paper.nextDays
- id: reusable_materials_last
channelTypeUID: http:datetime
label: Wertstoffe (letzte)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.reusableMaterials.last
- id: reusable_materials_next
channelTypeUID: http:datetime
label: Wertstoffe (nächste)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.reusableMaterials.next
- id: reusable_materials_next_days
channelTypeUID: http:number
label: Wertstoffe (nächste) relative
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.reusableMaterials.nextDays
- id: bio_last
channelTypeUID: http:datetime
label: Bio (letzte)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.bio.last
- id: bio_next
channelTypeUID: http:datetime
label: Bio (nächste)
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.bio.next
- id: bio_next_days
channelTypeUID: http:number
label: Bio (nächste) relative
description: null
configuration:
mode: READONLY
stateTransformation: JSONPATH:$.bio.nextDays
# - id: christmas_tree_last
# channelTypeUID: http:datetime
# label: Weihnachtsbaum (letzte)
# description: null
# configuration:
# mode: READONLY
# stateTransformation: JSONPATH:$.christmasTree.last
# - id: christmas_tree_next
# channelTypeUID: http:datetime
# label: Weihnachtsbaum (nächste)
# description: null
# configuration:
# mode: READONLY
# stateTransformation: JSONPATH:$.christmasTree.next
# - id: christmas_tree_next_days
# channelTypeUID: http:number
# label: Weihnachtsbaum (nächste) relative
# description: null
# configuration:
# mode: READONLY
# stateTransformation: JSONPATH:$.christmasTree.nextDays
ご注意:現在利用できるごみの種類は次のとおりです(ラベル/キー):古紙(paper)、生ごみ(bio)、燃えるごみ(residualWaste)、資源ごみ(reusableMaterials)、クリスマスツリー(christmasTree)、有害ごみ(toxic)、おむつ(diaper)、剪定枝(hedgeTreeTrimming)
Items
対応するチャンネルをもとに Items を作成します。
任意:日付の形式
State Description を作成すると、日付を正しい形式で表示できます(例:「%1$td.%1$tm.%1$tY」)。残り日数には次の State Description も使えます:「%.0f 日」。
完了です!
これで完了です。頻繁なリクエストは不要なので、「delay」の値は小さくしないでください。