Hi folks,
I'm pretty new to Domoticz, installed it 2 days ago, and experimenting with event scripts.
I baked my own led driver hardware where I can plug on a atmega328p, or now also an esp01 controlling the light with an enable and a pwm pin.
Works pretty good using ESPeasy self compiled on the esp01 and a quite static script in Domoticz.
I want my lights to dim up and down when turning them on/off and can achieve this already.
To properly calculate the dim time (fixed parameter to curl call for ESPeasy) I need also the old value of the dimmer setting and thought I store that in user variables.
Where I'm failing is to create a non existing user variable from the dzVent LUA script.
I tried to call the json command from the script using os.execute and openURL, but no effect.
Can somebody give me a hint how to achieve creation of a new user variable from a dzVents event script, please?
Cheers,
Klaus
dzVents adding a new user variable from script
Moderator: leecollings
-
- Posts: 1
- Joined: Monday 30 August 2021 22:47
- Target OS: Windows
- Domoticz version:
- Contact:
-
- Posts: 12
- Joined: Saturday 10 November 2018 12:47
- Target OS: Windows
- Domoticz version:
- Contact:
Re: dzVents adding a new user variable from script
Hi,
You won't need to create a user variable (unless you have to use it oustide of dzvents), instead you want to use a global or local dzvents data.
Local dzvents data : if this variable is to be used in the same script (and for every trigger of the script)
Global dzvents data : if the variable is to be used in multiple dzvents scripts
local data :
global data are defined in globa_data.lua
and then be used like this in other dzvents scripts
Based on what you want, I would create a local data, specifically an array, that will contain the current level of the dimmer.
Then create a dzvents script that will trigger for all your lights (using your led driver) and catch the level change, store the value in the global data (if you use an array match idx with level in your array)
Then in the same script you can catch the on/off and do your thing to dim the light.
Otherwise to create a user variable in dzvents, I would use the openURL function of dzvents domoticz object with the JSON API : /json.htm?type=command¶m=adduservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE...
You won't need to create a user variable (unless you have to use it oustide of dzvents), instead you want to use a global or local dzvents data.
Local dzvents data : if this variable is to be used in the same script (and for every trigger of the script)
Global dzvents data : if the variable is to be used in multiple dzvents scripts
local data :
Code: Select all
return {
on = {
devices = { 'MySwitch' }
},
data = {
counter = { initial = 0 }
},
execute = function(domoticz, switch)
if (domoticz.data.counter == 5) then
domoticz.notify('The switch was pressed 5 times!')
domoticz.data.counter = 0 -- reset the counter
else
domoticz.data.counter = domoticz.data.counter + 1
end
end
}
Code: Select all
return {
helpers = {},
data = {
heatingProgramActive = { initial = false }
}
}
Code: Select all
return {
on = {
devices = {'WindowSensor'}
},
execute = function(domoticz, windowSensor)
if (domoticz.globalData.heatingProgramActive
and windowSensor.state == 'Open') then
domoticz.notify("Hey don't open the window when the heating is on!")
end
end
}
Then create a dzvents script that will trigger for all your lights (using your led driver) and catch the level change, store the value in the global data (if you use an array match idx with level in your array)
Then in the same script you can catch the on/off and do your thing to dim the light.
Otherwise to create a user variable in dzvents, I would use the openURL function of dzvents domoticz object with the JSON API : /json.htm?type=command¶m=adduservariable&vname=USERVARIABLENAME&vtype=USERVARIABLETYPE&vvalue=USERVARIABLEVALUE...
Who is online
Users browsing this forum: No registered users and 1 guest