Re: dzvents rgb broadlink
Posted: Sunday 12 May 2019 0:13
My system crashes again, i am going to remove broadlink
Almost.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...
Code: Select all
helpers = {
myHelperFunction = function(domoticz)
-- code
end
Code: Select all
helpers = {
myHelperFunction = function(domoticz)
-- code
end,
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
}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
}
}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
}Use the scripts/dzvents/scripts one. No need to delete the other one.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 ?
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 } }
Is there a way to determine what the current color of the light is ?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
This solution is not robust enough. Chance of counter getting out of sync with reality is quite high.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.
Added a triggerDevice_Off.switchOn() in function Kleur.- when changing color first off on the device
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
}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
}