sidoh / esp8266_milight_hub

Replacement for a Milight/LimitlessLED hub hosted on an ESP8266
MIT License
948 stars 220 forks source link

Lots off lag #329

Closed poudenes closed 6 years ago

poudenes commented 6 years ago

Hi All,

Finally have add al my 35 bulbs into Domoticz. Have 11 Device ID's (virtual remotes). Everything work great using the WebUI. But now when i add everything into Domoticz that when i use Scripts to automate everything there is lot of lag.

Here a example of a script that control my bulbs when using Kodi:

local Version = '18.09.04'

return {
    active = true,
    on = {
        devices = {[KodiStatus] = { 'at nighttime' }},
    },
    -- logging = {marker = 'KODI Control ' ..Version..'...........'},
    execute = function(domoticz, device)

    if (domoticz.devices(SceneMovie).active and domoticz.devices(LogitechKodi).active) then
        if (domoticz.devices(KodiStatus).state == 'Paused') then 
            domoticz.variables(VarKodiStop).set(0)
            domoticz.variables(VarKodiPlay).set(0)
            domoticz.helpers.Kelvin(domoticz,BulbKitchenSinkAll,nil,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Kelvin(domoticz,BulbKitchenAll,nil,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbLivingroomAll,nil,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbBalcony,100,'Blue',nil)
            if (domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.Off(domoticz,BulbDressoirAll,nil,nil,nil) -- ESP MILIGHT GATEWAY
            elseif (not domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.RGB(domoticz,BulbDressoirAll,100,'Blue',nil) -- ESP MILIGHT GATEWAY
            end
            -- domoticz.log('------------------------==<[ KODI STAAT OP PAUZE ]>==-----------------------', domoticz.LOG_FORCE)

        elseif (domoticz.devices(KodiStatus).state  == 'Video' and domoticz.variables(VarKodiPlay).value == 0) then
            domoticz.variables(VarKodiStop).set(0)
            domoticz.variables(VarKodiPlay).set(1)
            domoticz.helpers.Off(domoticz,BulbKitchenSinkAll,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Off(domoticz,BulbKitchenAll,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Off(domoticz,SwitchCooker,nil,nil)
            domoticz.helpers.RGB(domoticz,BulbWallRight,70,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbWallLeft,70,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbWindowLeft,20,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbWindowRight,20,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbBalcony,25,'Blue',nil)
            if (domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.Off(domoticz,BulbDressoirAll,nil,nil,nil) -- ESP MILIGHT GATEWAY
            elseif (not domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.RGB(domoticz,BulbDressoirAll,25,'Blue',nil) -- ESP MILIGHT GATEWAY
            end
            -- domoticz.log('------------------------==<[ KODI IS FILM AAN AFSPELEN ]>==-----------------', domoticz.LOG_FORCE)

        elseif (domoticz.devices(KodiStatus).state  == 'TV Shows' and domoticz.variables(VarKodiPlay).value == 0) then
            domoticz.variables(VarKodiStop).set(0)
            domoticz.variables(VarKodiPlay).set(1)
            domoticz.helpers.Off(domoticz,BulbKitchenSinkAll,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Off(domoticz,BulbKitchenAll,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Off(domoticz,SwitchCooker,nil,nil)
            domoticz.helpers.RGB(domoticz,BulbWallRight,70,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbWallLeft,70,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbWindowLeft,50,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbWindowRight,50,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbBalcony,25,'Blue',nil)
            if (domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.Off(domoticz,BulbDressoirAll,nil,nil,nil) -- ESP MILIGHT GATEWAY
            elseif (not domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.RGB(domoticz,BulbDressoirAll,25,'Blue',nil) -- ESP MILIGHT GATEWAY
            end
            domoticz.helpers.Off(domoticz,SwitchToilet)
            -- domoticz.log('------------------------==<[ KODI IS SERIE AAN AFSPELEN ]>==----------------', domoticz.LOG_FORCE)

        elseif (domoticz.devices(KodiStatus).state  == 'On') then
            domoticz.variables(VarKodiStop).set(1)
            domoticz.variables(VarKodiPlay).set(0)
            domoticz.helpers.Off(domoticz,SwitchToilet)
            domoticz.helpers.Off(domoticz,BulbKitchenSinkAll,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Off(domoticz,BulbKitchenAll,nil,nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.Off(domoticz,SwitchCooker,nil,nil)
            domoticz.helpers.RGB(domoticz,BulbLivingroomAll,nil,'Green',nil) -- ESP MILIGHT GATEWAY
            domoticz.helpers.RGB(domoticz,BulbBalcony,75,'Blue',nil)
            if (domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.Off(domoticz,BulbDressoirAll,nil,nil,nil) -- ESP MILIGHT GATEWAY
            elseif (not domoticz.devices(SensorDiningRoomDoor).active) then
                domoticz.helpers.RGB(domoticz,BulbDressoirAll,75,'Blue',nil) -- ESP MILIGHT GATEWAY
            end
            -- domoticz.log('------------------------==<[ KODI SPEELT NIKS AF ]>==-----------------------', domoticz.LOG_FORCE)
        end
    end
end
}

The lines domoticz.helpers.RGB Have 2 actions:

local COLORS = {
                ['White']       = {255, 225, 255},
                ['Blue']        = {12, 0, 179},
                ['Green']       = {150,255,142},
                ['Romantic']    = {128,0,0}
            }

return {
    helpers = {

        RGB = function(domoticz,idx,dim,color,sec)
            if (dim == nil)     then dim = 100 end
            if (color == nil)   then rgb = COLORS['White']  else rgb = COLORS[color] end
            if (sec == nil)     then sec = 0 end
            domoticz.devices(idx).setRGB(rgb[1], rgb[2], rgb[3]).afterSec(sec)
            domoticz.devices(idx).dimTo(dim).afterSec(sec)
            status = 'aangezet'
            movement = 'beweging gedecteerd'
        end

The first line setRGB work. The second dimTo take some time before it start. Its always the second action that take some time.

When i reset the ESP8266 module, eveything work great for couple of minutes and then it get into trouble again.

My question now: Do i ask to many of the ESP8266 module to handle all the actions i send by Domoticz to ESP or is this a problem of the software of the Gateway emulator that give this lag problem?

sidoh commented 6 years ago

Probably some duplicated discussion in #304.

What you're probably seeing is the network stack on the ESP getting overwhelmed.

The most I have to offer in terms of existing solutions is this: https://github.com/sidoh/esp8266_milight_hub/wiki/Performance-Tuning

What integration is Domoticz using under the hood? MQTT or UDP?

poudenes commented 6 years ago

In domoticz i have MQTT installed and for the Gateway V6 because of my RGB-CCT bulbs. I dont know how to config MQTT on the ESP8266 so Domoticz will pick this up, or how this will work.

poudenes commented 6 years ago

Is there a better NRF24L01+ module to use? Also have idea that the singal is not strong enough. Sometimes bulbs don't go on/off or react on color/bright/kelvin changes.

PetricaM commented 6 years ago

Hi, Adding more bulbs on the same group should not have any impact on the latency. However, I think that the range of these cheap NRF24L01 modules (even the "+" ones) is not quite as good as advertised. I suggest first try to send the payloads straight to the MQTT broker. If that works fine, without delays, then the problem is in another place. Adding a capacitor between VCC and GND pins surely helps. Using a more powerful ESP8266 board (such as Wemos D1 R2) powered with a higher voltage power supply (12V) helps even more as NRF24L01 needs a stabilized power supply. Then use additional gateways in a mesh network would improve both range and reliability.

MimbaMonkeyHouse commented 6 years ago

Range is indeed rubbish. I have been using 3 of these boxes in a mesh. Doing this with MQTT is hassle-free. My only issue is with kids moving the boxes ever so slightly. The slightest change of angle or move seems to have big effects as to signal reach. I'm considering screwing them into walls so they stopped being moved around. I may have to get a fourth one set up as I get some shaded areas at the back of my garden.

poudenes commented 6 years ago

I've now add a NRF24L01 where i can screw a antenna on. This improve the signal also.

@MimbaMonkeyHouse Do you know how to config the Milight Gateway Emu's MQTT so it can used with Domoticz?

@PetricaM Do you know how to wire the NRF24L01 to a Wemos D1 R2?

I will order a Wemos D1 R2 and test how this will work then. I love this project so much and totally open to test whatever it needs. Im not a technical high class user :)

PetricaM commented 6 years ago

Wiring for D1 R2 is the same as for the other boards. Just remember to use the pins SCK/D5, MISO/D6 and MOSI/D7 not the ones with single values.

http://modtronix.com.au/product/wemos-d1r2/

poudenes commented 6 years ago

Thanks. Ans CE and CSN? I ordered now the Wemos d1r2... give it a try :)

PetricaM commented 6 years ago

D8 to CSN; D0 to CE

Here's the full wiring:

ESP         NRF24L01
3V->            VCC
GND->           GND
D0->            CE
SCK/D5->    SCK
MISO/D6->       MISO
MOSI/D7->   MOSI
SS/D8->         CSN
poudenes commented 6 years ago

Thank you so much!!! When i have the module ill let you all know how it work. For now i have add a "Dipole antenne 433 Mhz" antenna to the NRF24L01 and is already better

fliphess commented 6 years ago

FWIW: What added a huge performance gain for me was replacing my 1A power supply for a 2,5A one. Second: my RGBW bulbs are able to pair to multiple channels (2 or 3) which makes a huge difference when controlling a larger group of bulbs (6 and up) at once.

PetricaM commented 6 years ago

able to pair to multiple channels (2 or 3) which makes a huge difference when controlling a larger group of bulbs (6 and up) at once.

What do you mean?

I don’t think you can choose channel used by bulb or remote.

poudenes commented 6 years ago

Now my Wemos is running with NRF24L01 and a Dipole antenne 433 Mhz. Did have some issues with bulbs inside a group that not go on or of. Changed some values in WebUI:

Packet repeat -> 25 Packet repeat throttle sensitivity -> 0

For now it seems all good now. But i will post my experiences later :)

fliphess commented 6 years ago

@PetricaM My milight 9W RGBW bulbs can be paired to multiple channels (i believe 3 in total), so I pair them to a channel to control them as a single entity, and to a channel that multiple bulbs are paired to, this way instead of sending to a channel for each of the 12 bulbs, i send to one that all the bulbs are responding to. It's worth a try to see whether your bulbs/strips/etc support this as it saves lots of overhead.

In Hass/Domotics/Homeautomation you can then add both the entities: The one to control a group at once and the one to control a single bulb/strip/etc

poudenes commented 6 years ago

@fliphess you mean by channels = group ? I have add also bulbs into more then 1 group to combine them. You can add bulbs without limit into groups. Some of my bulbs are added into 5 different groups.

PetricaM commented 6 years ago

Sorry @fliphess , it was a misunderstanding. You were referring to infividual groups (1 for B0/FUT088, 4 for most remotes, 8 for B8/FUT089) and group 0. One remote can be paired to an unlimited number of bulbs however one bulb can be paired to up to 4 different remotes.

I was referring to channels on the 2.4 Ghz RF sprectrum used by MiLight (there have been some discussions in regard of channel hopping).

sidoh commented 6 years ago

Feel free to continue discussing, but I'm going to close as I'm not sure I see a clear course of action. Please feel free to reopen if I'm mistaken.