En3rGy / 14100_Hue

Gira HS logic module to control Philips Hue
MIT License
7 stars 0 forks source link

Control rooms #30

Closed En3rGy closed 1 year ago

En3rGy commented 1 year ago

Reported by https://knx-user-forum.de/forum/öffentlicher-bereich/knx-eib-forum/1451665-neuer-baustein-hue-group-14100?p=1890274#post1890274

I found a way to use the room name to get the group id (since you cannot turn on/off rooms)

When you look at the /resource/grouped_light the grouped lights in question have an owner, this is the room in which the lights are. So with some hack code i'm able to get the ID from the name -> RID -> ID. This way i can adjust my own code and keep it working with V2.😂 I know you have your own code to deal with and the bugs that come with that. But this might help in the future, so just sharing for that and not to pester you to implement it 😊

Code:

import json
import httplib
import ssl
def call_https_hue(ipadres, path):
  h = httplib.HTTPSConnection(ipadres,context=ssl._create_unverified_context())
  headers = {"Content-type": "text/plain" ,"hue-application-key": "myhuekey"}
  h.request('GET', path, headers=headers)
  return h
roomname = ("Eetkamer")
ipadres = ('192.168.178.128')
path = ('/clip/v2/resource/room')
h = call_https_hue(ipadres,path)
r = json.load(h.getresponse())
for i, member in enumerate(r['data']):
    x = str(member['metadata']['name'])
    if  x.lower() == roomname.lower():
      index_a = i

naam = (r['data'][index_a]['metadata']['name'])
rid = (r['data'][index_a]['id'])
print(naam)
print(rid)
path = ('/clip/v2/resource/grouped_light')

k = call_https_hue(ipadres,path)
l = json.load(k.getresponse())
for i, member in enumerate(l['data']):
    x = (member['owner']['rid'])
    if  x == rid:
      index_b = i
id = (l['data'][index_b]['id'])
print(id)​

roomname is the one i can change in whatever room and it will spit out the ID at the end. (the one before that is the Owner ID)