dzvents rgb broadlink

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents rgb broadlink

Post by pvklink »

My system crashes again, i am going to remove broadlink
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents rgb broadlink

Post by waaren »

pvklink wrote: Saturday 11 May 2019 20:52 I upgraded the script like you said,
Added the global helper, dont know if i did that right, see below...
Almost.

you left out a comma at the end of the myHelperFunction.

Code: Select all

helpers = {
		myHelperFunction = function(domoticz)
			-- code
		end
should be

Code: Select all

helpers = {
		myHelperFunction = function(domoticz)
			-- code
		end,
helpers is here a Lua table. A Lua table can contain values, strings, sub-tables but also functions.
Every helper function is declared in this helpers table with the function name as key and the function body as value.
So if you are use domoticz.helpers.myHelperFunction in your script, you call the function body and this will be executed.
The comma is necessary to separate the table entries from each other.

Hope this clarifies a bit and also explain why the comma is required at that place.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents rgb broadlink

Post by pvklink »

Thanks and clear!
No hope that somebody has the same instability as me with broadlink and the latest domoticz and raspbian.
I cant use this script until this is solved...
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents rgb broadlink

Post by pvklink »

Hi Waaren, i got broadlink working again!
So now finishing my last usb lamp script....
I used these posts to recover from...

i made the global_data.lua on scripts/dzvents/scripts
i see that there also is a global_data.lua on /scripts/templates/...
which one do i use / can i delete ?

Is it possible to call
dz.helpers.alertLidl(dz, "blauw", 12) without the 12, so that it stays on ?

Code: Select all

return {
	on = {
		devices = {
			'test'
		}
	},
	execute = function(dz, device)
	    dz.helpers.alertLidl(dz, "blauw", 12)
		dz.log('Device ' .. device.name .. ' was changed', dz.LOG_INFO)
	end
}
global_data.lua

Code: Select all

return {
	data = {
		myGlobalVar = { initial = 12 }
		},

	helpers = {
		alertLidl = function(dz, action, period)
			local controlVar = dz.variables("controlVar")
			local value = controlVar.value
        	        if controlVar.value ~= action then
                		controlVar.set(action) 
                        	controlVar.set(value).afterSec(period)
	                        dz.log("alert requested; controlVar set to " .. action .. ". It will return to ".. value .. " after " .. period .. " seconds." ,dz.LOG_FORCE)
                       	else
	                        dz.log("No changed needed; controlVar is already set to " .. value,dz.LOG_DEBUG)
        	        end
		end
   		}
}
usb_lamp

Code: Select all

- maak variable controlVar Aan
-- dz.helpers.alertLidl(dz, "paars", 12) daarmee kun je t licht n kleur geven
-- let op ook /script/templates/global_data.dzVents


local controlVar = "controlVar"  -- var, define as type string

return {
            on =    {   devices = { "usb lamp" }, -- controller , define as virtual selector Switch with all level as named in action table 
                        variables = { controlVar },   -- var, define as type string
                    },
                    
        logging =   {   level     =   domoticz.LOG_DEBUG,
                        marker    =   "Lidl"   },

    execute = function(dz, item)
        local triggerDevice_Off    = dz.devices(1415)
        local triggerDevice_Aan    = dz.devices(1414)
        local triggerDevice_Kleur  = dz.devices(1416)
        local triggerDevice_Wit    = dz.devices(1422)
        local triggerDevice_Flame  = dz.devices(1418)
        local triggerDevice_Play   = dz.devices(1419)
        local triggerDevice_Dim    = dz.devices(1420)
        local triggerDevice_Speed  = dz.devices(1421)
        
        local controlVar = dz.variables(controlVar)
        
        colors = { rood = 1,
                   groen = 2,
                   blauw = 3,
                   oranje = 4, 
                   grijs = 5,
                   roze = 6,
                   paars = 7,
                 }
        
        actions =   {   Off = function() triggerDevice_Off.switchOn() return end,
                        Aan = function() triggerDevice_Aan.switchOn() return end,
                        Kleur = function(color) 
                                    triggerDevice_Aan.switchOn() 
                                    local repeats = (( colors[color] or 1 ) - 1)
                                    dz.log("Color requested :" .. tostring(color) .. "==>> repeats required " .. repeats ,dz.LOG_DEBUG )
                                    triggerDevice_Kleur.switchOn().repeatAfterSec(0.1, repeats )
                                    return 
                                end,
                        Wit = function() triggerDevice_Aan.switchOn() triggerDevice_Wit.switchOn() return end,
                        Flame = function() triggerDevice_Aan.switchOn() triggerDevice_Flame.switchOn() return end,
                        Play = function() triggerDevice_Aan.switchOn() triggerDevice_Play.switchOn() return end,
                        Dim = function() triggerDevice_Aan.switchOn() triggerDevice_Dim.switchOn() return end,
                        Speed = function() triggerDevice_Aan.switchOn() triggerDevice_Speed.switchOn() return end, 
                    }
        
        local function setVar( request )
            if controlVar.value ~= request then
                controlVar.set(request).silent()
            end
        end
        
        local function isColorAction( action )
            for color, number in pairs(colors) do -- check if called with one of the defined colors
                if action == color then
                    setVar(color)
                    actions["Kleur"](color)
                    return true
                end
            end
            return false
        end
        
        local function doAction( action )
            if actions[action] then
                dz.log("known action requested ( " .. action .." )",dz.LOG_DEBUG )
                setVar(action)
                actions[action]()    -- Call required function with key = action
            else
               dz.log("unknown action requested ( " .. action .." )",dz.LOG_ERROR )
               return false
            end
        end
        
        if item.isDevice and ( not ( isColorAction(item.levelName) ) ) then 
            doAction(item.levelName) 
        elseif item.isVariable and ( not ( isColorAction(item.value) ) ) then 
            doAction(item.value) 
        end

    end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents rgb broadlink

Post by waaren »

pvklink wrote: Saturday 25 May 2019 17:38 I made the global_data.lua on scripts/dzvents/scripts
i see that there also is a global_data.lua on /scripts/templates/...
which one do i use / can i delete ?
Use the scripts/dzvents/scripts one. No need to delete the other one.
Is it possible to call
dz.helpers.alertLidl(dz, "blauw", 12) without the 12, so that it stays on ?

If you change the global_data part to this you can

Code: Select all

return 
{
    data = 
    {
        myGlobalVar = { initial = 12 }
    },

    helpers = 
    {
        alertLidl = function(dz, action, period)
            local controlVar = dz.variables("controlVar")
            local value = controlVar.value
            if controlVar.value ~= action then
                controlVar.set(action) 
                if period then
                    controlVar.set(value).afterSec(period)
                    dz.log("alert requested; controlVar set to " .. action .. ". It will return to ".. value .. " after " .. period .. " seconds." ,dz.LOG_FORCE)
                else
                    dz.log("alert requested; controlVar set to " .. action  ,dz.LOG_FORCE)
                end
            else
                dz.log("No changed needed; controlVar is already set to " .. value,dz.LOG_DEBUG)
            end
        end
    }
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents rgb broadlink

Post by pvklink »

I did,

when the lamp is already on and has a color, turning it to blue or some other color does not give the right color because it is a state where the color numbers dont match anymore...
in this situation it also goes back to the wrong color state
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents rgb broadlink

Post by waaren »

pvklink wrote: Sunday 26 May 2019 22:37 I did,

when the lamp is already on and has a color, turning it to blue or some other color does not give the right color because it is a state where the color numbers dont match anymore...
in this situation it also goes back to the wrong color state
Is there a way to determine what the current color of the light is ?
If the lamp is switched Off does it reset to the initial state ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents rgb broadlink

Post by pvklink »

yes. with a off command it goes back to initial...
so changing colors must :
- registrate the times colors is clicked and use that nr to count how much signals it must give or
- when changing color first off on the device

the script can get a color for example red or a push on the color selector that means next color
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: dzvents rgb broadlink

Post by waaren »

pvklink wrote: Monday 27 May 2019 7:01 - register the times colors is clicked and use that nr to count how much signals it must give.
This solution is not robust enough. Chance of counter getting out of sync with reality is quite high.
- when changing color first off on the device
Added a triggerDevice_Off.switchOn() in function Kleur.

Code: Select all

- maak variable controlVar Aan
-- dz.helpers.alertLidl(dz, "paars", 12) daarmee kun je t licht n kleur geven
-- let op ook scripts/dzVents/scripts/global_data.lua


local controlVar = "controlVar"  -- var, define as type string

return {
            on =    {   devices = { "usb lamp" }, -- controller , define as virtual selector Switch with all level as named in action table 
                        variables = { controlVar },   -- var, define as type string
                    },
                    
        logging =   {   level     =   domoticz.LOG_DEBUG,
                        marker    =   "Lidl"   },

    execute = function(dz, item)
        local triggerDevice_Off    = dz.devices(1415)
        local triggerDevice_Aan    = dz.devices(1414)
        local triggerDevice_Kleur  = dz.devices(1416)
        local triggerDevice_Wit    = dz.devices(1422)
        local triggerDevice_Flame  = dz.devices(1418)
        local triggerDevice_Play   = dz.devices(1419)
        local triggerDevice_Dim    = dz.devices(1420)
        local triggerDevice_Speed  = dz.devices(1421)
        
        local controlVar = dz.variables(controlVar)
        
        colors = { rood = 1,
                   groen = 2,
                   blauw = 3,
                   oranje = 4, 
                   grijs = 5,
                   roze = 6,
                   paars = 7,
                 }
        
        actions =   {   Off = function() triggerDevice_Off.switchOn() return end,
                        Aan = function() triggerDevice_Aan.switchOn() return end,
                        Kleur = function(color) 
                                    triggerDevice_Off.switchOn() 
                                    triggerDevice_Aan.switchOn() 
                                    local repeats = (( colors[color] or 1 ) - 1)
                                    dz.log("Color requested :" .. tostring(color) .. "==>> repeats required " .. repeats ,dz.LOG_DEBUG )
                                    triggerDevice_Kleur.switchOn().repeatAfterSec(0.1, repeats )
                                    return 
                                end,
                        Wit = function() triggerDevice_Aan.switchOn() triggerDevice_Wit.switchOn() return end,
                        Flame = function() triggerDevice_Aan.switchOn() triggerDevice_Flame.switchOn() return end,
                        Play = function() triggerDevice_Aan.switchOn() triggerDevice_Play.switchOn() return end,
                        Dim = function() triggerDevice_Aan.switchOn() triggerDevice_Dim.switchOn() return end,
                        Speed = function() triggerDevice_Aan.switchOn() triggerDevice_Speed.switchOn() return end, 
                    }
        
        local function setVar( request )
            if controlVar.value ~= request then
                controlVar.set(request).silent()
            end
        end
        
        local function isColorAction( action )
            for color, number in pairs(colors) do -- check if called with one of the defined colors
                if action == color then
                    setVar(color)
                    actions["Kleur"](color)
                    return true
                end
            end
            return false
        end
        
        local function doAction( action )
            if actions[action] then
                dz.log("known action requested ( " .. action .." )",dz.LOG_DEBUG )
                setVar(action)
                actions[action]()    -- Call required function with key = action
            else
               dz.log("unknown action requested ( " .. action .." )",dz.LOG_ERROR )
               return false
            end
        end
        
        if item.isDevice and ( not ( isColorAction(item.levelName) ) ) then 
            doAction(item.levelName) 
        elseif item.isVariable and ( not ( isColorAction(item.value) ) ) then 
            doAction(item.value) 
        end

    end
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
pvklink
Posts: 822
Joined: Wednesday 12 November 2014 15:01
Target OS: Raspberry Pi / ODroid
Domoticz version: latest b
Contact:

Re: dzvents rgb broadlink

Post by pvklink »

ok,!

Almost there!

When the light is white and i do a
dz.helpers.alertLidl(dz, "blauw", 12)
it becomes blue and then white again!
Same for red. etc.
When its off and i do a
dz.helpers.alertLidl(dz, "blauw", 12), it turns off after blue! perfect!

Only thing that does not work is when i click on "kleur" on the usb_lamp selector instead of a script command. It has to toggle the colors
kleur = id 20. It does not,
when it is off and i click on kleur it becomes red (the second color instead off white)
When it is already on and i click on kleur it goes off and then becomes red, i cant select colors by clicking it...

When ik click On or off, or flame, or speed or dim etc. they also all work fine!
So almost there !

i tried to change the script, amd it is working..... hope this is the right way ! i add a function and action with another name kleuren.
Default on is also changed in default to flame...

Code: Select all

-- maak variable controlVar Aan
-- dz.helpers.alertLidl(dz, "paars", 12) daarmee kun je t licht n kleur geven
-- let op ook scripts/dzVents/scripts/global_data.lua

local controlVar = "controlVar"  -- var, define as type string

return {
            on =    {   devices = { "usb lamp" }, -- controller , define as virtual selector Switch with all level as named in action table 
                        variables = { controlVar },   -- var, define as type string
                    },
                    
        logging =   {   level     =   domoticz.LOG_DEBUG,
                        marker    =   "Lidl"   },

    execute = function(dz, item)
        local triggerDevice_Off    = dz.devices(1415)
        local triggerDevice_Aan    = dz.devices(1414)
        local triggerDevice_Kleur  = dz.devices(1416)
        local triggerDevice_Kleuren= dz.devices(1416)
        local triggerDevice_Wit    = dz.devices(1422)
        local triggerDevice_Flame  = dz.devices(1418)
        local triggerDevice_Play   = dz.devices(1419)
        local triggerDevice_Dim    = dz.devices(1420)
        local triggerDevice_Speed  = dz.devices(1421)
        
        local controlVar = dz.variables(controlVar)
        
        colors = { rood = 1,
                   groen = 2,
                   blauw = 3,
                   oranje = 4, 
                   grijs = 5,
                   roze = 6,
                   paars = 7,
                 }
        
        actions =   {   Off = function() triggerDevice_Off.switchOn() return end,
                        Aan = function() triggerDevice_Aan.switchOn() triggerDevice_Flame.switchOn() return end,
                        Kleuren = function() triggerDevice_Aan.switchOn() triggerDevice_Kleuren.switchOn() return end,
                        Kleur = function(color) 
                                    triggerDevice_Off.switchOn() 
                                    triggerDevice_Aan.switchOn() 
                                    local repeats = (( colors[color] or 1 ) - 1)
                                    dz.log("Color requested :" .. tostring(color) .. "==>> repeats required " .. repeats ,dz.LOG_DEBUG )
                                    triggerDevice_Kleur.switchOn().repeatAfterSec(0.1, repeats )
                                    return 
                                end,
                        Wit = function() triggerDevice_Aan.switchOn() triggerDevice_Wit.switchOn() return end,
                        Flame = function() triggerDevice_Aan.switchOn() triggerDevice_Flame.switchOn() return end,
                        Play = function() triggerDevice_Aan.switchOn() triggerDevice_Play.switchOn() return end,
                        Dim = function() triggerDevice_Aan.switchOn() triggerDevice_Dim.switchOn() return end,
                        Speed = function() triggerDevice_Aan.switchOn() triggerDevice_Speed.switchOn() return end, 
                    }
        
        local function setVar( request )
            if controlVar.value ~= request then
                controlVar.set(request).silent()
            end
        end
        
        local function isColorAction( action )
            for color, number in pairs(colors) do -- check if called with one of the defined colors
                if action == color then
                    setVar(color)
                    actions["Kleur"](color)
                    return true
                end
            end
            return false
        end
        
        local function doAction( action )
            if actions[action] then
                dz.log("known action requested ( " .. action .." )",dz.LOG_DEBUG )
                setVar(action)
                actions[action]()    -- Call required function with key = action
            else
               dz.log("unknown action requested ( " .. action .." )",dz.LOG_ERROR )
               return false
            end
        end
        
        if item.isDevice and ( not ( isColorAction(item.levelName) ) ) then 
            doAction(item.levelName) 
        elseif item.isVariable and ( not ( isColorAction(item.value) ) ) then 
            doAction(item.value) 
        end

    end
}
Raspberry (raspbian on rpi 3) , Domoticz Beta, dzVents , RFXtrx433e, P1, Hue, Yeelight, Zwave+, X10, ESP(easy), MQTT,Weather Underground, System Alive Checker, Domoticz Remote Server to RPI with Google Assistant,
Jablotron connection, Ikea
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest