Page 1 of 1
idea for device within a timer
Posted: Thursday 22 February 2018 9:44
by poudenes
Hi All,
I have some scripts that triggered by follow
Code: Select all
on = {
timer = {'at nighttime'},
devices = {SensorMasterBedroom},
},
Maybe its a idea to add the device into the timer. So that device will only triggered within the timer. This example when its nighttime
Now it triggered always on the Sensor but does't do his actions. I see lots of log lines that are unnecessary.
cheers,
Re: idea for device within a timer
Posted: Thursday 22 February 2018 12:43
by dannybloe
Check the
docs: devices = { 'SensorMasterBedroom' = { 'at nighttime' } }
Re: idea for device within a timer
Posted: Thursday 22 February 2018 12:47
by poudenes
dannybloe wrote: Thursday 22 February 2018 12:43
Check the
docs: devices = { 'SensorMasterBedroom' = { 'at nighttime' } }
Thanks, i was playing with that option but didn't find out the right way.
Thanks again for helping !!!

Re: idea for device within a timer
Posted: Thursday 22 February 2018 23:20
by poudenes
dannybloe wrote: Thursday 22 February 2018 12:43
Check the
docs: devices = { 'SensorMasterBedroom' = { 'at nighttime' } }
It is working but not the way how i expected. When sensor turn on it wait for when the time change 1 minute then it turn on the lights.
When sensor goes of it wait again to turn off the lights
Re: idea for device within a timer
Posted: Friday 23 February 2018 8:18
by dannybloe
I can say that, given the current state of how everything works, this is technically impossible. When the device gets an update it immediately triggers the event system and dzVents will check if the current time is matching the 'at nighttime' rule. If that's the case then the event script is called immediately. There is no code in dzVents that can put the event on hold until the start of the minute. As a matter of fact, I just tested it. So.. having said that I can only conclude that the event is only raised every minute. Perhaps your sensor only reports to Domoticz every minute or your trigger rules in your script are not correct.
Btw, the rule above should be like (with the square brackets) but your probably already knew that:
Code: Select all
devices = {
{ ['SensorMasterBedroom'] = { 'at nighttime' } }
}
Maybe you can post the entire script here.
Re: idea for device within a timer
Posted: Friday 23 February 2018 9:31
by poudenes
I tried lot of things and now it working.
Code: Select all
devices = {[SensorMasterBedroom] = { 'at nighttime' }},
This was the line for me to let it work.
Here the full script
Code: Select all
local Version = '18.02.22'
local SensorMasterBedroom = 529
local MasterBedroom = 7
local SwitchGoodnight = 65
return {
active = true,
on = {
devices = {[SensorMasterBedroom] = { 'at nighttime' }},
},
logging = {marker = 'SLAAPKAMER Sensor ' ..Version..'......'},
execute = function(domoticz, device)
if
domoticz.devices(SensorMasterBedroom).active and
domoticz.devices(SwitchGoodnight).state == 'Off'
then
domoticz.devices(MasterBedroom).dimTo(100)
domoticz.devices(MasterBedroom).dimTo(100)
domoticz.devices(MasterBedroom).setKelvin(5000)
elseif
domoticz.devices(SensorMasterBedroom).toggleSwitch() and
domoticz.devices(MasterBedroom).active and
domoticz.devices(SwitchGoodnight).state == 'Off'
then
domoticz.devices(MasterBedroom).dimTo(1)
domoticz.devices(MasterBedroom).switchOff().afterSec(1)
end
end
}
Re: idea for device within a timer
Posted: Friday 23 February 2018 9:57
by dannybloe
Code: Select all
local Version = '18.02.22'
local SensorMasterBedroom = 529
local MasterBedroom = 7
local SwitchGoodnight = 65
return {
on = {
devices = {[SensorMasterBedroom] = { 'at nighttime' }},
},
logging = {marker = 'SLAAPKAMER Sensor ' ..Version..'......'},
execute = function(domoticz, sensor)
local goodnightSwitch = domoticz.devices(SwitchGoodnight)
local light = domoticz.devices(MasterBedroom)
if (sensor.active and not goodnightSwitch.active) then
light.dimTo(100)
light.setKelvin(5000)
elseif (light.active and not goodnightSwitch.active) then
light.dimTo(1)
light.switchOff().afterSec(1)
end
end
}
You had a 'domoticz.devices(SensorMasterBedroom).toggleSwitch()' in your elseif statement and that is not correct as the function toggleSwitch() doesn't return anything (nil basically so your elseif will always fail).
Untested of course

Re: idea for device within a timer
Posted: Friday 23 February 2018 10:07
by poudenes
Hmm... because its was working

.
Your script is working also. Look nicer

I have to learn a lot

every time little bit more haha
If i understand it correct. execute = function(domoticz, sensor) refer to everything thats in devices = {[SensorMasterBedroom] = { 'at nighttime' }} ?
So if i put 2 devices in it then sensor.active will check if those devices are both active?
dannybloe wrote: Friday 23 February 2018 9:57
Code: Select all
local Version = '18.02.22'
local SensorMasterBedroom = 529
local MasterBedroom = 7
local SwitchGoodnight = 65
return {
on = {
devices = {[SensorMasterBedroom] = { 'at nighttime' }},
},
logging = {marker = 'SLAAPKAMER Sensor ' ..Version..'......'},
execute = function(domoticz, sensor)
local goodnightSwitch = domoticz.devices(SwitchGoodnight)
local light = domoticz.devices(MasterBedroom)
if (sensor.active and not goodnightSwitch.active) then
light.dimTo(100)
light.setKelvin(5000)
elseif (light.active and not goodnightSwitch.active) then
light.dimTo(1)
light.switchOff().afterSec(1)
end
end
}
You had a 'domoticz.devices(SensorMasterBedroom).toggleSwitch()' in your elseif statement and that is not correct as the function toggleSwitch() doesn't return anything (nil basically so your elseif will always fail).
Untested of course