Page 1 of 1
AND function kills script
Posted: Sunday 14 January 2018 21:13
by R0yk3
Hello,
this script does not work like i want it to:
Code: Select all
return {
on = {
devices = {
'Telefoon_Jeanine',
'Telefoon_Roy',
'ZonOnder'
},
},
execute = function(domoticz, device)
if ((device.name == 'Telefoon_Jeanine' and device.state == 'On') or
(device.name == 'Telefoon_Roy' and device.state == 'On') and
(device.name == 'ZonOnder' and device.state == 'On')) then
domoticz.devices('Tuin').switchOn()
end
end
}
What i want is:
The light 'tuin' is turned on when:
'Telefoon_Jeanine', is on
or
'Telefoon_Roy', is on
and
'ZonOnder' is on
Al three are switches. Without the ZonOnder it works.
I replaced ZondOnder also by
But at nighttime does not work, or while testing at daytime.
I'm Using the latest beta Version: 3.8807
Re: AND function kills script
Posted: Sunday 14 January 2018 22:27
by waaren
Maybe this can help you ?
Code: Select all
return {
active = true,
on = { devices = { ['Telefoon*'] = {'at nighttime'} } },
execute = function(domoticz,Telefoon)
if Telefoon.state == 'On' then
domoticz.devices('Tuin').switchOn()
end
end
}
Re: AND function kills script
Posted: Sunday 14 January 2018 22:58
by R0yk3
Thank You!! This works for turning the lights on.
But, i also want the lights to turn off if we leave the house.
Now i added this
Code: Select all
else
domoticz.devices('Tuin').switchOff()
But now the light does turn off if only 1 phone leaves the house?
Re: AND function kills script
Posted: Sunday 14 January 2018 23:29
by waaren
How about ? [Edit]
Code: Select all
return {
active = true,
on = {
devices = { ['Telefoon*'] = {'at nighttime'} ,
timer = { 'at sunrise', 'at sunset'}
}
},
execute = function(domoticz,Telefoon,TriggerInfo)
if TriggerInfo.trigger == "at sunrise" then
domoticz.devices('Tuin').switchOff()
elseif TriggerInfo.trigger == "at sunset" then
if domoticz.devices("Telefoon_Jeanine").state == "On" or domoticz.devices("Telefoon_Roy").state == "On" then
domoticz.devices('Tuin').switchOn()
end
else
if Telefoon.state == 'On' then
domoticz.devices('Tuin').switchOn()
elseif domoticz.devices("Telefoon_Jeanine").state == "Off" and domoticz.devices("Telefoon_Roy").state == "Off" then
domoticz.devices('Tuin').switchOff()
end
end
end
}
Re: AND function kills script
Posted: Sunday 14 January 2018 23:34
by R0yk3
Thankyou, I wil try this tonight.
Just for me to learn as i think i understand the script.
{'at nighttime'} is a device????
and what is the difference between the red parts in the script:
I use spoiler so i can use colors
- Spoiler: show
-
else
if Telefoon.state == 'On' then
domoticz.devices('Tuin').switchOn()
elseif domoticz.devices("Telefoon_Jeanine").state == "Off" and domoticz.devices("Telefoon_Roy").state == "Off" then
domoticz.devices('Tuin').switchOff()
Loads of other questions because just starting with the dzvents.. Until now just copy paste scripts, so i would like to know what i did wrong in my version of the script.
Re: AND function kills script
Posted: Monday 15 January 2018 21:20
by R0yk3
Re: AND function kills script
Posted: Monday 15 January 2018 23:17
by waaren
Maybe you found out already but to clarify:
devices = { ['Telefoon*'] = {'at nighttime'} -- Trigger script on any change to devices with a name starting with Telefoon but only at nighttime
Telefoon.state == 'On' then -- Check if state of (the single) device that triggered the script is 'On'
domoticz.devices("Telefoon_Jeanine").state == "Off" and domoticz.devices("Telefoon_Roy").state == "Off" then
-- Only true if both phone states are "Off"
Re: AND function kills script
Posted: Monday 15 January 2018 23:23
by R0yk3
Waaren, Thank you!!
Re: AND function kills script
Posted: Wednesday 17 January 2018 6:03
by Luuc_a
I do some thing similar to your needs. I have edited the code I used to your needs
Code: Select all
return {
on = {
devices = {
'Telefoon*'
}
},
execute = function(domoticz, device)
local home = false
--Look in Domoticz for each device started with Telefoon. If a device has the status on, then set local var "Home" to True
domoticz.devices().forEach(function(device)
if string.find(device.name,'Telefoon') then
if (device.state == 'On') then
home=true
end
end
end )
if home==false then
domoticz.log('Nobody home' .. device.name, domoticz.LOG_INFO)
domoticz.devices('Tuinverlichting').switchOff().checkfirst()
else
domoticz.log('Somebody home' .. device.name, domoticz.LOG_INFO)
domoticz.devices('Tuinverlichting').switchOn().checkfirst()
end
domoticz.log('Device ' .. device.name .. ' was changed', domoticz.LOG_INFO)
end
}
Every device had the name "Telefoon....." and the script is triggerd by that device. In the for each loop you check if one of the devices with that name is "On". If there is another device is On the "Tuinverlichting" will stay on.
Maybe you can use this and edit to your needs.
Edit/
The only thing I don't have is the check for nighttime.
Re: AND function kills script
Posted: Wednesday 17 January 2018 6:35
by R0yk3
Thankyou. This helpes me learn the language.