Problem with script

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
User avatar
Varazir
Posts: 482
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Problem with script

Post by Varazir »

Hello,

Something making abounding this platform soon.
There are always something that's not working between this zigbee2mqtt/zwave-js-ui/MQTT5 and Domoticz and I can't see any way to troubleshoot in where the problem are.

Is the update sent from zigbee2mqtt or zwave-js-ui to MQTT5?
Have Domoticz read the update ?

Feels like it's a black hole you can't see the whole picture with MQTT Explorer
I need to jump around in 4 different logs to even understand what's going on. It was so much better if everything could be in one log.

But over to my issue now.

This script has worked just fine for months but right it just stopped working and I don't understand why
Yes it's built using Gemini

Code: Select all

--[[
    Improved script for bedroom and hall lighting based on motion and a roller blind.

    Features:
    1.  Turns on lights on motion only if it is night AND the roller blind is down.
    2.  Ignores motion during the daytime, even if the roller blind is down.
    3.  If motion stops, schedules the lights to turn off.
    4.  If motion is detected again, the scheduled turn-off is cancelled.
    5.  This also works if the light was turned on manually.
    6.  Execution is BLOCKED between 22:00 and 06:00.
--]]
return {
    on = {
        devices = {
            'IKEA - Sensor sovrum' -- Change name if your sensor is named differently
        }
    },
    logging = {
        level = domoticz.LOG_INFO, -- Change to domoticz.LOG_FORCE for detailed debugging
        marker = "BedroomLogic"
    },
    execute = function(dz, motionSensor)
        -- Check if current time is within the blocked period. If so, stop the script.
        if dz.time.matchesRule('at nighttime between 23:00 and 06:00') then
            dz.log('Execution blocked between 23:00 and 06:00. Aborting.', dz.LOG_INFO)
            return -- Exit the script immediately
        end

        -- --- Settings ---
        local RULLGARDIN_SOVRUM = 304
        local LAMPA_SOVRUM = 287
        local LAMPA_HALL = 292
        
        local BLIND_LEVEL_CLOSED = 90 -- % level for the blind to be considered closed
        local BRIGHTNESS_LEVEL = 60 -- Brightness level when turning on (in %)
        local OFF_DELAY_SECONDS = 300 -- Time in seconds before turning off the lights (300s = 5 min)
        
        -- Get the device objects
        local blind = dz.devices(RULLGARDIN_SOVRUM)
        local lampBedroom = dz.devices(LAMPA_SOVRUM)
        local lampHall = dz.devices(LAMPA_HALL)

        if motionSensor.state == 'On' then
            -- MOTION HAS STARTED
            
            -- Always cancel any scheduled turn-off commands
            lampBedroom.cancelQueuedCommands()
            lampHall.cancelQueuedCommands()
            dz.log('Motion detected. Cancelling any scheduled turn-off.', dz.LOG_INFO)

            -- Check if the conditions to turn on the lights are met
            if dz.time.isNightTime and blind.level >= BLIND_LEVEL_CLOSED then
                dz.log('Conditions met (Night & Blind Down). Turning lights ON.', dz.LOG_FORCE)
                lampBedroom.dimTo(BRIGHTNESS_LEVEL)
                lampHall.dimTo(BRIGHTNESS_LEVEL)
            else
                dz.log('Conditions not met to turn on (Daytime or blind is open). Ignoring.', dz.LOG_INFO)
            end
            
        else -- motionSensor.state == 'Off'
            -- MOTION HAS STOPPED
            
            -- If any of the lights are on, schedule them to turn off.
            if lampBedroom.state ~= 'Off' or lampHall.state ~= 'Off' then
                dz.log('No more motion. Scheduling lights to turn OFF in ' .. OFF_DELAY_SECONDS .. ' seconds.', dz.LOG_FORCE)
                lampBedroom.dimTo(0).afterSec(OFF_DELAY_SECONDS)
                lampHall.dimTo(0).afterSec(OFF_DELAY_SECONDS)
            end
        end
    end
}
The error I get is

Code: Select all

2025-10-15 19:35:52.586 dzVents: BedroomLogic: Motion detected. Cancelling any scheduled turn-off.
2025-10-15 19:35:52.586 dzVents: BedroomLogic: Conditions not met to turn on (Daytime or blind is open). Ignoring.
I understand the error but this my timers are this and Blinder was at 90% so I don't see why it should say "Conditions not met"
Image
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
jannl
Posts: 823
Joined: Thursday 02 October 2014 6:36
Target OS: Raspberry Pi / ODroid
Domoticz version: 2025.5.x
Location: Geleen
Contact:

