The problem is that the script does not know if the light is switched on by the script or by you manually. So it will just switch off if lux is not < 38.
So in your first if statement add a boolean true/false for script switched on and then check in the else if for the boolean.
Problem with checkFirst() ?
Moderator: leecollings
- waltervl
- Posts: 5853
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Problem with checkFirst() ?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- waltervl
- Posts: 5853
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Problem with checkFirst() ?
CheckFirst() will only check if it is already in the desired state. If so it will not send the switch command. This will prevent switch triggers for other scripts using that device.
I added the switchedonbyscript boolean in your script. I hope it works....
Edit: added switchedonbyscript = false in switch off section.
I added the switchedonbyscript boolean in your script. I hope it works....
Edit: added switchedonbyscript = false in switch off section.
Code: Select all
local
return {
on = { devices = {['PIR chodba'] = {'between 23:00 and 06:00'}} -- <<< --- set activity time
},
data = { switchedonbyscript = { initial = false }
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "Pohyb v chodbě"
},
execute = function(dz, item)
local function logWrite(str,level)
dz.log(str,level or dz.LOG_DEBUG)
end
-- local Lux = dz.devices("Motion Sensor LUX").lux
local LuxDevice = dz.devices(26) -- <<<--- replace xxx by IDX of your Lux device
local Lux = LuxDevice.lux
-- local Lights = dz.devices("WLED - Color & Brightness")
local Lights = dz.devices(172) -- <<<--- replace xxx by IDX dummy switch
logWrite(LuxDevice.name .. " ==>> Lux: " .. Lux )
logWrite(Lights.name .. " ==>> State: " .. Lights.state)
logWrite(item.name .. " ==>> State: " .. item.state)
if Lux < 38 and item.state == "On" and Lights.state == "Off" then -- <<< --- set value LUX for switching
Lights.cancelQueuedCommands()
switchedonbyscript = true -- Switched on by script
Lights.switchOn() -- checkfirst not needed as it is Off
Lights.dimTo(10) -- <<< --- set value dummy switch "LEVEL"
elseif item.state == "Off" and switchedonbyscript then -- only switch off when switched on by script
Lights.switchOff().checkFirst().afterSec(5) -- If light already off do nothing
switchedonbyscript = false
end
end
}
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
- waltervl
- Posts: 5853
- Joined: Monday 28 January 2019 18:48
- Target OS: Linux
- Domoticz version: 2024.7
- Location: NL
- Contact:
Re: Problem with checkFirst() ?
That check you described is the checkFirst() function. Check first before doing it.Mayki wrote: ↑Tuesday 28 November 2023 18:11 So I tried it and unfortunately this doesn't work. The LED strip lights up after a signal from the PIR sensor, but it doesn't go off.
Is there any option (command) to ensure that the script checks if the dimmer is in ON state before executing the command and does not start? If it is in the OFF state, everything will run normally.
Also it could be that in my script the check first and aftersec should be switched in order.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Who is online
Users browsing this forum: No registered users and 1 guest