Mercurial > code > home > repos > homeauto
comparison service/rdf_to_mqtt/rdf_to_mqtt.py @ 789:e7eb3fc8db54
more lights, color temp control
author | drewp@bigasterisk.com |
---|---|
date | Sat, 28 Nov 2020 01:34:31 -0800 |
parents | acf58b83022f |
children | 6b80a6c58907 |
comparison
equal
deleted
inserted
replaced
788:7916b9786288 | 789:e7eb3fc8db54 |
---|---|
63 ROOM['bedHeadboard']: { | 63 ROOM['bedHeadboard']: { |
64 'root': 'bed/light/headboard/command', | 64 'root': 'bed/light/headboard/command', |
65 'hasWhite': True, | 65 'hasWhite': True, |
66 }, | 66 }, |
67 # https://github.com/Koenkk/zigbee2mqtt.io/blob/new_api/docs/information/mqtt_topics_and_message_structure.md#general | 67 # https://github.com/Koenkk/zigbee2mqtt.io/blob/new_api/docs/information/mqtt_topics_and_message_structure.md#general |
68 ROOM['syl1']: { | 68 ROOM['frontRoom1']: { |
69 'root': 'zigbee2mqtt/syl1/set', | 69 'root': 'zigbee2mqtt/frontRoom1/set', |
70 'hasBrightness': True, | 70 'hasBrightness': True, |
71 'defaults': { | 71 'defaults': { |
72 'transition': 0, | 72 'transition': 0, |
73 } | 73 } |
74 }, | 74 }, |
75 ROOM['syl2']: { | 75 ROOM['frontRoom2']: { |
76 'root': 'zigbee2mqtt/syl2/set', | 76 'root': 'zigbee2mqtt/frontRoom2/set', |
77 'hasBrightness': True, | 77 'hasBrightness': True, |
78 'defaults': { | 78 'defaults': { |
79 'transition': 0, | 79 'transition': 0, |
80 } | 80 } |
81 }, | 81 }, |
82 ROOM['syl3']: { | 82 ROOM['asherCeiling']: { |
83 'root': 'zigbee2mqtt/syl3/set', | 83 'root': 'zigbee2mqtt/asherCeiling/set', |
84 'hasBrightness': True, | 84 'hasBrightness': True, |
85 'defaults': { | 85 'defaults': { |
86 'transition': 0, | 86 'transition': 0, |
87 } | 87 } |
88 }, | 88 }, |
89 ROOM['syl4']: { | 89 ROOM['stairTop']: { |
90 'root': 'zigbee2mqtt/syl4/set', | 90 'root': 'zigbee2mqtt/stairTop/set', |
91 'hasBrightness': True, | 91 'hasBrightness': True, |
92 'defaults': { | 92 'defaults': { |
93 'transition': 0, | 93 'transition': 0, |
94 } | 94 } |
95 }, | 95 }, |
96 ROOM['noname1']: { 'root': 'zigbee2mqtt/0xf0d1b8000001ffc6/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } }, | |
97 ROOM['noname2']: { 'root': 'zigbee2mqtt/0xf0d1b80000023583/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } }, | |
98 ROOM['noname3']: { 'root': 'zigbee2mqtt/0xf0d1b80000023708/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } }, | |
99 ROOM['noname4']: { 'root': 'zigbee2mqtt/0xf0d1b80000022adc/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } }, | |
96 } | 100 } |
97 | 101 |
98 | 102 |
99 class OutputPage(PrettyErrorHandler, cyclone.web.RequestHandler): | 103 class OutputPage(PrettyErrorHandler, cyclone.web.RequestHandler): |
100 | 104 |
128 which = 'up' if delta > 0 else 'down' | 132 which = 'up' if delta > 0 else 'down' |
129 self._publish(topic=f'theater_blaster/ir_out/volume_{which}', message=json.dumps({'timed': abs(delta)})) | 133 self._publish(topic=f'theater_blaster/ir_out/volume_{which}', message=json.dumps({'timed': abs(delta)})) |
130 ignored = False | 134 ignored = False |
131 if stmt[0:2] == (dev, ROOM['color']): | 135 if stmt[0:2] == (dev, ROOM['color']): |
132 h = stmt[2].toPython() | 136 h = stmt[2].toPython() |
133 r, g, b = int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16) | 137 msg = {} |
134 msg = { | 138 if h.endswith(b'K'): # accept "0.7*2200K" (brightness 0.7) |
135 'state': 'ON' if r or g or b else 'OFF', | |
136 'color': { | |
137 'r': r, | |
138 'g': g, | |
139 'b': b | |
140 }, | |
141 } | |
142 if attrs.get('hasBrightness', False): | |
143 # todo- still not right for sylvania bulbs; they want color x-y. | |
144 # see https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html#zigbee2mqttfriendly_nameset | 139 # see https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html#zigbee2mqttfriendly_nameset |
145 msg['brightness'] = max(r, g, b) | 140 bright, kelvin = map(float, h[:-1].split(b'*')) |
146 if msg['brightness'] != 0: | 141 msg['state'] = 'ON' |
147 scl = msg['brightness'] / 255 | 142 msg["color_temp"] = round(1000000 / kelvin, 2) |
148 for chan in ['r', 'g', 'b']: | 143 msg['brightness'] = int(bright * 255) # 1..20 look about the same |
149 msg['color'][chan] = int(msg['color'][chan] / 255.0 / scl * 255) | 144 else: |
150 | 145 r, g, b = int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16) |
151 if attrs.get('hasWhite', False): | 146 msg = { |
152 msg['white_value'] = max(r, g, b) | 147 'state': 'ON' if r or g or b else 'OFF', |
148 'color': { | |
149 'r': r, | |
150 'g': g, | |
151 'b': b | |
152 }, | |
153 } | |
154 | |
155 if attrs.get('hasWhite', False): | |
156 msg['white_value'] = max(r, g, b) | |
153 msg.update(attrs.get('defaults', {})) | 157 msg.update(attrs.get('defaults', {})) |
154 self._publish(topic=attrs['root'], message=json.dumps(msg)) | 158 self._publish(topic=attrs['root'], message=json.dumps(msg)) |
155 ignored = False | 159 ignored = False |
156 | 160 |
157 if ignored: | 161 if ignored: |