Re: Problem with script

Post by jannl »

You checked the batteries of your sensor? Some sensors tend to generate more motion when the battery is closer to empty.

Using zigbee2mqtt and zwave for over 5 years without any problems.
User avatar
Varazir
Posts: 482
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Problem with script

Post by Varazir »

jannl wrote: Wednesday 15 October 2025 19:59 You checked the batteries of your sensor? Some sensors tend to generate more motion when the battery is closer to empty.

Using zigbee2mqtt and zwave for over 5 years without any problems.
I noticed it for one of my other sensors but in this case positiv motion. I was in the room.
So the script is triggered but something buggs out when it checking the values for the blinder and if it's night time.

Could be HW issue as well, I have issue with a wallet plugg that send Current Watt but for some reason kWh stops reporting(red) in Domoticz.
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Problem with script

Post by waltervl »

You better add some extra debug logging to understand why conditions are not met. So for example log the blind-level too.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Varazir
Posts: 482
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Problem with script

Post by Varazir »

The blinder reporter 40 and not 90 as it did before
Added debug

Code: Select all

dz.log('DEBUG: Value of dz.time.isNightTime is: ' .. tostring(isNight), dz.LOG_FORCE)
            
            -- Check 2: Blind level condition
            if blind ~= nil then
                local currentBlindLevel = blind.level
                dz.log('DEBUG: Value of blind.level is: ' .. tostring(currentBlindLevel), dz.LOG_FORCE)
                dz.log('DEBUG: Required blind level (BLIND_LEVEL_CLOSED) is: ' .. tostring(BLIND_LEVEL_CLOSED), dz.LOG_FORCE)
                
                local isBlindClosedEnough = (currentBlindLevel >= BLIND_LEVEL_CLOSED)
                dz.log('DEBUG: Is (blind.level >= BLIND_LEVEL_CLOSED)? Result: ' .. tostring(isBlindClosedEnough), dz.LOG_FORCE)
            else
                dz.log('DEBUG ERROR: Could not find the blind device with ID ' .. tostring(RULLGARDIN_SOVRUM) .. '. Is the ID correct?', dz.LOG_ERROR)
            end

            dz.log('--- ENDING DEBUG CHECK ---', dz.LOG_FORCE)

Code: Select all

2025-10-16 21:03:41.923 dzVents: !Info: BedroomLogic: --- STARTING DEBUG CHECK ---
2025-10-16 21:03:41.923 dzVents: !Info: BedroomLogic: DEBUG: Value of dz.time.isNightTime is: true
2025-10-16 21:03:41.923 dzVents: !Info: BedroomLogic: DEBUG: Value of blind.level is: 40
2025-10-16 21:03:41.923 dzVents: !Info: BedroomLogic: DEBUG: Required blind level (BLIND_LEVEL_CLOSED) is: 40
2025-10-16 21:03:41.923 dzVents: !Info: BedroomLogic: DEBUG: Is (blind.level >= BLIND_LEVEL_CLOSED)? Result: true
2025-10-16 21:03:41.923 dzVents: !Info: BedroomLogic: --- ENDING DEBUG CHECK ---

Image

Changed 40 in the script and it's working.
Gemini said it could have due to the the blinder do not report back correct.
But I don't understand why the current stat page say 90 but the script see it 40. It's some conversion ?
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
User avatar
waltervl
Posts: 6677
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2025.1
Location: NL
Contact:

Re: Problem with script

Post by waltervl »

I am not aware of a conversion. Perhaps some lagging of data. In your screenshot it says 90% but value is 10 so there seems to be a reverse setting. See the wiki blinds page as you can do some settings now (compared to a old 2021 Domoticz version) https://wiki.domoticz.com/Blinds
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
Varazir
Posts: 482
Joined: Friday 20 February 2015 22:23
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Problem with script

Post by Varazir »

waltervl wrote: Thursday 16 October 2025 21:19 I am not aware of a conversion. Perhaps some lagging of data. In your screenshot it says 90% but value is 10 so there seems to be a reverse setting. See the wiki blinds page as you can do some settings now (compared to a old 2021 Domoticz version) https://wiki.domoticz.com/Blinds
Yes it's set in reversed.

I tested to change to this but it didn't do anything
Image
Raspberry PI 4 with RaZberry Controller 2016 ZWave+ and CC2531(zigbee)
Several IKEA devices/z-wave devices
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest