changeset 789:e7eb3fc8db54

more lights, color temp control
author drewp@bigasterisk.com
date Sat, 28 Nov 2020 01:34:31 -0800
parents 7916b9786288
children b85986495848
files service/rdf_to_mqtt/index.html service/rdf_to_mqtt/rdf_to_mqtt.py
diffstat 2 files changed, 76 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/service/rdf_to_mqtt/index.html	Thu Sep 10 15:02:00 2020 -0700
+++ b/service/rdf_to_mqtt/index.html	Sat Nov 28 01:34:31 2020 -0800
@@ -1,7 +1,11 @@
 <!DOCTYPE html>
 <html>
   <head>
-    <title>rdf_to_mqtt</title>
+    <title>rdf_to_mqtt</title>   
+    <meta name="viewport" content="width=device-width, initial-scale=1" />
+    <meta name="mobile-web-app-capable" content="yes" />
+    <meta name="apple-mobile-web-app-capable" content="yes" />
+
     <meta charset="utf-8" />
     <script src="/lib/polymer/1.0.9/webcomponentsjs/webcomponents.min.js"></script>
     <script src="/lib/require/require-2.3.3.js"></script>
@@ -67,20 +71,49 @@
       <div><button data-post="output?s=:bedHeadboard&p=:color" data-body="#0000ff">headboard blue</button></div>
     </section>
     <section>
-      <div><button data-post="output?s=:syl1&p=:color" data-body="#000000">Send (:syl1 :color black)</button></div>
-      <div><button data-post="output?s=:syl1&p=:color" data-body="#ffffff">Send (:syl1 :color white)</button></div>
+      <div><button data-post="output?s=:frontRoom1&p=:color" data-body="0*3200K">Send (:frontRoom1 :color black)</button></div>
+      <div><button data-post="output?s=:frontRoom1&p=:color" data-body="1*3200K">Send (:frontRoom1 :color white)</button></div>
+    </section>
+    <section>
+      <div><button data-post="output?s=:frontRoom2&p=:color" data-body="0*3200K">Send (:frontRoom2 :color black)</button></div>
+      <div><button data-post="output?s=:frontRoom2&p=:color" data-body="1*3200K">Send (:frontRoom2 :color white)</button></div>
     </section>
     <section>
-      <div><button data-post="output?s=:syl2&p=:color" data-body="#000000">Send (:syl2 :color black)</button></div>
-      <div><button data-post="output?s=:syl2&p=:color" data-body="#ffffff">Send (:syl2 :color white)</button></div>
-    </section>
-    <section>
-      <div><button data-post="output?s=:syl3&p=:color" data-body="#000000">Send (:syl3 :color black)</button></div>
-      <div><button data-post="output?s=:syl3&p=:color" data-body="#ffffff">Send (:syl3 :color white)</button></div>
-    </section>
-    <section>
-      <div><button data-post="output?s=:syl4&p=:color" data-body="#000000">Send (:syl4 :color black)</button></div>
-      <div><button data-post="output?s=:syl4&p=:color" data-body="#ffffff">Send (:syl4 :color white)</button></div>
+      <section>
+        <div><button data-post="output?s=:asherCeiling&p=:color" data-body="0*3200K">Send (:asherCeiling :color black)</button></div>
+        <div><button data-post="output?s=:asherCeiling&p=:color" data-body="1*3200K">Send (:asherCeiling :color white)</button></div>
+      </section>
+      <section>
+        <div><button data-post="output?s=:noname1&p=:color" data-body="0*3200K">Send (:noname1 :color black)</button></div>
+        <div><button data-post="output?s=:noname1&p=:color" data-body="1*3200K">Send (:noname1 :color white)</button></div>
+      </section>
+      <section>
+        <div><button data-post="output?s=:noname2&p=:color" data-body="0*3200K">Send (:noname2 :color black)</button></div>
+        <div><button data-post="output?s=:noname2&p=:color" data-body="1*3200K">Send (:noname2 :color white)</button></div>
+      </section>
+      <section>
+        <div><button data-post="output?s=:noname3&p=:color" data-body="0*3200K">Send (:noname3 :color black)</button></div>
+        <div><button data-post="output?s=:noname3&p=:color" data-body="1*3200K">Send (:noname3 :color white)</button></div>
+      </section>
+      <section>
+        <div><button data-post="output?s=:noname4&p=:color" data-body="0*3200K">Send (:noname4 :color black)</button></div>
+        <div><button data-post="output?s=:noname4&p=:color" data-body="1*3200K">Send (:noname4 :color white)</button></div>
+      </section>
+          
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="0*2200K">Send (:stairTop :color black)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*200K">Send (:stairTop :color white 200K)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*1200K">Send (:stairTop :color white)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*2200K">Send (:stairTop :color white)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*3200K">Send (:stairTop :color white)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*4200K">Send (:stairTop :color white)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*5200K">Send (:stairTop :color white)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="1*6200K">Send (:stairTop :color white 6200K)</button></div>
+      <hr>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="0.8*3200K">Send (:stairTop :color white*.8)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="0.6*3200K">Send (:stairTop :color white*.6)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="0.4*3200K">Send (:stairTop :color white*.4)</button></div>
+      <div><button data-post="output?s=:stairTop&p=:color" data-body="0.2*3200K">Send (:stairTop :color white*.2)</button></div>
+      
     </section>
 
     <script>
