@Max_G You were completely right. I’ve also added a print(.)-line as a debug information - not as part of the solution. But this shifted my lines.
So, no I’ve added also 2 author lines.
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Code by AndreasK (openhab.org-User) ~ 2022-02-17
# Modified by ornostar (openhab.org-user) ~ 2022-12-26
import json
print("pls wait...")
exportStr = []
with open('org.openhab.core.items.Item.json') as json_file:
data = json.load(json_file)
for p in data:
# itemType
itemType = (data[p]['value']['itemType'] + " ")
# name
name = str(p)
# label
label = ""
if 'label' not in data[p]['value']:
label = (" \"" + name + "\"")
else:
label = (" \"" + data[p]['value']['label'] + "\"")
# category
category = ""
if 'category' in data[p]['value']:
category = data[p]['value']['category']
if category:
category = (" <" + category + ">")
# groupNames
groupNames = ""
if 'groupNames' in data[p]['value']:
groupNames = ""
for erg in data[p]['value']['groupNames']:
groupNames = groupNames + erg + ", "
if groupNames:
groupNames = (" (" + groupNames.rstrip(', ') + ")")
# tags
tags = ""
if 'tags' in data[p]['value']:
tags = ""
for ergTags in data[p]['value']['tags']:
tags = tags + "\"" + ergTags + "\", "
if tags:
tags = (" [" + tags.rstrip(', ') + "]")
# ItemChannelLink
channel = ""
uid = ""
with open('org.openhab.core.thing.link.ItemChannelLink.json') as json_file_links:
dataLinks = json.load(json_file_links)
# print(dataLinks)
for pLinks in dataLinks:
if name == dataLinks[pLinks]['value']['itemName']:
uid = dataLinks[pLinks]['value']['channelUID']['uid']
with open('org.openhab.core.thing.Thing.json') as json_file_things:
dataThings = json.load(json_file_things)
# print(dataThings)
for pThings in dataThings:
if pThings in uid:
channel = uid
# Metadata
metadata = ""
stateDescription = ""
expire = ""
widget = ""
cellWidget = ""
autoupdate = ""
listWidget = ""
with open('org.openhab.core.items.Metadata.json') as json_file_meta:
dataMeta = json.load(json_file_meta)
# print(dataMeta)
for pMeta in dataMeta:
if name in pMeta:
if "stateDescription:" in pMeta:
stateDescription = "stateDescription=\"\"["
if 'pattern' in dataMeta[pMeta]['value']['configuration']:
stateDescription = stateDescription + "pattern=\"" + dataMeta[pMeta]['value']['configuration']['pattern'] + "\", "
if 'min' in dataMeta[pMeta]['value']['configuration']:
stateDescription = stateDescription + "min=\"" + dataMeta[pMeta]['value']['configuration']['min'] + "\", "
if 'max' in dataMeta[pMeta]['value']['configuration']:
stateDescription = stateDescription + "max=\"" + dataMeta[pMeta]['value']['configuration']['max'] + "\", "
if 'step' in dataMeta[pMeta]['value']['configuration']:
stateDescription = stateDescription + "step=\"" + dataMeta[pMeta]['value']['configuration']['step'] + "\", "
if 'options' in dataMeta[pMeta]['value']['configuration']:
stateDescription = stateDescription + "options=\"" + dataMeta[pMeta]['value']['configuration']['options'] + "\", "
stateDescription = stateDescription.rstrip(", ") + "], "
# print(stateDescription)
if "expire:" in pMeta:
expire = "expire=\""
if 'value' in dataMeta[pMeta]['value']:
expire = expire + dataMeta[pMeta]['value']['value']
expire = expire + "\", "
# print(expire)
if "widget:" in pMeta:
widget = "expire=\""
if 'value' in dataMeta[pMeta]['value']:
widget = widget + dataMeta[pMeta]['value']['value']
widget = widget + "\", "
# print(widget)
if "cellWidget:" in pMeta:
cellWidget = "cellWidget=\""
if 'value' in dataMeta[pMeta]['value']:
cellWidget = cellWidget + dataMeta[pMeta]['value']['value']
cellWidget = cellWidget + "\", "
# print(cellWidget)
if "autoupdate:" in pMeta:
autoupdate = "autoupdate=\""
if 'value' in dataMeta[pMeta]['value']:
autoupdate = autoupdate + dataMeta[pMeta]['value']['value']
autoupdate = autoupdate + "\", "
# print(autoupdate)
if "listWidget:" in pMeta:
listWidget = "listWidget=\"" + dataMeta[pMeta]['value']['value'] + "\"["
if 'title' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "title=\"" + str(dataMeta[pMeta]['value']['configuration']['title']) + "\", "
if 'subtitle' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "subtitle=\"" + str(dataMeta[pMeta]['value']['configuration']['subtitle']) + "\", "
if 'icon' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "icon=\"" + str(dataMeta[pMeta]['value']['configuration']['icon']) + "\", "
if 'min' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "min=\"" + str(dataMeta[pMeta]['value']['configuration']['min']) + "\", "
if 'max' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "max=\"" + str(dataMeta[pMeta]['value']['configuration']['max']) + "\", "
if 'step' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "step=\"" + str(dataMeta[pMeta]['value']['configuration']['step']) + "\", "
if 'vertical' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "vertical=\"" + str(dataMeta[pMeta]['value']['configuration']['vertical']) + "\", "
if 'label' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "label=\"" + str(dataMeta[pMeta]['value']['configuration']['label']) + "\", "
if 'scale' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "scale=\"" + str(dataMeta[pMeta]['value']['configuration']['scale']) + "\", "
if 'scaleSteps' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "scaleSteps=\"" + str(dataMeta[pMeta]['value']['configuration']['scaleSteps']) + "\", "
if 'scaleSubSteps' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "scaleSubSteps=\"" + str(dataMeta[pMeta]['value']['configuration']['scaleSubSteps']) + "\", "
if 'unit' in dataMeta[pMeta]['value']['configuration']:
listWidget = listWidget + "unit=\"" + str(dataMeta[pMeta]['value']['configuration']['unit']) + "\", "
listWidget = listWidget.rstrip(", ") + "], "
# print(listWidget)
metadata = (stateDescription + expire + widget + listWidget + cellWidget + autoupdate).rstrip(", ")
lastEnt = ""
if channel:
lastEnt = "channel=\"" + channel + "\", "
if metadata:
lastEnt = lastEnt + metadata + ", "
if lastEnt:
lastEnt = (" { " + lastEnt.rstrip(", ") + " }")
exportStr.append(channel + " " + itemType + name + label + category + groupNames + tags + lastEnt)
# export all the data to a file and sort it
f = open("export.items", "w")
for line in sorted(exportStr):
# print (line.split(" ", 1)[1] + "\n")
f.write(line.split(" ", 1)[1].encode('utf-8').strip() + "\n")
#f.write(line.split(" ", 1)[1] + "\n")
f.close()
print("done")