Page 1 of 1
Variable 'at' time
Posted: Monday 21 December 2020 7:27
by EddyG
It would be nice to have something like:
Code: Select all
['timer'] = { 'at ' .. domoticz.devices("selectorSwitch").levelName }
Or is there a simple way to emulate this?
Re: Variable 'at' time
Posted: Monday 21 December 2020 11:12
by waaren
EddyG wrote: Monday 21 December 2020 7:27
Or is there a simple way to emulate this?
It can be emulated with below example
selector levelNames 'Off', '08:03', '12:23', etc..
If you cannot name the levelNames like this using Add, use a dummy name first and rename afterwards.
Code: Select all
local scriptVar = 'selector controlled'
local selector = 'selectorSwitch'
return
{
on =
{
timer =
{
'at 00:01',
},
devices =
{
selector,
},
customEvents =
{
scriptVar,
},
},
logging =
{
level = domoticz.LOG_DEBUG,
marker = scriptVar,
},
execute = function(dz, item)
local selector = dz.devices(selector)
if item.isTimer or item.isDevice then
local setTime = selector.levelName
dz.log('Emit event at '.. setTime, dz.LOG_DEBUG)
dz.emitEvent(scriptVar, selector.levelName).at(setTime)
elseif item.isCustomEvent and item.data == selector.levelName then
selector.switchSelector(0).silent() -- EDIT changed to the more appropriate switchSelector ( was dimTo() )
dz.log('-- rest of script', dz.LOG_DEBUG) -- rest of script behind this line
else
dz.log('No action needed now', dz.LOG_DEBUG)
end
end
}
Re: Variable 'at' time
Posted: Monday 21 December 2020 11:58
by EddyG
Tnx, but I got this error when I actuate the selector. (zzz.lua is my script.)
Code: Select all
2020-12-21 11:57:18.831 Error: dzVents: Error: (3.0.19) selector controlled: An error occurred when calling event handler zzz
2020-12-21 11:57:18.831 Error: dzVents: Error: (3.0.19) selector controlled: /home/pi/domoticz/dzVents/runtime/Utils.lua:151: attempt to perform arithmetic on a nil value (local 'hours')
Edit: Sorry forgot to save the selector names.
Second edit: The 'Off' value is not accepted, changed that too.
Re: Variable 'at' time
Posted: Monday 21 December 2020 22:45
by EddyG
Is there also a cancelemitEvent, or is there just 1 emitEvent active?
Re: Variable 'at' time
Posted: Monday 21 December 2020 23:07
by waaren
EddyG wrote: Monday 21 December 2020 22:45
Is there also a cancelemitEvent, or is there just 1 emitEvent active?
There is no cancel EmitEvent possible and there can be multiple emitEvents active.
Re: Variable 'at' time
Posted: Wednesday 23 December 2020 10:07
by EddyG
Tnx, it works brilliant.
Would not it be nice to have a cancelEmitEvent function too?

Are they kept in memory or saved in the database? If so where?
P.S. the dimTo should be switchSelector, I think.
Funny indeed that initially levelnames cannot contain the ':' , but afterwards by editing the levelnames it is possible.
Re: Variable 'at' time
Posted: Wednesday 23 December 2020 10:33
by waaren
EddyG wrote: Wednesday 23 December 2020 10:07
Would not it be nice to have a cancelEmitEvent function too?

Are they kept in memory or saved in the database? If so where?
P.S. the dimTo should be switchSelector, I think.
I don't know if implementing cancelEmitEvent() is possible / easy (@MrHobbes74 ?) but the script(s) dealing with the customEvents at hand could check the conditions leading to a situation that the customEvent should no longer perform any follow up action.
You are right about dimTo vs switchSelector. They do the same in domoticz but it's better to use switchSelector here.
btw. emitEvent It is only in memory.
Re: Variable 'at' time
Posted: Wednesday 23 December 2020 11:47
by EddyG
I use it as a minimum time that automated lights go on.
My problem is that when a emitevent cannot be canceled, a click on 07:00 and subsequent click on 07:30 the lights still go on at 07:00 and again at 07:30
I would like to cancel the 07:00 once I click on an other time in the selectorswitch.
Is there an enum of all outstanding emitevents?
Is there a workaround?
Re: Variable 'at' time
Posted: Wednesday 23 December 2020 12:07
by waaren
EddyG wrote: Wednesday 23 December 2020 11:47
My problem is that when a emitevent cannot be canceled, a click on 07:00 and subsequent click on 07:30 the lights still go on at 07:00 and again at 07:30
that should not happen as the script checks if the time of the selectorLevel == item.data of the customEvent
Code: Select all
elseif item.isCustomEvent and item.data == selector.levelName then
Is there an enum of all outstanding emitevents?
No
You could create something yourself by keeping track of the emitEvents in globalData but I cannot see a use case for this that could not be solved easier by checking the conditions with the the same- or similar code as I posted in this topic.
Re: Variable 'at' time
Posted: Wednesday 23 December 2020 12:09
by EddyG
Oke. Tnx, totally clear now.