--- a/service/rdf_to_mqtt/rdf_to_mqtt.py	Thu Sep 10 15:02:00 2020 -0700
+++ b/service/rdf_to_mqtt/rdf_to_mqtt.py	Sat Nov 28 01:34:31 2020 -0800
@@ -65,34 +65,38 @@
         'hasWhite': True,
     },
     # https://github.com/Koenkk/zigbee2mqtt.io/blob/new_api/docs/information/mqtt_topics_and_message_structure.md#general
-    ROOM['syl1']: {
-        'root': 'zigbee2mqtt/syl1/set',
+    ROOM['frontRoom1']: {
+        'root': 'zigbee2mqtt/frontRoom1/set',
         'hasBrightness': True,
         'defaults': {
             'transition': 0,
         }
     },
-    ROOM['syl2']: {
-        'root': 'zigbee2mqtt/syl2/set',
+    ROOM['frontRoom2']: {
+        'root': 'zigbee2mqtt/frontRoom2/set',
         'hasBrightness': True,
         'defaults': {
             'transition': 0,
         }
     },
-    ROOM['syl3']: {
-        'root': 'zigbee2mqtt/syl3/set',
+    ROOM['asherCeiling']: {
+        'root': 'zigbee2mqtt/asherCeiling/set',
         'hasBrightness': True,
         'defaults': {
             'transition': 0,
         }
     },
-    ROOM['syl4']: {
-        'root': 'zigbee2mqtt/syl4/set',
+    ROOM['stairTop']: {
+        'root': 'zigbee2mqtt/stairTop/set',
         'hasBrightness': True,
         'defaults': {
             'transition': 0,
         }
     },
+    ROOM['noname1']: { 'root': 'zigbee2mqtt/0xf0d1b8000001ffc6/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } },
+    ROOM['noname2']: { 'root': 'zigbee2mqtt/0xf0d1b80000023583/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } },
+    ROOM['noname3']: { 'root': 'zigbee2mqtt/0xf0d1b80000023708/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } },
+    ROOM['noname4']: { 'root': 'zigbee2mqtt/0xf0d1b80000022adc/set', 'hasBrightness': True, 'defaults': { 'transition': 0, } },
 }
 
 
@@ -130,26 +134,26 @@
                 ignored = False
             if stmt[0:2] == (dev, ROOM['color']):
                 h = stmt[2].toPython()
-                r, g, b = int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16)
-                msg = {
-                    'state': 'ON' if r or g or b else 'OFF',
-                    'color': {
-                        'r': r,
-                        'g': g,
-                        'b': b
-                    },
-                }
-                if attrs.get('hasBrightness', False):
-                    # todo- still not right for sylvania bulbs; they want color x-y.
+                msg = {}
+                if h.endswith(b'K'):  # accept "0.7*2200K" (brightness 0.7)
                     # see https://www.zigbee2mqtt.io/information/mqtt_topics_and_message_structure.html#zigbee2mqttfriendly_nameset
-                    msg['brightness'] = max(r, g, b)
-                    if msg['brightness'] != 0:
-                        scl = msg['brightness'] / 255
-                        for chan in ['r', 'g', 'b']:
-                            msg['color'][chan] = int(msg['color'][chan] / 255.0 / scl * 255)
+                    bright, kelvin = map(float, h[:-1].split(b'*'))
+                    msg['state'] = 'ON'                    
+                    msg["color_temp"] = round(1000000 / kelvin, 2)
+                    msg['brightness'] = int(bright * 255)  # 1..20 look about the same
+                else:
+                    r, g, b = int(h[1:3], 16), int(h[3:5], 16), int(h[5:7], 16)
+                    msg = {
+                        'state': 'ON' if r or g or b else 'OFF',
+                        'color': {
+                            'r': r,
+                            'g': g,
+                            'b': b
+                        },
+                    }
 
-                if attrs.get('hasWhite', False):
-                    msg['white_value'] = max(r, g, b)
+                    if attrs.get('hasWhite', False):
+                        msg['white_value'] = max(r, g, b)
                 msg.update(attrs.get('defaults', {}))
                 self._publish(topic=attrs['root'], message=json.dumps(msg))
                 ignored = False