f.lux style light management

Moderator: leecollings

Post Reply
foxingdemon
Posts: 3
Joined: Thursday 27 September 2018 14:33
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

f.lux style light management

Post by foxingdemon »

I tried to search on the forum but couldn't find. Has anyone got a solution to control Yeelight lamps like f.lux does with Hue. Or using f.lux API?
tiberx
Posts: 2
Joined: Saturday 03 November 2018 21:22
Target OS: Windows
Domoticz version: 4.9700
Contact:

Re: f.lux style light management

Post by tiberx »

That's how I do it with my milight bulbs:

Code: Select all

return {
   on = {
      timer = { '20 minutes before sunset', '10 minutes before sunset', 
                'every minute between sunset and 21:30'}
    },
   
   execute = function(domoticz, roomSwitch)
    local Time = require('Time')
    local currentTime = Time()
    Stunden = os.date("%H",os.time(currentTime))
    Minuten = os.date("%M",os.time(currentTime))
    GesamtMinuten = Stunden*60+Minuten -- minutes today from midnight until now 
    Differenz = 1290-GesamtMinuten -- time between desired EndTime of transition to WarmWhite (in minutes, calculated hour*60+minutes) and current time (in minutes)
    LightTemp = -1/3*Differenz+100 -- calculation of LightTemp according to time of the day. Transition starts 5 hours (300 minutes) before desired end time
      
    if (currentTime.matchesRule('at 07:00-21:30')) then domoticz.devices('RGB-CCT 2').setKelvin(LightTemp)
    end

   end
}
The problem I have is, that the light is automatically turned on all the time - even if I don't want it to be. My dream is: I can manually turn on the lights by using the remote/milight-app and the script only adjusts the color temperature.

I guess the reason is the command

Code: Select all

//First send ON , sleep 100ms, then the command
Send_V6_RGBWW_On(pLed->dunit, 100);
(https://github.com/domoticz/domoticz/bl ... itless.cpp) that is sent all the time before the actual command.
Why is this written this way? It's not the behavior that I know from the remote/milight-app, where I can press the color/... buttons but the light doesn't turn on - since I don't want it to be turned on.

Could this specific code been taken out before all the different functions (like switch to white, choose color, ...)? If I want to have the lights turned on in a script I can add this command by myself.

If not: Is there a workaround so that only the light temperature (or everything else) can be controlled without turning it on all the time?
Boredcat
Posts: 38
Joined: Friday 17 March 2017 9:31
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Netherlands
Contact:

Re: f.lux style light management

Post by Boredcat »

Try something like this. There might be syntax errors in the script, but the idea might work.

The script is now actived by a switch command. Which set the kevin value every minute.

There are still some flaws in the script, if sunset is after 21:30 you encounter errors (negative time).

Code: Select all

return {
   on = {
      device = {'RGB-CCT 2'}



    },
   
   execute = function(domoticz, roomSwitch)
    local light = dz.devices('RGB-CCT 2')
    local Time = require('Time')
    local currentTime = Time()

    -- Cancel All Commands to light
    light.cancelQueuedCommands()

    Stunden = os.date("%H",os.time(currentTime))
    Minuten = os.date("%M",os.time(currentTime))
    GesamtMinuten = Stunden*60+Minuten -- minutes today from midnight until now 
    Differenz = 1290-GesamtMinuten -- time between desired EndTime of transition to WarmWhite (in minutes, calculated hour*60+minutes) and current time (in minutes)

   if (currentTime.matchesRule('after sunset') and light.state <> 'Off') then

     for i = 1,Differenz,1 do

       LightTemp = -1/3*Differenz+100 -- calculation of LightTemp according to time of the day. Transition starts 5 hours (300 minutes) before desired end time
      
       light.setKelvin(LightTemp).afterMin(i)
    end
  end

   end
}
RFXCom(E) - Yeelight Lights - KaKu / Alexa HA Bridge
Windows 2012 / Windows 2012R2 / Xpenology/ Pi 3 / Milight / Home build ESP8266 / Sonoff
tiberx
Posts: 2
Joined: Saturday 03 November 2018 21:22
Target OS: Windows
Domoticz version: 4.9700
Contact:

Re: f.lux style light management

Post by tiberx »

Good idea!
But I guess that the command

Code: Select all

if (currentTime.matchesRule('after sunset') and light.state <> 'Off') then
only works if I turn on/off the bulbs through Domoticz and not by the remote/app, right? Because the bulbs don't send a state change to the box/Domoticz
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest