Author Topic: Blink hue lights and revert to prior light status  (Read 579 times)

Offline shillingcl

  • Newbie
  • *
  • Posts: 2
  • Karma: +0/-0
Blink hue lights and revert to prior light status
« on: December 10, 2017, 02:42:37 pm »
I've been looking for an easy way to Vera to blink my hue lights with a specific color when driveway motion is detected.  Blinking the lights is fairly straightforward, but reverting them back to the prior light color and brightness is more difficult.  Some others may have suggestions for simplified ways to do this, but this was the best I could cobble together based on the limited information I could find.

Code: [Select]
-- Blink hue lights and revert to prior light settings
local blinkColorHue = "44000"
local blinkColorSat = "254"
local blinkCount = 4
-- Insert the device id's of your hue lights below to replace the 271 and 272.  Add more with additional commas
local lightIDs = {271, 272}

--Capture current light levels and color for hue lights
local curLightStatus = { }
for i, lightID in ipairs(lightIDs) do   
    local curDimLevel = luup.variable_get("urn:upnp-org:serviceId:Dimming1","LoadLevelStatus", lightID)
    local curLampValuesString = luup.variable_get("urn:micasaverde-com:serviceId:PhilipsHue1","LampValues", lightID)
    local curLampValues = {}
        for k, v in string.gmatch(curLampValuesString, "(%w+):(%w+)") do
            curLampValues[k] = v
        end   
    local curHue = curLampValues["hue"]
    local curSat = curLampValues["sat"]
    curLightStatus[lightID] = {curDimLevel, curHue, curSat}
end

--Set lights to blink color and sat
for i, lightID in ipairs(lightIDs) do 
    luup.call_action("urn:micasaverde-com:serviceId:PhilipsHue1", "SetHueAndSaturation", {Hue=blinkColorHue ;Saturation=blinkColorSat ;Effect=""}, lightID)
    luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "100"}, lightID)
end
luup.sleep(900)

--Perform set number of blinks
for bc=1, blinkCount do
    for i, lightID in ipairs(lightIDs) do
        luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "0"}, lightID)
    end
luup.sleep(900)
    for i, lightID in ipairs(lightIDs) do
        luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = "100"}, lightID)
    end
luup.sleep(900)
end

--Revert lights back to prior settings
for i, lightID in ipairs(lightIDs) do
    luup.call_action("urn:micasaverde-com:serviceId:PhilipsHue1", "SetHueAndSaturation", {Hue=curLightStatus[lightID][2];Saturation=curLightStatus[lightID][3];Effect=""}, lightID)
    luup.call_action("urn:upnp-org:serviceId:Dimming1", "SetLoadLevelTarget", {newLoadlevelTarget = curLightStatus[lightID][1]}, lightID)
end

Hope this helps some others