LUA and dim Hue light bulbs

Moderator: leecollings

Post Reply
rotero
Posts: 10
Joined: Saturday 13 June 2015 13:44
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.2284
Contact:

LUA and dim Hue light bulbs

Post by rotero »

Hi,

I have a Domoticz/Philips Hue question.
On the second floor I want to use a Philips Hue (white) light bulb with an KlikAanKlikUit motion sensor. No problems so far (I have this already working on the first floor).

The difference between the first floor and the second floor: on the second floor I want to change the dim level (5% or 75%) depending on the time.

I thought to use this solution:
- Create in the Hue app a scene for the Hue light bulb with 5% dim level [SCENE 1]
- Create in the Hue app a scene for the Hue light bulb with 75% dim level [SCENE 2]
- Between 06.00 and 23.00 hrs I switch on [SCENE 1] after a motion is detected
- Between 23.00 and 06.00 hrs I switch on [SCENE 2] after a motion is detected

You cannot turn off a Hue scene, so in stead of that I turn off the Hue light bulb after 5 minutes (after motion is deteced). This solution is not working. I also tried a lot of other options, but nothing works the way I like it to work.

Is it possible to create a solution to dim a Hue light blub in LUA for my problem with a standard Domoticz installation on a Raspberry Pi 2B?
If not, what should I do? Please tell me when it is neccesary to install additional plugins/programs.

This option isn't also working: turn on a scene with "ON FOR 5"

I am using the new Domoticz version v3.8153.
Thanks in advance for your help!

Regards,
Rob


LUA SCRIPT:

commandArray = {}
l_time = os.date("*t")

if (otherdevices['KAKU MOTION SENSOR 2'] == "On" and otherdevices['LIGHT 2'] == "Off") then
if (l_time.hour >= 23 or l_time.hour < 6) then
commandArray['SCENE 2'] = "On"
elseif (l_time.hour >= 6 and l_time.hour < 23) then
commandArray['SCENE 1'] = "On"
end
commandArray['LIGHT 2'] = "Off AFTER 300"
end

return commandArray
scottydj2
Posts: 15
Joined: Monday 06 February 2017 11:09
Target OS: Windows
Domoticz version:
Contact:

Re: LUA and dim Hue light bulbs

Post by scottydj2 »

Hi,
I use dzVents scripting to directly control my hue lights and just change dim level depending on the time rather than using scenes. I'll upload my script later when I'm home if no-one else chimes in.
Cheers
Scott
rotero
Posts: 10
Joined: Saturday 13 June 2015 13:44
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.2284
Contact:

Re: LUA and dim Hue light bulbs

Post by rotero »

Hi Scott,

That would be great.
In the meantime I'm checking out: https://www.domoticz.com/wiki/%27dzVent ... _Hue_Light

Thanks.

Regards,
Rob
scottydj2
Posts: 15
Joined: Monday 06 February 2017 11:09
Target OS: Windows
Domoticz version:
Contact:

Re: LUA and dim Hue light bulbs

Post by scottydj2 »

Hi Rob,

Sooooo.... my script is a lot messier than I remember it....

I've taken the section below to show how I check the time and switch dim percentage based on time.

Code: Select all

local normal_percentage = 67
local dim_percentage = 9

local min_dim_hour = 1
local max_dim_hour = 6

-- Device IDs below
local light = 26 

-- Do we need the light on?
	if (domoticz.data.stored_lux < min_lux) and (domoticz.devices(light).state == 'Off') then
		if (domoticz.time.hour >= min_dim_hour) and (domoticz.time.hour <= max_dim_hour) then
			domoticz.log('Light on dim', domoticz.LOG_FORCE)
			domoticz.devices(light).dimTo(dim_percentage)
		else
			domoticz.log('Light on normal', domoticz.LOG_FORCE)
			domoticz.devices(light).dimTo(normal_percentage)
		end      
	end
The full script uses the Hue motion and lux sensors as well as a door contact sensor.

The device(x).dimTo is a dzVents command which you could convert to a raw LUA equivalent, but I'd recommend giving dzVents a go :)

Regards,

Scott
rotero
Posts: 10
Joined: Saturday 13 June 2015 13:44
Target OS: Raspberry Pi / ODroid
Domoticz version: V2.2284
Contact:

Re: LUA and dim Hue light bulbs

Post by rotero »

Hi Scott,

Thanks for your help, it's working perfect now!
Yesterday I switched to the new version of Domoticz and I hadn't discovered dzVents scripting yet.

It isn't a problem, but I can't use a dim level below 7%?

Thanks again.

Regards,
Rob


This is my code:

Code: Select all

return {
    active = true,
    on = {
        devices = {
            'KAKU MOTION SENSOR 2'
        }
    },
    execute = function(domoticz, device)
        if (device.state == 'On') and (domoticz.devices('LIGHT 2').state == 'Off') then
            if (domoticz.time.hour >= 23) or (domoticz.time.hour <= 6) then
                domoticz.log('LICHT aan BG1 Dim level 7', domoticz.LOG_FORCE)
                domoticz.devices('LIGHT 2').dimTo(7).forMin(2)
            else
                domoticz.log('LICHT aan BG1 Dim level 80', domoticz.LOG_FORCE)
                domoticz.devices('LIGHT 2').dimTo(80).forMin(5)
            end      
        end
    end
}
scottydj2
Posts: 15
Joined: Monday 06 February 2017 11:09
Target OS: Windows
Domoticz version:
Contact:

Re: LUA and dim Hue light bulbs

Post by scottydj2 »

Hi Rob,

Glad it's working for you.

In the hue api, brighness levels go between 0 and 255, but 0 and 1 are the same (lowest setting) and 255 and 254 are considered the same (highest setting) and due to rounding conversions, I *think* anything below 7 get translated into a 0, and becomes an off.

The hue code may have a few errors around these points (assuming a range of 255 rather than 254).

Cheers

Scott
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest