Yeelight

From Domoticz
Jump to navigation Jump to search

Yeelight LED Bulbs

These are WiFi enabled LED Bulbs that come with excellent supporting software, and can also be controlled from Domoticz. Currently working with the White and Color LED Bulbs http://www.yeelight.com/en_US

Compatible Lights

  1. LED Bulb (White)
  2. RGBW LED Bulb (Color)
  3. LED Desk Lamp
  4. Lightstrip (Color)
  5. LED Ceiling Light

The Bedside Lamp is not compatible with this Domoticz plugin as it uses Bluetooth instead of WiFi.

But your lights at gearbest and you help the Domoticz community.

Adding Yeelight Bulbs in Domoticz

You first need to enable developer mode on your bulbs through the Yeelight Android or iOS App. http://www.yeelight.com/en_US/developer. If developer mode is not enabled, Domoticz will not be able to communicate with your lights.

Then go to Setup -> Hardware, and choose the Yeelight LED Type. Enter a name (such as 'Yeelight Controller'), and then click Add.

Note that the IP address of the light is used as the device ID in Domoticz. For that reason, use static IP addresses for your lights (assign via MAC address reservation on your router). See next section if you did that too late and need to change IP addresses.

After a minute, Domoticz should start detecting your bulbs and be visible under Setup -> Devices

If your Yeelight is not found automatically, try adding it manually by clicking the 'Add Light' button


Modifying Yeelight Bulbs IP address in Domoticz

If after having setup correctly a Yeelight Bulb, one day, you have to (or just want to) change it's IP addresses without removing the bulb all its configuration and history, you will have to follow these steps:

  • Stop Domoticz service (sudo service domoticz stop)
  • Backup Domoticz database (DB is located into domoticz root directory, simply do cp domoticz.db domoticz.db-bak)
  • Get a copy of that database (domoticz.db) onto your main computer
  • Open it with an sql-lite browser software (DB Browser for SQLite for instance)
  • Go into "DeviceStatus" table
  • You now have to adjust the "DeviceID" with the new IP.
    IP addresses are stored into their Hexadecimal representation. That way "C0A8051B" means "192.168.5.27".
    See IPv4 address representations on Wikipedia for more informations. (and you can use an online converter of course)
  • Save all the modifications
  • Put the modified database back into Domoticz directory and make sure that the file is named "domoticz.db"
  • Start Domoticz service (sudo service domoticz start)
  • Enjoy !

This procedure can come in handy if, for instance, you change ISP and you have to reconfigure the router but want to makes things neater!

It is also a way of solving the error message: "Error: YeeLight: Exception: connect: No route to host"

Adding White Temperature Control (RGBW Bulb Only)

Important note : Those scripts will not work on the windows version of Domoticz

First You have to add a dummy selector switch, and set it as a dimmer on switch page

And get your yeelight IP (Fing app on Android do the job)

Then create a LUA Script via Domoticz event Editor:

This script turn Bulb ON if you choose a value from 1% to 100%. This script turn Bulb OFF if you set the dimmer to 0%. This Dimmer can be call on scene, groupe, events, or API call

commandArray = {}
DomDevice = 'nameofyourdummyselectorsetasdimmer';
IP = 'youryeelightip';
PORT = '55443'

if devicechanged[DomDevice] then
   if(devicechanged[DomDevice]=='Off') then 
     DomValue = 0;
     runcommandoff = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";;
     os.execute(runcommandoff);
   else
     DomValue = otherdevices_svalues[DomDevice];   
   CalcValue = ((DomValue-1) * 48)+1700;
   end
   if CalcValue==nil then CalcValue=0 end
     runcommand = " sudo echo -ne '{\"id\":1, \"method\":\"set_scene\",\"params\":[\"ct\"," .. CalcValue .. ", 75]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
   os.execute(runcommand);
   print(runcommand)
   print("Color Temp= "..CalcValue);
end
return commandArray

Here is the same script updated to DZVents:

return {
    active = true,
    on = {
        devices = { 'YeelightTemperature'}
    },
    execute = function(domoticz, device)
        port = '55443'
        yeelights = {'192.168.xxx.xxx'}
        for ix, ipadress in ipairs(yeelights) do
            if (device.state == 'Off') then
                domoticz.log('Turning light off')
                runcommand = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            else
                domoticz.log('Changing color level')
                calcvalue = ((device.level - 1) * 48)+1700;
                runcommand = " sudo echo -ne '{\"id\":1, \"method\":\"set_scene\",\"params\":[\"ct\"," .. calcvalue .. ", 75]}\\r\\n' | nc -w1 " ..ipadress.." " ..port..""
                os.execute(runcommand)
            end
        end
    end
}

