Page 1 of 2
Disable Use of Switch or Group
Posted: Friday 26 July 2019 19:20
by djdevil
hi to all, I have a problem in practice I have 6 roller shutter fibaro that control the shutters and I have created a group where I control through controlicz for alexa command the opening and the closing. Now I would like to understand how to disable the voice command or the use of this group when I activate the alarm mode or when I am away from home. my concern is that if any neighbor even from outside the entrance door pronounces alex open house the command starts.
if you could kindly tell me some solution like some command to disable the use of the switch based on my presence or when I arm the domoticz panel. but I didn't understand how to proceed thanks
Re: Disable Use of Switch o Group
Posted: Friday 26 July 2019 20:44
by waaren
waaren wrote: ↑Friday 26 July 2019 20:32
djdevil wrote: ↑Friday 26 July 2019 19:20
controlicz for alexa command the opening and the closing. Now I would like to understand how to disable the voice command or the use of this group when I activate the alarm mode or when I am away from home
if you could kindly tell me some solution like some command to disable the use of the switch based on my presence or when I arm the domoticz panel.
[EDIT] added switchTrigger_*
My solution is to have Alexa switch a virtual switch switchTrigger_<switchName>, groupTrigger_<groupName> / sceneTrigger_<sceneName> and use this dzvents script to conditional process the state of this triggerswitch based on the current security state.
See script below
Code: Select all
--Secure Switch / Group / Scene Trigger
return
{
on =
{ devices =
{
'groupTrigger_*',
'sceneTrigger_*',
'switchTrigger_*',
}
},
logging =
{
level = domoticz.LOG_DEBUG, -- Set to error when script is OK
marker = 'Secure trigger'
},
execute = function(dz, item)
if dz.security == dz.SECURITY_DISARMED then
local target = (item.name):gsub('groupTrigger_',''):gsub('sceneTrigger_',''):gsub('switchTrigger_','') -- remove sub strings
if (item.name):sub(1,2) == 'sw' then -- Switches can be switched On or Off
if item.active then
dz.log('Switch ' .. target .. ' will be switched On',dz.LOG_DEBUG)
dz.devices(target).switchOn()
else
dz.log('Switch ' .. target .. ' will be switched Off',dz.LOG_DEBUG)
dz.devices(target).switchOff()
end
elseif (item.name):sub(1,1) == 'g' then -- Groups (can be switched On or Off)
if item.active then
dz.log('Group ' .. target .. ' will be switched On',dz.LOG_DEBUG)
dz.groups(target).switchOn()
else
dz.log('Group ' .. target .. ' will be switched Off',dz.LOG_DEBUG)
dz.groups(target).switchOff()
end
elseif item.active then -- scenes (can only be switched On)
dz.log('Scene ' .. target .. ' will be switched On',dz.LOG_DEBUG)
dz.scenes(target).switchOn()
item.switchOff().silent()
end
else
dz.log('No triggering allowed while security is set to !! ' .. dz.security .. " !!" , dz.LOG_ERROR)
end
end
}
When not yet familiar with dzVents please start with reading
Get started Before implementing. Special attention please for
"In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents disabled' is not checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."
Please feel free to ask if anything is not clear yet.
Re: Disable Use of Switch or Group
Posted: Friday 26 July 2019 20:53
by djdevil
Thanks a lot for the answer
more or less I understood the concept for I don't know how to put it into practice you could tell me where should I change the code? do i have to do it for each buckle and switch?
Re: Disable Use of Switch or Group
Posted: Friday 26 July 2019 21:01
by waaren
djdevil wrote: ↑Friday 26 July 2019 20:53
Thanks a lot for the answer
more or less I understood the concept for I don't know how to put it into practice you could tell me where should I change the code? do i have to do it for each buckle and switch?
No dzVents code change needed because it is generic. You have to add a virtual switch for every switch / group and scene you want to protect.
If that is too much of a pain you could also look for a solution that disables controlicz / Alexa completely when security is armed. Happy to help with that if you can tell me what is needed at the OS level / controlicz API to do that.
Re: Disable Use of Switch or Group
Posted: Saturday 27 July 2019 2:34
by waaren
djdevil wrote: ↑Friday 26 July 2019 20:53
more or less I understood the concept
Different approach based on the comment @madgeni made about protect API
Code: Select all
-- Secure devices using protect API
-- Add device IDX to protect to deviceList table
return
{
on =
{ security =
{
domoticz.SECURITY_ARMEDAWAY,
domoticz.SECURITY_ARMEDHOME,
domoticz.SECURITY_DISARMED,
},
devices =
{
'atHome switch', -- if active and security disarmed then devices are unprotected
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- Set to error when script is OK
marker = 'Secure trigger2'
},
execute = function(dz, item)
local deviceList = { 35, -- Replace / Add your device IDX numbers here
2228,
2277,
}
local protectMe = true
if item.isSecurity or ( item.isDevice and item.active ) then
protectMe = ( dz.security ~= dz.SECURITY_DISARMED ) -- Only when at home and disarmed are devices unprotectd
end
local function protect(idx)
local url = dz.settings['Domoticz url'] .. '/json.htm?type=setused&used=true' ..
'&protected=' .. tostring(protectMe) ..
'&idx=' .. idx
dz.openURL(url)
end
for _, idx in ipairs(deviceList) do
protect(idx)
end
end
}
Re: Disable Use of Switch or Group
Posted: Saturday 27 July 2019 22:00
by djdevil
I don't know how to thank

, function and perfect now when I arm the system and the presence switch is off the shutter buckles are password protected!

Re: Disable Use of Switch or Group
Posted: Friday 02 August 2019 22:46
by djdevil
I'm still here asking for help, I wanted to know if instead I want to protect the devices only based on the activation of the presence switch as I have to change the code thanks
Re: Disable Use of Switch or Group
Posted: Saturday 03 August 2019 12:49
by waaren
djdevil wrote: ↑Friday 02 August 2019 22:46
I'm still here asking for help, I wanted to know if instead I want to protect the devices only based on the activation of the presence switch as I have to change the code thanks
For this the code should look like
Code: Select all
-- Secure devices using protect API
-- Add device IDX to protect to deviceList table
return
{
on =
{ -- security =
-- {
-- domoticz.SECURITY_ARMEDAWAY,
-- domoticz.SECURITY_ARMEDHOME,
-- domoticz.SECURITY_DISARMED,
-- },
devices =
{
'atHome switch', -- if active then devices are unprotected
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- Set to error when script is OK
marker = 'Secure trigger2'
},
execute = function(dz, item)
local deviceList = { 35, -- Replace / Add your device IDX numbers here
2228,
2277,
}
local protectMe = not(item.active)
-- if item.isSecurity or ( item.isDevice and item.active ) then
-- protectMe = ( dz.security ~= dz.SECURITY_DISARMED ) -- Only when at home and disarmed are devices unprotectd
-- end
local function protect(idx)
local url = dz.settings['Domoticz url'] .. '/json.htm?type=setused&used=true' ..
'&protected=' .. tostring(protectMe) ..
'&idx=' .. idx
dz.openURL(url)
end
for _, idx in ipairs(deviceList) do
protect(idx)
end
end
}
Re: Disable Use of Switch or Group
Posted: Saturday 03 August 2019 12:58
by djdevil
thanks for the reply, I meant to exclude the alarm system in the code and use only the presence switch as a condition. type if the presence swtich is on protect and off does not protect.
thank you so much
Re: Disable Use of Switch or Group
Posted: Sunday 04 August 2019 23:23
by djdevil
Any news please help me thx
Re: Disable Use of Switch or Group
Posted: Sunday 04 August 2019 23:59
by waaren
djdevil wrote: ↑Sunday 04 August 2019 23:23
Any news please help me thx
did you check the latest script. The security system parts are commented so no longer active in this script.
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 0:49
by djdevil
waaren wrote: ↑Sunday 04 August 2019 23:59
djdevil wrote: ↑Sunday 04 August 2019 23:23
Any news please help me thx
did you check the latest script. The security system parts are commented so no longer active in this script.
thx for reply i try the code but have this error
EventSystem: in Script #2: [string "-- Secure devices using protect API..."]:22: attempt to index global 'domoticz' (a nil value)
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 9:57
by waaren
djdevil wrote: ↑Monday 05 August 2019 0:49
[thx for reply i try the code but have this error
Code: Select all
EventSystem: in Script #2: [string "-- Secure devices using protect API..."]:22: attempt to index global 'domoticz' (a nil value)
This is not a dzVents error but one from the domoticz EventSystem. Most likely you tried to save the script as a Lua type. You should save it as a dzVents type.
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 10:57
by djdevil
hello yes in fact I had the wrong section and I entered as a script lua. but inserting it correctly still does not work! does not protect my switches! what's the problem?
Thx
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 11:23
by waaren
djdevil wrote: ↑Monday 05 August 2019 10:57
hello yes in fact I had the wrong section and I entered as a script lua. but inserting it correctly still does not work! does not protect my switches! what's the problem?
Thx
"It does not work" is almost never a good starting point for finding the reason

.
It 's about as meaningless as my reply "It does for me"
- What do you see in the log ?
- Which domoticz / dzVents version do you use.
- Did you read the
Using dzVents with Domoticz section of the dzVents wiki and did you apply the required setting in the domoticz security settings as described there ?
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 18:12
by djdevil
hello waaren thx for reply,
Yes i see log no error but the code not work when switch "at home" is off not protect,
While the old code work perfect with condition of security arm.

Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 19:00
by waaren
djdevil wrote:
Yes i see log no error but the code not work when switch "at home" is off not protect,
While the old code work perfect with condition of security arm.

Please show the log when you switch the "at home" switch.
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 19:13
by djdevil
i see but thereisnt nothing
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 19:22
by waaren
djdevil wrote: ↑Monday 05 August 2019 19:13
i see but thereisnt nothing
Is dzVents and logging enabled and is the name of the switch exactly as in the script ?
Re: Disable Use of Switch or Group
Posted: Monday 05 August 2019 23:05
by djdevil
The name of switch is "Presenza"
2019-08-05 23:04:06.997 (Posizione) Lighting 1 (Presenza)
2019-08-05 23:04:06.992 Status: User: davide initiated a switch command (253/Presenza/Off)
2019-08-05 23:04:07.110 Status: dzVents: Debug: Processing device-adapter for Presenza: Switch device adapter
2019-08-05 23:04:07.111 Status: dzVents: Debug: - Device: Presenza
this debug when on
2019-08-05 23:05:07.077 Status: Notification: Presenza >> ON
2019-08-05 23:05:07.176 Status: dzVents: Debug: Processing device-adapter for Presenza: Switch device adapter
2019-08-05 23:05:07.176 Status: dzVents: Debug: - Device: Presenza