How can i use seconds in an script, I mean I have an switch that toggles an other switch for 3 seconds.
I'm totally new to this dzvents script so go easy please
Moderator: leecollings
something likejacobsentertainment wrote: Friday 19 March 2021 12:54 How can i use seconds in an script, I mean I have an switch that toggles an other switch for 3 seconds.
Code: Select all
return
{
on =
{
devices =
{
'activatingSwitch', -- name of the switch that triggers the next one
},
},
execute = function(dz)
follower = dz.devices('name of follower switch')
follower.switchOn().checkFirst()
follower.switchOff().afterSec(3)
end
}
Look good, ill give it a try tonight. Thanks!waaren wrote: Friday 19 March 2021 14:00 something like
Code: Select all
return { on = { devices = { 'activatingSwitch', -- name of the switch that triggers the next one }, }, execute = function(dz) follower = dz.devices('name of follower switch') follower.switchOn().checkFirst() follower.switchOff().afterSec(3) end }
Code: Select all
return {
on = {
devices = {
'PIR3 overloop', 'PIR1 gang',
}
},
execute = function(domoticz, device)
local Device1 = domoticz.devices(95)
if (Device1 <= 180 ) then
follower = domoticz.devices(262)
follower.switchOn().checkFirst()
follower.switchOff().afterSec(185)
end
end
}
Your script tries to compare a device object (a table) with the value 180.jacobsentertainment wrote: Sunday 28 March 2021 17:51 What's going wrong here?
The log is returning; lua:11: attempt to compare table with number
I'm lost here.
Code: Select all
return {
on = {
devices = {
'PIR3 overloop', 'PIR1 gang',
}
},
execute = function(domoticz, device)
local lux = domoticz.devices(95).lux
local follower = domoticz.devices(262)
if lux <= 180 and follower.state ~= 'On' then
follower.switchOn()
follower.switchOff().afterSec(185)
end
end
}
Code: Select all
local Device1 = domoticz.devices(95)Code: Select all
local Device1 = domoticz.devices(95).luxAlmost. A device object has many attributes. Some generic and some specific for the devicetype. You were looking for the value of the attribute luxjacobsentertainment wrote: Sunday 28 March 2021 21:58 So for my info, I was only calling the device hereWhere I should call the value of the deviceCode: Select all
local Device1 = domoticz.devices(95)Code: Select all
local Device1 = domoticz.devices(95).lux
Code: Select all
hardwareName: Xiaomi
name: WC Lux
unit: 43
lux: 3
inActive: true
idx: 2676
deviceSubType: Lux
nValue: 0
icon: lux
customImage: 0
deviceId: 000002B
active: false
_adapters:
1: Lux device adapter
description:
hardwareType: Xiaomi Gateway
baseType: device
protected: false
hardwareId: 33
lastUpdate: 2021-03-28 21:41:47
timedOut: false
batteryLevel: 81
deviceType: Lux
isDevice: true
signalLevel: 12
state: 3
sValue: 3
Code: Select all
return {
active = true,
on = {
timer = {
'every 1 minutes'
}
},
execute = function(domoticz)
local myDevice1 = domoticz.devices('Lux')
local myDevice2 = domoticz.devices(219)
local myDevice3 = domoticz.devices(350)
local LUX = myDevice1.lux
domoticz.log(myDevice1.name .. ' ' .. LUX, domoticz.LOG_INFO)
domoticz.log(myDevice2.name .. ' ' .. myDevice2.state, domoticz.LOG_INFO)
domoticz.log(myDevice3.name .. ' ' .. myDevice3.state, domoticz.LOG_INFO)
if (LUX <= 15 ) then
myDevice2.switchOn()
domoticz.log('Light info, The light ' .. myDevice2.name .. ' will be switched on due to low LUX', domoticz.LOG_INFO)
elseif (LUX <= 15 ) then
myDevice3.switchOn()
domoticz.log('Light info, The light ' .. myDevice3.name .. ' will be switched on due to low LUX', domoticz.LOG_INFO)
else
myDevices.switchOff()
end
end
}The second condition is equal to the first condition so if the first is true the elseif will not be evaluated. If the first condition is false the condition after the elseif also evaluates to falsejacobsentertainment wrote: Friday 07 May 2021 23:25 I tried to add an second device and so far the script ain't returning any errors but the second device isn't switching on.
What am I doing wrong here?
Code: Select all
return {
active = true,
on = {
timer = {
'every 1 minutes'
}
},
execute = function(domoticz)
local myDevice1 = domoticz.devices('Lux')
local myDevice2 = domoticz.devices(219)
local myDevice3 = domoticz.devices(350)
local LUX = myDevice1.lux
domoticz.log(myDevice1.name .. ' ' .. LUX, domoticz.LOG_INFO)
domoticz.log(myDevice2.name .. ' ' .. myDevice2.state, domoticz.LOG_INFO)
domoticz.log(myDevice3.name .. ' ' .. myDevice3.state, domoticz.LOG_INFO)
if (LUX <= 15 ) then
myDevice2.switchOn()
domoticz.log('Light info, The light ' .. myDevice2.name .. ' will be switched on due to low LUX', domoticz.LOG_INFO)
myDevice3.switchOn()
domoticz.log('Light info, The light ' .. myDevice3.name .. ' will be switched on due to low LUX', domoticz.LOG_INFO)
else
myDevices.switchOff()
end
end
}
Users browsing this forum: Google [Bot] and 1 guest