Disable Use of Switch or Group [Solved]
Moderator: leecollings
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Disable Use of Switch or Group
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
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch o Group
waaren wrote: ↑Friday 26 July 2019 20:32[EDIT] added switchTrigger_*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.
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 belowWhen not yet familiar with dzVents please start with reading Get started Before implementing. Special attention please forCode: 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 }
"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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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?
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?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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! 


- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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
thank you so much
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
Any news please help me thx
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
did you check the latest script. The security system parts are commented so no longer active in this script.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
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.djdevil wrote: ↑Monday 05 August 2019 0:49 [thx for reply i try the code but have this errorCode: Select all
EventSystem: in Script #2: [string "-- Secure devices using protect API..."]:22: attempt to index global 'domoticz' (a nil value)
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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
Thx
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
"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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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.

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.


- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
Please show the log when you switch the "at home" switch.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.![]()
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
i see but thereisnt nothing
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Disable Use of Switch or Group
Is dzVents and logging enabled and is the name of the switch exactly as in the script ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
- djdevil
- Posts: 101
- Joined: Friday 26 July 2019 18:19
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2021.1
- Contact:
Re: Disable Use of Switch or Group
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
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
Who is online
Users browsing this forum: No registered users and 1 guest