Adding simple Dimmer Control (RGBW Bulb Only)

First You have to add a dummy selector switch, and set it as a dimmer on switch page

And get your yeelight IP (Fing app on Android do the job)

Then create a LUA Script via Domoticz event Editor:

This Script change Brightness Bulb from 0 to 100% This Script turn ON Bulb set it to dimmer value and White Temperature choose on the previous slider. This Dimmer can be call on scene, groupe, events, or API call

commandArray = {}
DomDevice = 'Yeelight Dimmer';
TempDevice = 'White Temp Yeelight'
IP = '192.168.0.207';
PORT = '55443'

if devicechanged[DomDevice] then
   if(devicechanged[DomDevice]=='Off') then 
     DomValue = 0;
     runcommandoff = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";;
     os.execute(runcommandoff);
   else
    TempValue = otherdevices_svalues[TempDevice];   
    CalcValue = ((TempValue-1) * 48)+1700;
    DomValue = otherdevices_svalues[DomDevice]; 
   end
   if CalcValue==nil then CalcValue=0 end
     
     runcommand = "sudo echo -ne '{\"id\":1, \"method\":\"set_scene\", \"params\":[\"ct\", " .. CalcValue .. ", " .. DomValue .. "]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
      os.execute(runcommand);
   print(runcommand)
   print("bright value= "..DomValue);
end
return commandArray

Adding Scenes

Yeelight Bulb offer an API, who allow use to made scene : http://www.yeelight.com/download/Yeelight_Inter-Operation_Spec.pdf

Idea here is to reproduce scene who are stored on Yeelight App.

For White Bulb (Mono)

First You have to add a dummy selector switch and set it like this :

And get your yeelight IP (Fing app on Android do the job)

Then create a LUA Script via Domoticz event Editor, don't forget to set your script as de device one !

commandArray = {}
DomDevice = 'Yeelight Mono Scenes';
IP = 'Your Yeelight IP';
PORT = '55443'
 
if devicechanged[DomDevice]=='Off' then -- turn off
     runcommandoff = "sudo echo -ne '{\"id\":1,\"method\":\"set_power\", \"params\":[\"off\", \"smooth\", 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommandoff);
   --  print(runcommandoff) 
     
     elseif devicechanged[DomDevice]=='Sunrise' then -- turn to sunrise mode from 0 to 100% on 15 minutes
     runcommandsunrise = " sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"cf\",2,1,\"50,2,4000,1,900000,2,4000,100\"]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommandsunrise);
   --  print(runcommandsunrise) 
     
     elseif devicechanged[DomDevice]=='Sunset' then -- turn to sunset mode from 100% to 0 on 15 minutes and turn off bulb
     runcommandsunset = " sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"cf\",2,2,\"50,2,4000,75,900000,2,4000,1\"]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommandsunset);
   --  print(runcommandsunset) 
   
    elseif devicechanged[DomDevice]=='Bright 25%' then -- turn to 25% bright
     runcommand25 = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"bright\", 25, 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommand25);
    -- print(runcommand25) 
     
     elseif devicechanged[DomDevice]=='Bright 50%' then -- turn to 50% bright
     runcommand50 = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"bright\", 50, 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommand50);
    -- print(runcommand50) 
     
    elseif devicechanged[DomDevice]=='Bright 75%' then -- turn to 75% bright
     runcommand75 = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"bright\", 75, 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommand75);
    -- print(runcommand75) 
     
    elseif devicechanged[DomDevice]=='Baby' then -- turn to Baby Mode
     runcommandbaby = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"bright\", 1, 500]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommandbaby);
    -- print(runcommandbaby) 
     
    elseif devicechanged[DomDevice]=='4-7-8' then -- turn to 4-7-8 mode
     runcommand478 = "sudo echo -ne '{\"id\":1,\"method\":\"set_scene\", \"params\":[\"cf_\",24,2,\"4000,2,4000,30,7000,2,4000,10,8000,2,4000,1\"]}\\r\\n' | nc -w1 " ..IP.." " ..PORT.."";
     os.execute(runcommand478);
    -- print(runcommand478) 
     
end
return commandArray

I add a 4-7-8 fonction, who is a helping to sleep methode base on breath : http://www.medicaldaily.com/life-hack-sleep-4-7-8-breathing-exercise-will-supposedly-put-you-sleep-just-60-332122

Exhale completely through your mouth, making a whoosh sound.

Close your mouth and inhale quietly through your nose to a mental count of four : light is on 30% bright

Hold your breath for a count of seven : light is on 10% bright

Exhale completely through your mouth, making a whoosh sound to a count of eight : light is on 1% bright

After 8 cycles : Bulb will turn OFF because you are sleeping