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.

Philips HUE Lamps state
#14
Hi,
since I also needed the color temperature feedback, I modified the "Hue feedback" script as per attached code.

But the result is that it assigns to all "ctstate" addresses the same value, that is, that of the first.

The rest of the script works fine.
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
  ['Led Sinistro Down'] = {state = '11/4/10', bri = '11/4/14', rgb = '12/5/14', ct = '12/5/15', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},
  ['Led Centrale Down'] = {state = '11/4/20', bri = '11/4/24', rgb = '12/5/24', ct = '12/5/25', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},
  ['Led Destro Down'] = {state = '11/4/30', bri = '11/4/34', rgb = '12/5/34', ct = '12/5/35', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},
  ['Led Sinistro Up'] = {state = '12/4/10', bri = '12/4/14', rgb = '12/6/14', ct = '12/6/15', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},
  ['Led Centrale Up'] = {state = '12/4/20', bri = '12/4/24', rgb = '12/6/24', ct = '12/6/25', statevalue = '', brivalue = '', colorvalue = '', ctstate =''},
  ['Led Destro Up'] = {state = '12/4/30', bri = '12/4/34', rgb = '12/6/34', ct = '12/6/35', statevalue = '', brivalue = '', colorvalue = '', ctstate =''}
}

-- 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

      -- 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 TEMP. KELVIN
      name = addressmapping[item.name]
      if name then
        addr = addressmapping[item.name]['ct']
        if addr and addr ~= '' then

          currentvalue = addressmapping[item.name]['ctstate']
          if currentvalue ~= item.state.ct then
            grp.update(addr, tonumber(item.state.ct))
            addressmapping[item.name]['ctstate'] = item.state.ct
            if logging == true then
              log('lamp ' .. item.name .. ' ct is: ' .. item.state.ct)
            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

I have missing something...

Peppe

Attached Files Thumbnail(s)
   
Reply


Messages In This Thread
Philips HUE Lamps state - by gdimaria - 21.09.2021, 15:18
RE: Philips HUE Lamps state - by admin - 22.09.2021, 12:54
RE: Philips HUE Lamps state - by gdimaria - 22.09.2021, 15:34
RE: Philips HUE Lamps state - by gdimaria - 14.12.2021, 17:44
RE: Philips HUE Lamps state - by gdimaria - 15.12.2021, 14:47
RE: Philips HUE Lamps state - by admin - 15.12.2021, 05:50
RE: Philips HUE Lamps state - by gdimaria - 15.12.2021, 13:53
RE: Philips HUE Lamps state - by gdimaria - 16.12.2021, 07:02
RE: Philips HUE Lamps state - by gdimaria - 16.12.2021, 12:32
RE: Philips HUE Lamps state - by gdimaria - 25.01.2022, 13:09

Forum Jump: