This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Hue Brightness feedback
#21
Hi,

Can it be that your bri value gets negative? You substract 30 from the current bri but when it’s smaller then 30 you should round it to max 0. That is not handled in your current script. Also needed for dimming up to maximize to 100.

BR,

Erwin
Reply
#22
400 bad request is triggered by this line (invalid HTTP header):
Code:
['content-length'] = '',

Remove this line or replace empty string with 0 and try again.
Reply
#23
(03.12.2018, 07:49)admin Wrote: 400 bad request is triggered by this line (invalid HTTP header):
Code:
['content-length'] = '',

Remove this line or replace empty string with 0 and try again.

Worked like a charm! Weird though, that this line works fine at my place for some reason.

Erwin;

The HUE bridge handles the request even if I'm under the allowed value, so there's no errors. It just won't dim Wink
Reply
#24
Thank for your template, i can success to control multi Hue bridge, but i face othe problem, for now philip hue have other type only not for RGB, it's can change the color temperture form 2700K to 6500K, is there any script for those lighting?
Reply
#25
Hi
Here is a script which should convert color temperature to RGB. Never tested on real light but check if it will work.

Code:
Temperature = event.getvalue()


Temperature = Temperature / 100
   
  -- Calculate Red:

if Temperature <= 66 then
    Red = 255
else
 Red = Temperature - 60
 Red = 329.698727446 *  math.pow(Red, -0.1332047592)
 if Red < 0 then
   Red = 0
 end
 if Red > 255 then
   Red = 255
 end
end
   
   --Calculate Green:

if Temperature <= 66 then
  Green = Temperature
  Green = 99.4708025861 * math.log(Green) - 161.1195681661
 if Green < 0 then
   Green = 0
 end  
 if Green > 255 then
   Green = 255
 end  
else
  Green = Temperature - 60
  Green = 288.1221695283 * math.pow(Green, -0.0755148492)
  if Green < 0 then
   Green = 0
 end
 if Green > 255 then
   Green = 255
 end  
end
   
   --Calculate Blue:

if Temperature >= 66 then
  Blue = 255
else
  if Temperature <= 19 then
     Blue = 0
 else
     Blue = Temperature - 10
     Blue = 138.5177312231 * math.log(Blue) - 305.0447927307
     if Blue < 0 then
         Blue = 0
       end
     if Blue > 255 then
         Blue = 255
       end
 end
end

Red = math.floor(Red + 0.5)
Green = math.floor(Green + 0.5)
Blue = math.floor(Blue + 0.5)


Red = lmcore.inttohex(Red, 1)
Green = lmcore.inttohex(Green, 1)
Blue = lmcore.inttohex(Blue, 1)


RGB = lmcore.hextoint(Red..Green..Blue)

grp.update('RGB temp', RGB)

BR
------------------------------
Ctrl+F5
Reply
#26
Hello, I also have some problems with the feedback of the Hue lamp. 

I get the following error message. 


Quote:Resident script:22: bad argument #1 to 'decode' (string expected, got table)
stack traceback:
 [C]: in function 'decode'


I suspect the problem is the following line. 

  mylamps = json.decode(reply)

could someone take a look at my code? 
Is something wrong? 
I only have the user.hue in my user library.



