I've written a python script to rename the devices, based on the names in zwavejs2mqtt + some rules (that could be changed in the script)
I'm not a coder and it's my 2nd python script, so perhaps not perfect.
Code: Select all
#!/usr/bin/python
# -*- coding: ISO-8859-1 -*-
# rename devicesd with hardware info
import sys
import requests
from requests.auth import HTTPBasicAuth
import json
#~~~~~~~~~~ Parameters Domoticz ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
domoticz_ip='hestiatest' #IP or DNS
domoticz_port='8080'
user=''
password=''
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Input
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
NODES = {
"11": {
"name": "Portail"
},
"17": {
"name": "Terrasse"
},
"30": {
"name": "Prise HKZW"
},
"47": {
"name": "Chauffe-eau Studio"
},
"53": {
"name": "Radiateur Salon Studio"
},
"54": {
"name": "Détecteur Salon"
},
"55": {
"name": "Détecteur Couloir"
},
"59": {
"name": "Allée"
},
"61": {
"name": "Haut escalier"
},
"62": {
"name": "Escalier Studio"
},
"72": {
"name": "Détecteur Fumées Couloir"
},
"76": {
"name": "Dégagement"
},
"78": {
"name": "Entrée"
},
"80": {
"name": "Détecteur Portail"
},
"87": {
"name": "Balcon Studio"
},
"94": {
"name": "SdB Studio"
},
"95": {
"name": "LED Terrasse"
},
"99": {
"name": "Détecteur Portillon"
},
"102": {
"name": "Portillon"
},
"104": {
"name": "VMC Studio"
},
"106": {
"name": "Garage"
},
"107": {
"name": "s/Balcon"
},
"108": {
"name": "Atelier Cave"
},
"111": {
"name": "Couloir"
},
"113": {
"name": "Escalier Cave"
},
"119": {
"name": "LED s/ Balcon"
},
"120": {
"name": "Radiateur SdB Studio"
},
"121": {
"name": "Détecteur Allée"
},
"122": {
"name": "Sonnette"
},
"123": {
"name": "Prise NEO1",
"loc": ""
},
"124": {
"name": "Prise NEO2"
},
"126": {
"name": "Détecteur Terrasse"
},
"127": {
"name": "Détecteur Cave"
},
"128": {
"name": "Détecteur Studio"
},
"130": {
"name": "Cave Vin"
},
"131": {
"name": "Salon Studio"
}
}
DEVICES = (
1915,
1917,
1918,
1919,
1920,
1921,
1922,
1923,
1924,
1925,
1926,
1927,
1928,
1929,
1930,
1931,
1932,
1933,
1934,
1935,
1936,
1937,
1938,
1939,
1940,
1941,
1942,
1943,
1944,
1945,
1946,
1947,
1948,
1949,
1950,
1951,
1952,
1953,
1954,
1955,
1956,
1957,
1958,
1959,
1960,
1961,
1962,
1963,
1964,
1965,
1966,
1967,
1968,
1969,
1970,
1971,
1972,
1973,
1974,
1975,
1976,
1977,
1978,
1979,
1980,
1981,
1982,
1983,
1984,
1985,
1986,
1987,
1988,
1989,
1990,
1991,
1992,
1993,
1994,
1995,
1996,
1997,
1998,
1999,
2000,
2001,
2002,
2003,
2004,
2005,
2006,
2007,
2008,
2009,
2010,
2011,
2012,
2013,
2014,
2015,
2016,
2017,
2018,
2019,
2020,
2021,
2022,
2023,
2024,
2025,
2026,
2027,
2028,
2029,
2030,
2031,
2032,
2033,
2034,
2035,
2036,
2037,
2038,
2039,
2040,
2041,
2042,
2043,
2044,
2045,
2046,
2047,
2048,
2049,
2050,
2051,
2052,
2053,
2054,
2055,
2056,
2057,
2058,
2059,
2060,
2061,
2062
)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Functions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
### rename the device
def rename_device(idx, name):
#print "rename_device idx: " +idx+ " name: " +name
req='http://'+domoticz_ip+':'+domoticz_port+'/json.htm?type=command¶m=renamedevice&idx='+idx+'&name='+name
print req
requests.get(req,auth=HTTPBasicAuth(user,password))
###
### get attribute value from a device
def get_device_attrib(idx, attrib):
r = requests.get('http://'+domoticz_ip+':'+domoticz_port+'/json.htm?type=devices&rid='+str(idx),auth=HTTPBasicAuth(user,password))
status=r.status_code
if status == 200:
r=r.json()
result={}
attrib_val =r['result'][0][attrib]
#print "get_device_attrib "+attrib+" IDX: "+str(idx)
#print attrib_val
return attrib_val
else:
print "get_device_attrib " +attrib+" IDX:"+str(idx)+" not found ?"
###
#-----------------------------------### MAIN ###--------------------------------------------#
for Dz_IDX in DEVICES:
print " "
#print Dz_IDX
Dz_Name=get_device_attrib(str(Dz_IDX), "Name")
#print "Dz_Name: "+str(Dz_IDX)+" "+Dz_Name
Dz_HardwareName=get_device_attrib(str(Dz_IDX), "HardwareName")
#print Dz_HardwareName
Dz_ID=get_device_attrib(str(Dz_IDX), "ID")
#print Dz_ID
ZW_ID=Dz_ID[1:4]
#print ZW_ID
tempID=ZW_ID[-1]
#print tempID
if tempID == '/':
#print 'slash'
ZW_ID=ZW_ID[0:2]
#print ZW_ID
#print "ZW_ID: "+ZW_ID
ZW_MS=Dz_ID[-20:]
#print ZW_MS
Dz_Unit=get_device_attrib(str(Dz_IDX), "Unit") # to have unique device name
#print Dz_Unit
Dz_Type=get_device_attrib(str(Dz_IDX), "Type")
#print Dz_Type
Dz_SubType=get_device_attrib(str(Dz_IDX), "SubType")
#print Dz_SubType
Dz_Used=get_device_attrib(str(Dz_IDX), "Used")
#print "Dz_Used: "+str(Dz_Used)
ZW_Name=NODES[ZW_ID]['name']
#print ZW_Name
New_Name = "!"
Name_Add = '?'
if Dz_Type == 'Light/Switch':
New_Name = ZW_Name+" "+str(Dz_Unit)
else:
if Dz_Type == 'Temp':
Name_Add = 'Temp'
elif Dz_Type == 'Usage' and Dz_SubType == 'Electric':
Name_Add = 'W'
else:
Name_Add = str(Dz_SubType)
New_Name = ZW_Name+" "+Name_Add+" "+str(Dz_Unit)
print str(Dz_IDX)+" "+Dz_Name
print "=> "+New_Name
rename_device(str(Dz_IDX), New_Name)
When I use a device, I remove the number (unit) at the end of the name and eventually add something; easier for me to change the end than the beginning