Page 1 of 1
switch error
Posted: Wednesday 13 January 2021 15:37
by kroonp
Hello all,
Can anyone see what I am doing wrong in the script?
The intention is that if I turn on one switch, the other 2 will turn off.
However, this does not happen.
As soon as I press a switch, it lights up briefly and goes out again. The others don't respond.
Thank you for thinking along.
Peter
----------------------------------------
Code: Select all
return {
on = {
devices = {
'Thuis',
'Afwezig',
'Vakantie'
}
},
logging =
{
level = domoticz.LOG_ERROR, -- change to dz.LOG_ERROR when script is OK
marker = 'test Statuscontrole',
},
execute = function(dz)
local Thuis = dz.devices('Thuis')
local Vakantie=dz.devices('Vakantie')
local Afwezig=dz.devices('Afwezig') -- idx 395
if(Thuis.state=='On') then
Afwezig.switchOff()
Vakantie.switchOff()
elseif(Afwezig.state=='On') then
Thuis.switchOff()
Vakantie.switchOff()
elseif(Vakantie.state=='On') then
Thuis.switchOff()
Afwezig.switchOff()
end
end
}
Re: switch error
Posted: Wednesday 13 January 2021 17:32
by waaren
kroonp wrote: ↑Wednesday 13 January 2021 15:37
As soon as I press a switch, it lights up briefly and goes out again. The others don't respond.
Below modified script turns on more logging, shows which device caused the execution of the script and switches the devices silent() so the will not cause a subsequent execution of the script.
Code: Select all
return
{
on =
{
devices =
{
'Thuis',
'Afwezig',
'Vakantie',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to dz.LOG_ERROR when script is OK
marker = 'test Statuscontrole',
},
execute = function(dz, item)
dz.log(item.name .. ', State: ' .. item.state .. ', Type: ' .. item.deviceType, dz.LOG_DEBUG )
local Thuis = dz.devices('Thuis')
local Vakantie = dz.devices('Vakantie')
local Afwezig = dz.devices('Afwezig') -- idx 395
if (Thuis.state == 'On') then
Afwezig.switchOff().silent()
Vakantie.switchOff().silent()
elseif (Afwezig.state == 'On') then
Thuis.switchOff().silent()
Vakantie.switchOff().silent()
elseif (Vakantie.state == 'On') then
Thuis.switchOff().silent()
Afwezig.switchOff().silent()
end
end
}
Re: switch error
Posted: Wednesday 13 January 2021 22:23
by kroonp
Hallo waaren,
Unfortunately, it doesn't work as expected. Apparently there is still an error in the script.
The intention is that if I turn on one of the switches the other 2 will go out. I don't get it working either with if or elseif.
Is there any other way to get this working.
Peter
Re: switch error
Posted: Thursday 14 January 2021 0:50
by waaren
kroonp wrote: ↑Wednesday 13 January 2021 22:23
The intention is that if I turn on one of the switches the other 2 will go out. I don't get it working either with if or elseif.
Is there any other way to get this working.
The script logic is OK.
What do you see in the log?
Re: switch error
Posted: Thursday 14 January 2021 10:02
by kroonp
The log when i push the 3 switches
- Spoiler: show
-
Code: Select all
2021-01-14 09:59:15.614 Status: dzVents: Debug: test Statuscontrole: Afwezig, State: Off, Type: Light/Switch
2021-01-14 09:59:15.615 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Thuis: Switch device adapter
2021-01-14 09:59:15.615 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Vakantie: Switch device adapter
2021-01-14 09:59:15.615 Status: dzVents: Info: test Statuscontrole: ------ Finished 00 AB test
2021-01-14 09:59:17.880 Status: dzVents: Info: test Statuscontrole: ------ Start internal script: 00 AB test: Device: "Afwezig (Virtual switch)", Index: 225
2021-01-14 09:59:17.880 Status: dzVents: Debug: test Statuscontrole: Afwezig, State: On, Type: Light/Switch
2021-01-14 09:59:17.881 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Thuis: Switch device adapter
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Vakantie: Switch device adapter
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:17.898 Status: dzVents: Info: test Statuscontrole: ------ Finished 00 AB test
2021-01-14 09:59:51.846 Status: dzVents: Info: test Statuscontrole: ------ Start internal script: 00 AB test: Device: "Vakantie (Dummy)", Index: 246
2021-01-14 09:59:51.846 Status: dzVents: Debug: test Statuscontrole: Vakantie, State: On, Type: Light/Switch
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Thuis: Switch device adapter
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Afwezig: Switch device adapter
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:51.849 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:51.849 Status: dzVents: Info: test Statuscontrole: ------ Finished 00 AB test
Re: switch error
Posted: Thursday 14 January 2021 10:56
by kroonp
I also tried this script.
Does not work either.
Peter
-----------
Code: Select all
return
{
on =
{
devices =
{
'Thuis',
'Afwezig',
'Vakantie',
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to dz.LOG_ERROR when script is OK
marker = 'Testing Statuscontrole',
},
execute = function(dz, item)
dz.log(item.name .. ', State: ' .. item.state .. ', Type: ' .. item.deviceType, dz.LOG_DEBUG )
local Thuis = dz.devices('Thuis')
local Vakantie = dz.devices('Afwezig')
local Afwezig = dz.devices('Vakantie') -- idx 395
if(item.name=='Thuis') then
if (Thuis.state == 'On') then
if Afwezig.state=='On' then
Afwezig.switchOff()
end
if Vakantie.state=='On' then
Afwezig.switchOff()
end
end
end
if(item.name=='Afwezig') then
if (Afwezig.state == 'On') then
if Thuis.state=='On' then
Thuis.switchOff()
end
if Vakantie.state=='On' then
Vakantie.switchOff()
end
end
end
if(item.name=='Vakantie') then
if (Vakantie.state == 'On') then
if Thuis.state=='On' then
Thuis.switchOff()
end
if Afwezig.state=='On' then
Afwezig.switchOff()
end
end
end
end
}
Index: 395
2021-01-14 10:51:17.198 Status: dzVents: Debug: Testing Statuscontrole: Thuis, State: On, Type: Light/Switch
2021-01-14 10:51:17.199 Status: dzVents: Debug: Testing Statuscontrole: Processing device-adapter for Afwezig: Switch device adapter
2021-01-14 10:51:17.199 Status: dzVents: Debug: Testing Statuscontrole: Processing device-adapter for Vakantie: Switch device adapter
2021-01-14 10:51:17.199 Status: dzVents: Info: Testing Statuscontrole: ------ Finished 00 AB test
Re: switch error
Posted: Thursday 14 January 2021 11:18
by waaren
kroonp wrote: ↑Thursday 14 January 2021 10:02
The log when i push the 3 switches
- Spoiler: show
-
Code: Select all
2021-01-14 09:59:15.614 Status: dzVents: Debug: test Statuscontrole: Afwezig, State: Off, Type: Light/Switch
2021-01-14 09:59:15.615 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Thuis: Switch device adapter
2021-01-14 09:59:15.615 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Vakantie: Switch device adapter
2021-01-14 09:59:15.615 Status: dzVents: Info: test Statuscontrole: ------ Finished 00 AB test
2021-01-14 09:59:17.880 Status: dzVents: Info: test Statuscontrole: ------ Start internal script: 00 AB test: Device: "Afwezig (Virtual switch)", Index: 225
2021-01-14 09:59:17.880 Status: dzVents: Debug: test Statuscontrole: Afwezig, State: On, Type: Light/Switch
2021-01-14 09:59:17.881 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Thuis: Switch device adapter
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Vakantie: Switch device adapter
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:17.898 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:17.898 Status: dzVents: Info: test Statuscontrole: ------ Finished 00 AB test
2021-01-14 09:59:51.846 Status: dzVents: Info: test Statuscontrole: ------ Start internal script: 00 AB test: Device: "Vakantie (Dummy)", Index: 246
2021-01-14 09:59:51.846 Status: dzVents: Debug: test Statuscontrole: Vakantie, State: On, Type: Light/Switch
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Thuis: Switch device adapter
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Processing device-adapter for Afwezig: Switch device adapter
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:51.848 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off
2021-01-14 09:59:51.849 Status: dzVents: Debug: test Statuscontrole: Constructed timed-command: Off NOTRIGGER
2021-01-14 09:59:51.849 Status: dzVents: Info: test Statuscontrole: ------ Finished 00 AB test
This log shows that the script works as expected and the right commands are send. What happens if you switch the devices in the Gui from the switch tab ?
Re: switch error
Posted: Thursday 14 January 2021 11:20
by waaren
kroonp wrote: ↑Thursday 14 January 2021 10:56
I also tried this script.
You don't have to modify the script. It works as expected. If the switches do not react there is another issue on the system.
Re: switch error
Posted: Thursday 14 January 2021 12:32
by kroonp
Thuis Afwezig Vakantie
Start postion Off Off Off
switch Thuis On On Off Off
switich Afwezig On On blink-Off Off
switchVakantie On On Off blink-Off
Start postion Off Off Off
switich Afwezig On Off On Off
switchVakantie On Off On blink-Off
switch Thuis On On Off Off
Start postion Off Off Off
switich Vakantie On Off Off ON
switch Afwezig On Off On Off
switch Thuis On On Off Off
Re: switch error
Posted: Thursday 14 January 2021 12:44
by kroonp
The third version ( from vakantie-afwezig to thuis) works Oke!
Re: switch error
Posted: Thursday 14 January 2021 13:31
by waaren
kroonp wrote: ↑Thursday 14 January 2021 12:44
The third version ( from vakantie-afwezig to thuis) works Oke!
Can you please double check that no other scripts are active- or On-Off actions / On-Off delays are defined for these switches?
Re: switch error
Posted: Thursday 14 January 2021 15:48
by kroonp
I closed all other scripts.
I restart system
Does not work
I created three new dummy's: een-twee-drie
I have adapted your script with the three new dummy switches. Get the same result as the third postions as above.
Code: Select all
return
{
on =
{
devices =
{
'een',
'twee',
'drie'
},
},
logging =
{
level = domoticz.LOG_DEBUG, -- change to dz.LOG_ERROR when script is OK
marker = 'test Statuscontrole',
},
execute = function(dz, item)
dz.log(item.name .. ', State: ' .. item.state .. ', Type: ' .. item.deviceType, dz.LOG_DEBUG )
local Thuis = dz.devices('een') -- 1847
local Vakantie = dz.devices('twee') -- 1848
local Afwezig = dz.devices('drie') -- 1849
if (Thuis.state == 'On') then
Afwezig.switchOff().silent()
Vakantie.switchOff().silent()
elseif (Afwezig.state == 'On') then
Thuis.switchOff().silent()
Vakantie.switchOff().silent()
elseif (Vakantie.state == 'On') then
Thuis.switchOff().silent()
Afwezig.switchOff().silent()
end
end
}
Re: switch error
Posted: Thursday 14 January 2021 16:21
by waaren
kroonp wrote: ↑Thursday 14 January 2021 15:48
I have adapted your script with the three new dummy switches. Get the same result as the third postions as above.
Found something. Because the script did not look at the item that triggered the script it always evaluates the first if.
I tested below version and that one does the job in all cases.
Code: Select all
return
{
on =
{
devices =
{
'Een',
'Twee',
'Drie'
},
},
logging =
{
level = domoticz.LOG_ERROR, -- change to dz.LOG_DEBUG when developing / debugging
marker = 'test Statuscontrole',
},
execute = function(dz, item)
local Thuis = dz.devices('Een') -- 1847
local Vakantie = dz.devices('Twee') -- 1848
local Afwezig = dz.devices('Drie') -- 1849
if item.active then
if item ~= Thuis then Thuis.switchOff().silent() end
if item ~= Vakantie then Vakantie.switchOff().silent() end
if item ~= Afwezig then Afwezig.switchOff().silent() end
end
end
}
Re: switch error [Solved]
Posted: Thursday 14 January 2021 16:41
by kroonp
Great that you found that. Now it works for me too. It took me and you a lot of effort but I am very happy that it is now working, I will be even more careful and check next time. Thanks again and have a nice day.
Peter