Problem with the blockly script turning on the light
Moderator: leecollings
-
Dave21w
- Posts: 399
- Joined: Sunday 29 November 2015 21:55
- Target OS: Raspberry Pi / ODroid
- Domoticz version: Stable
- Location: UK
- Contact:
Re: Problem with the blockly script turning on the light
If turned on individually do you want to disable the auto on via pir of both or only the one you have manually turned on
-
Maciek90
- Posts: 55
- Joined: Friday 05 March 2021 23:01
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Problem with the blockly script turning on the light
Only the one I turned on manually.
The script from madpatrick works exactly as I want. However, there's a problem, and I don't know what's causing it. Every few days, one of the lights won't turn off after a set time (30 seconds) after the motion sensor signal is turned off. I had the same problem with my script in Blockly.
The script from madpatrick works exactly as I want. However, there's a problem, and I don't know what's causing it. Every few days, one of the lights won't turn off after a set time (30 seconds) after the motion sensor signal is turned off. I had the same problem with my script in Blockly.
- madpatrick
- Posts: 758
- Joined: Monday 26 December 2016 12:17
- Target OS: Linux
- Domoticz version: 2025.2
- Location: Netherlands
- Contact:
Re: Problem with the blockly script turning on the light
Sounds it is not an script issue.
You can give extra/second switch off command but that makes no sense
You can give extra/second switch off command but that makes no sense
-= HP server GEN11 =- ZwaveJS-=- Domoticz v2025.2 -=- Dashticz =-
-= Checkout https://github.com/MadPatrick for the plugins =-
-= Checkout https://github.com/MadPatrick for the plugins =-
-
Maciek90
- Posts: 55
- Joined: Friday 05 March 2021 23:01
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Problem with the blockly script turning on the light
I thought about that tooSounds it is not an script issue.
I tried something like this in blockly but it didn't helpYou can give extra/second switch off command but that makes no sense
However, I noticed that this problem was more common with blockly. With dzVents, it happens once every few days. Any ideas what might be causing this?
- madpatrick
- Posts: 758
- Joined: Monday 26 December 2016 12:17
- Target OS: Linux
- Domoticz version: 2025.2
- Location: Netherlands
- Contact:
Re: Problem with the blockly script turning on the light
Is the switched off command triggered when it happens
If the command is send to the switch then it is not a acriot issue but hardware
If the command is send to the switch then it is not a acriot issue but hardware
-= HP server GEN11 =- ZwaveJS-=- Domoticz v2025.2 -=- Dashticz =-
-= Checkout https://github.com/MadPatrick for the plugins =-
-= Checkout https://github.com/MadPatrick for the plugins =-
- madpatrick
- Posts: 758
- Joined: Monday 26 December 2016 12:17
- Target OS: Linux
- Domoticz version: 2025.2
- Location: Netherlands
- Contact:
Re: Problem with the blockly script turning on the light
Can you try this
it should switch off the lamp 30 after after the last movement. When there will be new movement within the 30 sec it will reset to 30 sec again
it should switch off the lamp 30 after after the last movement. When there will be new movement within the 30 sec it will reset to 30 sec again
Code: Select all
local SCRIPT_NAME = 'PIR'
local LOG_LEVEL = domoticz.LOG_FORCE
local OFF_DELAY = 30
return {
on = {
devices = {68, 69, 1574, 1575},
},
logging = {
level = LOG_LEVEL,
marker = SCRIPT_NAME
},
execute = function(dz, device)
local pir1 = dz.devices(69)
local pir2 = dz.devices(1575)
local lamp1 = dz.devices(68)
local lamp2 = dz.devices(1574)
local lamp1PirVar = dz.variables('Lamp1_PIR')
local lamp2PirVar = dz.variables('Lamp2_PIR')
----------------------------------------------------------------
-- PIR 1 / Lamp 1
----------------------------------------------------------------
-- PIR detects motion → lamp ON or timer reset
if device.id == pir1.id and pir1.state == 'On' then
if lamp1.state == 'Off' then
lamp1.switchOn()
dz.log('PIR1 → Lamp1 ON', LOG_LEVEL)
end
-- mark lamp as PIR-controlled
lamp1PirVar.set(1)
-- cancel any pending OFF by reasserting ON
lamp1.switchOn().checkFirst()
dz.log('PIR1 → OFF timer reset', LOG_LEVEL)
end
-- PIR no motion → plan OFF
if device.id == pir1.id
and pir1.state == 'Off'
and lamp1.state == 'On'
and lamp1PirVar.value == 1
then
lamp1.switchOff().afterSec(OFF_DELAY)
dz.log('PIR1 → Lamp1 OFF in ' .. OFF_DELAY .. ' sec', LOG_LEVEL)
end
-- Lamp actually turned off → reset PIR flag
if device.id == lamp1.id
and lamp1.state == 'Off'
and lamp1PirVar.value == 1
then
lamp1PirVar.set(0)
dz.log('Lamp1 OFF → PIR mode reset', LOG_LEVEL)
end
-- Manual ON → disable PIR control
if device.id == lamp1.id
and lamp1.state == 'On'
and pir1.state == 'Off'
then
lamp1PirVar.set(0)
dz.log('Lamp1 manually ON → PIR disabled', LOG_LEVEL)
end
----------------------------------------------------------------
-- PIR 2 / Lamp 2
----------------------------------------------------------------
-- PIR detects motion → lamp ON or timer reset
if device.id == pir2.id and pir2.state == 'On' then
if lamp2.state == 'Off' then
lamp2.switchOn()
dz.log('PIR2 → Lamp2 ON', LOG_LEVEL)
end
lamp2PirVar.set(1)
-- cancel pending OFF
lamp2.switchOn().checkFirst()
dz.log('PIR2 → OFF timer reset', LOG_LEVEL)
end
-- PIR no motion → plan OFF
if device.id == pir2.id
and pir2.state == 'Off'
and lamp2.state == 'On'
and lamp2PirVar.value == 1
then
lamp2.switchOff().afterSec(OFF_DELAY)
dz.log('PIR2 → Lamp2 OFF in ' .. OFF_DELAY .. ' sec', LOG_LEVEL)
end
-- Lamp actually turned off → reset PIR flag
if device.id == lamp2.id
and lamp2.state == 'Off'
and lamp2PirVar.value == 1
then
lamp2PirVar.set(0)
dz.log('Lamp2 OFF → PIR mode reset', LOG_LEVEL)
end
-- Manual ON → disable PIR control
if device.id == lamp2.id
and lamp2.state == 'On'
and pir2.state == 'Off'
then
lamp2PirVar.set(0)
dz.log('Lamp2 manually ON → PIR disabled', LOG_LEVEL)
end
end
}
-= HP server GEN11 =- ZwaveJS-=- Domoticz v2025.2 -=- Dashticz =-
-= Checkout https://github.com/MadPatrick for the plugins =-
-= Checkout https://github.com/MadPatrick for the plugins =-
-
Maciek90
- Posts: 55
- Joined: Friday 05 March 2021 23:01
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
Re: Problem with the blockly script turning on the light
In this script, when I manually turn on the lamp and then the motion sensor is triggered and then turned off, after 30 seconds the lamps also turn off. The variables also change their value to 1.
Who is online
Users browsing this forum: No registered users and 1 guest