Page 1 of 1

local function

Posted: Saturday 10 March 2018 18:15
by poudenes
Hi All,

Me again. Im trying to let this work. I have a test switch "testswitch" and when i switch it on i want to do a action for a bulb "BulbBathroomSink"
Everything i try i get the IDX of testswitch and not from the BulbBathroomSink.

If this working i can add the setRGB colors etc to make it easier.

Can someone assist me with this :geek:

Code: Select all

local Version                   = '18.03.06'
local testswitch                = 316

return {
    active = true,
    on = {
        devices = {testswitch},
        },
    logging = {marker = 'TEST ' ..Version..'..'},
    execute = function(domoticz,device)

local BulbBathroomSink          = domoticz.devices(28)

local function Test1(domoticz,idx)
       domoticz.devices(idx).setRGB(255,255,255)
end

local function Test2(domoticz,idx)
       domoticz.devices(idx).setRGB(242, 7, 7)
end
    if (device.active) then
        Test1(BulbBathroomSink)
      
    elseif (not device.active) then
        Test2(BulbBathroomSink)
    end
end
}

Re: local function

Posted: Saturday 10 March 2018 18:27
by Charley
Change

on = {
devices = { "testswitch " },
},

Use " on the name of the device. Then save the event and look in LOG to see if it triggered

Re: local function

Posted: Saturday 10 March 2018 18:30
by poudenes
It triggered by the switch. That is working.

But with the IF state when active i want setRGB to a bulb. Tried everything but cant get it work.
Seems the function code only see the testswitch IDX and not the BulbBathroomSink IDX

Im new into LUA script and learn everytime more and more.. but need some help :)

Re: local function

Posted: Sunday 11 March 2018 8:49
by poudenes
Finally solved my issue myself. Here it is and its working. Maybe not the best script but it work:

Code: Select all

local Version                   = '18.03.11'
local SwitchKayLearn            = 90
local SwitchHall		        = 92
local SwitchDressoir		    = 100
local SwitchBalcony		        = 101
local SwitchKitchenSink	        = 102
local SwitchKitchen		        = 104
local SwitchWindows		        = 105
local SwitchWall		        = 106
local SwitchBedroom	            = 107
local SwitchBathroom	        = 109

local BulbWallRight	            = 12
local BulbWallLeft              = 13    
local BulbWindowsLeft           = 14
local BulbWindowRight           = 15
local BulbMasterBedroom         = 22
local BulbDressoir              = 23
local BulbBalcony               = 24
local BulbHall                  = 25
local BulbBathroomSink          = 28
local BulbShower                = 29
local BulbKitchen               = 30
local BulbKitchenSink           = 31

local function RGB(domoticz,idx)
    domoticz.devices(idx).setRGB(255,255,255)
    status = 'aangezet'
    end 
local function Kelvin(domoticz,idx)
    domoticz.devices(idx).dimTo(100)
    domoticz.devices(idx).setKelvin(4000)
    status = 'aangezet'
    end 
local function TurnOff(domoticz,idx)
    domoticz.devices(idx).dimTo(5)
    domoticz.devices(idx).switchOff().afterSec(1) 
    status = 'uitgezet'
    end 

return {
    active = true,
    on = {
        devices = {'Switch*'},
    },
    logging = {marker = 'SWITCHES ' ..Version..'..............'},
    execute = function(domoticz, device)

--

status = ''

    if (device.idx == SwitchWindows and device.active) then -- WINDOWS SWITCH ON

        RGB(domoticz,BulbWindowsLeft)
        RGB(domoticz,BulbWindowRight)

    elseif (device.idx == SwitchWindows and not device.active) then -- WINDOWS SWITCH OFF
    
        TurnOff(domoticz,BulbWindowsLeft)
        TurnOff(domoticz,BulbWindowRight)
    
    elseif (device.idx == SwitchWall and device.active) then -- WALL SWITCH ON
        
        RGB(domoticz,BulbWallLeft)
        RGB(domoticz,BulbWallRight)

    elseif (device.idx == SwitchWall and not device.active) then -- WALL SWITCH OFF
        
        TurnOff(domoticz,BulbWallLeft)
        TurnOff(domoticz,BulbWallRight)
    
    elseif (device.idx == SwitchBedroom and device.active) then -- MASTERBEDROOM SWITCH ON
        Kelvin(domoticz,BulbMasterBedroom)

    elseif (device.idx == SwitchBedroom and not device.active) then -- MASTERBEDROOM SWITCH OFF
        TurnOff(domoticz,BulbMasterBedroom)

    elseif (device.idx == SwitchHall and device.active) then -- HALL SWITCH ON
        RGB(domoticz,BulbHall)

    elseif (device.idx == SwitchHall and not device.active) then -- HALL SWITCH OFF
        TurnOff(domoticz,BulbHall)
        
    elseif (device.idx == SwitchDressoir and device.active) then -- DRESSOIR SWITCH ON
        Kelvin(domoticz,BulbDressoir)

    elseif (device.idx == SwitchDressoir and not device.active) then -- DRESSOIR SWITCH OFF
        TurnOff(domoticz,BulbDressoir)
        
    elseif (device.idx == SwitchBathroom and device.active) then -- BATHROOM SWITCH ON
        Kelvin(domoticz,BulbBathroomSink)
        Kelvin(domoticz,BulbShower)

    elseif (device.idx == SwitchBathroom and not device.active) then -- BATHROOM SWITCH OFF
        TurnOff(domoticz,BulbBathroomSink)
        TurnOff(domoticz,BulbShower)
        
    elseif (device.idx == SwitchBalcony and device.active) then -- BALCONY SWITCH ON
        Kelvin(domoticz,BulbBalcony)

    elseif (device.idx == SwitchBalcony and not device.active) then -- BALCONY SWITCH OFF
        TurnOff(domoticz,BulbBalcony)
        
    elseif (device.idx == SwitchKitchenSink and device.active) then -- KITCHEN SINK SWITCH ON
        Kelvin(domoticz,BulbKitchenSink)

    elseif (device.idx == SwitchKitchenSink and not device.active) then -- KITCHEN SINK SWITCH OFF
        TurnOff(domoticz,BulbKitchenSink)
        
    elseif (device.idx == SwitchKitchen and device.active) then -- KITCHEN SWITCH ON
        Kelvin(domoticz,BulbKitchen)

    elseif (device.idx == SwitchKitchen and not device.active) then -- KITCHEN SWITCH OFF
        TurnOff(domoticz,BulbKitchen)
        
    elseif (device.idx == SwitchKayLearn and device.active) then -- KITCHEN SWITCH ON
        status = 'aangezet'        

    elseif (device.idx == SwitchKayLearn and not device.active) then -- KITCHEN SWITCH OFF
        status =' uitgezet'

    end
    domoticz.log('------------------------==<[ ' ..device.name.. ' is ' ..status..'. ]>==-----------------------------', domoticz.LOG_FORCE)
end
}