If someone is interested, here is a pure python version of the script without any file creation or copy but you need to install graphviz python interface
#!/usr/bin/python3
import json
import sys
from graphviz import Digraph
def main(argv):
if(len(sys.argv) < 2):
print('missing input file')
sys.exit(2)
inputfile = str(sys.argv[1])
outputfile = 'zigbee_map'
if(len(sys.argv) >= 3):
outputfile = str(sys.argv[2])
file = open(inputfile)
json_string = file.read()
file.close()
dot = Digraph('graph',comment='Zigbee map',graph_attr={'rankdir':'LR'},node_attr={'shape': 'record'},format='png',filename=outputfile)
json_dictionary = json.loads(json_string)
for key in json_dictionary:
if(key.find("zigbee:")>=0):
zigbee_logicaltype=json_dictionary[key]["value"]["properties"]["zigbee_logicaltype"]
zigbee_networkaddress =json_dictionary[key]["value"]["properties"]["zigbee_networkaddress"]
label = json_dictionary[key]["value"]["label"]
if(zigbee_logicaltype=="COORDINATOR"):
zigbee_macaddress=json_dictionary[key]["value"]["properties"]["zigbee_macaddress"]
modelId =""
else:
zigbee_macaddress=json_dictionary[key]["value"]["configuration"]["properties"]["zigbee_macaddress"]
modelId =json_dictionary[key]["value"]["properties"]["modelId"]
dot_label=str()
dot_label+=zigbee_logicaltype
dot_label+="|"+label
dot_label+="|"+modelId
dot_label+="|{adress |"+zigbee_networkaddress+"}"
dot_label+="|{mac |"+zigbee_macaddress+"}"
dot.node(zigbee_networkaddress, dot_label)
zigbee_networkaddress =json_dictionary[key]["value"]["properties"]["zigbee_networkaddress"]
zigbee_neighbors_json =json_dictionary[key]["value"]["properties"]["zigbee_neighbors"]
zigbee_neighbors_list = json.loads(zigbee_neighbors_json)
for item in zigbee_neighbors_list:
dot.edge(zigbee_networkaddress, item['address'], label=item['joining'], color='blue')
zigbee_routes_json =json_dictionary[key]["value"]["properties"]["zigbee_routes"]
zigbee_routes_list = json.loads(zigbee_routes_json)
for item in zigbee_routes_list:
dot.edge(item['next_hop'], item['destination'], label=item['state'], color='black')
dot.render()
if __name__ == "__main__":
main(sys.argv[1:])
Do you have any reason to use a backup or a request and not directly the jsondb file /var/lib/openhab2/jsondb/org.eclipse.smarthome.core.thing.Thing.json ?
I was able to produce a map in /tmp/zigbee.png with the command
./zigbee_map.py /var/lib/openhab2/jsondb/org.eclipse.smarthome.core.thing.Thing.json /tmp/zigbee