Code:
-- Set name (Lookup in HUE app under light configuration) and feedback adresses (don't change statevalue, brivalue and colorvalue as they are used as memoryfield)
addressmapping = {
  -- Name   -- On/Off FB    -- Bright FB   -- Color FB
  ['Stehlampe Wohnzimmer'] = {state = '8/4/0', bri = '8/5/0', rgb = '8/2/0', statevalue = '', brivalue = '', colorvalue = ''},
--  ['Hue Küche'] = {state = '1/3/2', bri = '1/4/2', rgb = '1/5/2', statevalue = '', brivalue = '', colorvalue = ''},
--  ['Schalter Wohnzimmer'] = {state = '1/3/3', bri = '1/4/3', rgb = '1/5/3', statevalue = '', brivalue = '', colorvalue = ''},
--  ['Hue Schlafzimmer'] = {state = '1/3/4', bri = '1/4/4', rgb = '1/5/4', statevalue = '', brivalue = '', colorvalue = ''}
}

-- Set polling interval in seconds
interval = 1

-- Use logging
logging = true


require('user.hue')
require('json')
-- loop indefenitly
while true do
  reply = getHueLights()
  mylamps = json.decode(reply)
  
  for _, item in pairs(mylamps) do

    -- Check if lamp is found by bridge otherwise it make no sense to send commands
    if item.state.reachable == true then
      log(item.state.reachable)
      -- On/Off
      name = addressmapping[item.name]
      if name then
        addr = addressmapping[item.name]['state']
        if addr and addr ~= '' then
          currentvalue = addressmapping[item.name]['statevalue']
          if currentvalue ~= item.state.on then
            grp.update(addr, item.state.on)
            addressmapping[item.name]['statevalue'] = item.state.on
            if logging == true then
              log('lamp ' .. item.name .. ' state is: ' .. tostring(item.state.on))
            end
          end
        end
      end

      -- Brightness
      name = addressmapping[item.name]
      if name then
        addr = addressmapping[item.name]['bri']
        if addr and addr ~= '' then
          -- Check if lamp is on otherwise overrule BRI value to 0
          if item.state.on == false then
            item.state.bri = 0
          end
          currentvalue = addressmapping[item.name]['brivalue']
          if currentvalue ~= item.state.bri then
            grp.update(addr, math.floor((tonumber(item.state.bri)/2.55) + 0.5))
            addressmapping[item.name]['brivalue'] = item.state.bri
            if logging == true then
              log('lamp ' .. item.name .. ' brightness is: ' .. math.floor((tonumber(item.state.bri)/2.55) + 0.5) .. ' %')
            end
          end
        end
      end

      -- Color
      name = addressmapping[item.name]
      if name then
        addr = addressmapping[item.name]['rgb']
        if addr and addr ~= '' then
          -- Check if lamp is on otherwise overrule color value to 0
          if item.state.on == false then
             colorvalue = 0
          end
          if item.state.colormode == 'xy' then
            currentvalue = addressmapping[item.name]['colorvalue']
            colorvalue = xy_to_rgb(item.state.xy[1],item.state.xy[2],item.state.bri)
            --colorvalue = xyz_to_rgb((item.state.xy[1] * 100), (item.state.xy[2] * 100))
            if currentvalue ~= colorvalue then
              grp.update(addr, colorvalue)
              addressmapping[item.name]['colorvalue'] = colorvalue
              if logging == true then
                log('lamp ' .. item.name .. ' color is: ' .. colorvalue)
              end
            end
          elseif item.state.colormode == 'ct' then
            currentvalue = addressmapping[item.name]['colorvalue']
            --colortemp = math.floor((item.state.ct / 0.0769) + 0.5)  --0.0769230769230769
            colortemp = math.abs((item.state.ct - 500) / 2)
            colortemp = math.floor(colortemp + 0.5)
            colortemp = 80 + colortemp
            if colortemp > 255 then
              colortemp = 255
            end
            r = lmcore.inttohex(255, 1)
            g = lmcore.inttohex(255, 1)
            b = lmcore.inttohex(colortemp, 1)
            rgb = r .. g .. b
            colortemp = lmcore.hextoint(rgb,3)
            if currentvalue ~= colortemp then
              --colortempconverted = ct_to_rgb(colortemp)
              grp.update(addr, colortemp)
              addressmapping[item.name]['colorvalue'] = colortemp
              if logging == true then
                log('lamp ' .. item.name .. ' color is: ' .. colortemp)
              end
            end
          end
        end
      end
      
    end

    --log('manufacturername = ' .. item.manufacturername)
    --log('swversion = ' .. item.swversion)
    --log('type = ' .. item.type)
    --log('ct = ' .. item.state.ct)
    --log('reachable = ' .. item.state.reachable)
    --log('alert = ' .. item.state.alert)
    --log('on = ' .. item.state.on)
  --log('bri = ' .. item.state.bri)
    --log('colormode = ' .. item.state.colormode)
    --log('hue = ' .. item.state.hue)
    --log('sat = ' .. item.state.sat)
    --log('effect = ' .. item.state.effect)
    --log('x = ' .. item.state.xy[1])
    --log('y = ' .. item.state.xy[2])
    --log('uniqueid = ' .. item.uniqueid)
    --log('modelid = ' .. item.modelid)
    --log('name = ' .. item.name)

  end
-- Delay loop
os.sleep(interval)
end
Reply
#27
Hi
Make sure to use the latest version from here https://forum.logicmachine.net/showthrea...49#pid6549, some other users also reported this on old version.
BR
------------------------------
Ctrl+F5
Reply
#28
Hi,

I was wondering how to save the resident feedback script (what is the resident interval) since it has a resident function in itself. Or can I remove the infinite loop in case it is stored as a resident script?
Reply
#29
You can remove the loop and os.sleep at the end and set polling interval as needed (at least 1 second). It won't make a difference really.
Reply
#30
Thanks for the confirmation!
Reply
#31
Hey guys,
I tried the Hue script to start with my SE-Wiser for knx.
it took a while (I'm totally new to it and has to learn everything first) but it works!
And the feedback works great too.

Now my question. I also want to operate the Hue lamps via my KNX buttons (SE - 627644).  Preferably only via 1 button .... short press = on / off .... long press = dimming up / down.
The buttons in the ETS5 only have 1 bit for on / off and 4 bit for dimming.
On / off already works, but dimming doesn't work. The script uses 1byte for dimming, and I can't set that to a button. Or am I doing something wrong?
Reply
#32
Hi,

See this article for converting 4 bit to byte: (in SE pushbuttons we have this native, set function to 8-bit linear regulator )

https://forum.logicmachine.net/showthrea...27#pid8027

BR,

Erwin
Reply
#33
hey it worked great Big Grin Cool
But I didn't use the 8-bit linear regulator, it didn't work.
I have left the dimmer function for the switch and set the dimmer function to send cyclically. So it worked.
Big thanks again ... you guys are great  Big Grin Big Grin Big Grin
Reply
#34
Hi all,

Im trying to get this script to work, but as i'm a novice i need a little help. Last week i bought a Hue Bridge and a LED strip for outdoor use. It works with the Hue App and i know the IP of the Hue Bridge 

I copy/pasted file user.hue_v2.lua into user libraries; modified the IP-Adress, but i don't have the user.hue as the hue commands script gives error:

Code:
Hue discovery 08.06.2020 17:57:13
Resident script:2: module 'user.hue' not found:
no field package.preload['user.hue']
no file './user/hue'
no file 'Library user/hue'
no file 'User library hue'
no file 'Library user/hue.so'
no file 'Library user.so'
stack traceback:
[C]: in function 'require'

I copy/pasted file resident hue feedback_v2.lua into Resident script
I copy/pasted file hue commands_v2.lua (until the Event based parts) into Resident script. ==> See error above
Created 3 event based scripts from the remaining code in hue commands_v2.lua and modified the groupadresses to the correct ones for lamp 1.

What am i doing wrong and how do i get a user id for the homelynk?

Thx
Novice DIY with a HL and KNX basics trying to ...
Reply
#35
Hi,

You need to create the user library’user.hue’ to be able to use the scripts, when you start you need set the IP address of the bridge in the userlib and you need to to press the button on the HUE bridge and run bridgesetuo() to get the token that is also filled in the user library. When that is setup you can use the feedback and commands.

BR,

Erwin
Reply
#36
Ok, got it working now!

Thx for the help
Novice DIY with a HL and KNX basics trying to ...
Reply
#37
Hi,

Currently the feedback script uses the command getHueLights() to get the JSON response from the bridge for the induvidual lamps, and this response is processed further to sync the KNX objects according the light states.

If you want this also for groups you need to use the command getHueGroups() and change the feedback script so it will process the JSON response from the bridge in the same way, so this means you need to run getHueGroups(), check the result and modify the things you need to have.

So i'ts possible but takes a bit of work.

BR,

Erwin
Reply
#38
Hi,

I updated my Wiser to the lates firmware 2.5.1. and now I get this error in my hue feedback script.

Hue lamp feedback 30.07.2020 21:54:56
Resident script:21: Expected value but found T_END at character 1
stack traceback:
[C]: in function 'decode'


It has been working fine until the update.
I'm using the resident hue feedback_v2.lua

Any one experienced the same?

BR,Magnus
Reply
#39
Hi,

No not seen the issue yet, i use it at home and have upgraded to 2.5.1 so i don’t think it’s FW related..

I will check what might be the issue, could be i use a newer version..

BR,

Erwin
Reply
#40
Hi,

I checked and line 21 is handling the response of the function getHueLights() that is located in the user.hue, so i guess you use a older version of the user lib.

Can you try to replace your user.hue with this version? A restart might be required.

.lua   user.hue v4.lua (Size: 9.9 KB / Downloads: 47)

BR,

Erwin
Reply


Forum Jump: