Flash lights when fridge is left open [Solved]  [Solved]

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

Moderator: leecollings

Post Reply
Buteo72
Posts: 3
Joined: Monday 16 December 2019 18:43
Target OS: Windows
Domoticz version:
Contact:

Flash lights when fridge is left open [Solved]

Post by Buteo72 »

Hello, so now and then the door from the fridge is left open. --> some nasty issues then.

I want to flash some lights if the door is left open for x minutes.
I get the lights flashing with the code below, but only when lights are off.
I tried to set them off but the lamps are not reacting and are not set to off.

Someone any clue?

Code: Select all

return {
	on = {
		timer = {
			'every minute',              -- causes the script to be called every minute
	   },
    },
	execute = function(domoticz, timer)
	    
		domoticz.log('======================== ', domoticz.LOG_INFO)
		domoticz.log('======================== ', domoticz.LOG_INFO)
		domoticz.log('======================== ', domoticz.LOG_INFO)
		domoticz.log('Diepvries trigger started ' .. timer.trigger, domoticz.LOG_INFO)

	    local diepVriesDeur     = domoticz.devices('DiepvriesSensor')
	    local sonoffKeuken      = domoticz.devices('sonoff keuken')
	    local sonoffKeukenKoof  = domoticz.devices('sonoff keukenkoof')

		--first turn off the lights if the are on
		
		if (sonoffKeuken.active) then
    		sonoffKeuken.switchOff().silent()
        end
		if (sonoffKeukenKoof.active) then
    		sonoffKeukenKoof.switchOff().silent()
        end

		if (diepVriesDeur.state == 'Open' and diepVriesDeur.lastUpdate.minutesAgo > 1) then  -- > 1 to be change to a higher value when script is final
    		domoticz.log('Dievries trigger: hij staat open, laat de lampen knipperen... ', domoticz.LOG_INFO)
			--domoticz.notify('Dievriesdeur alert', 'De diepvriesdeur staat al meer dan 5 minuten open!', domoticz.PRIORITY_HIGH)

    		-- flash a light for 5 times
			sonoffKeuken.switchOn().forSec(1).repeatAfterSec(1, 5)
			sonoffKeukenKoof.switchOn().forSec(1).repeatAfterSec(1, 5)
		end

	end
}


The log give the following info:
Spoiler: show
2020-03-23 23:35:00.128 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:00.128 Status: dzVents: Debug: - Timer
2020-03-23 23:35:00.185 Status: dzVents: Info: ------ Start internal script: Diepvries:, trigger: every minute
2020-03-23 23:35:00.185 Status: dzVents: Info: ========================
2020-03-23 23:35:00.185 Status: dzVents: Info: ========================
2020-03-23 23:35:00.185 Status: dzVents: Info: ========================
2020-03-23 23:35:00.186 Status: dzVents: Info: Diepvries trigger started every minute
2020-03-23 23:35:00.220 Status: dzVents: Debug: Processing device-adapter for DiepvriesSensor: Switch device adapter
2020-03-23 23:35:00.221 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:00.221 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:00.222 Status: dzVents: Debug: Constructed timed-command: Off
2020-03-23 23:35:00.222 Status: dzVents: Debug: Constructed timed-command: Off NOTRIGGER
2020-03-23 23:35:00.222 Status: dzVents: Debug: Constructed timed-command: Off
2020-03-23 23:35:00.222 Status: dzVents: Debug: Constructed timed-command: Off NOTRIGGER
2020-03-23 23:35:00.222 Status: dzVents: Info: Dievries trigger: hij staat open, laat de lampen knipperen...
2020-03-23 23:35:00.222 Status: dzVents: Debug: Constructed timed-command: On
2020-03-23 23:35:00.223 Status: dzVents: Debug: Constructed timed-command: On FOR 1 SECONDS
2020-03-23 23:35:00.223 Status: dzVents: Debug: Constructed timed-command: On FOR 1 SECONDS REPEAT 6 INTERVAL 1 SECONDS
2020-03-23 23:35:00.223 Status: dzVents: Debug: Constructed timed-command: On
2020-03-23 23:35:00.223 Status: dzVents: Debug: Constructed timed-command: On FOR 1 SECONDS
2020-03-23 23:35:00.223 Status: dzVents: Debug: Constructed timed-command: On FOR 1 SECONDS REPEAT 6 INTERVAL 1 SECONDS
2020-03-23 23:35:00.224 Status: dzVents: Info: ------ Finished Diepvries
2020-03-23 23:35:00.224 Status: dzVents: Debug: Commands sent to Domoticz:
2020-03-23 23:35:00.224 Status: dzVents: Debug: - sonoff keuken = Off NOTRIGGER
2020-03-23 23:35:00.224 Status: dzVents: Debug: - sonoff keukenkoof = Off NOTRIGGER
2020-03-23 23:35:00.224 Status: dzVents: Debug: - sonoff keuken = On FOR 1 SECONDS REPEAT 6 INTERVAL 1 SECONDS
2020-03-23 23:35:00.224 Status: dzVents: Debug: - sonoff keukenkoof = On FOR 1 SECONDS REPEAT 6 INTERVAL 1 SECONDS
2020-03-23 23:35:00.224 Status: dzVents: Debug: =====================================================
2020-03-23 23:35:00.227 Status: EventSystem: Script event triggered: C:\Program Files (x86)\Domoticz\dzVents\runtime\dzVents.lua
2020-03-23 23:35:01.883 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:01.955 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:01.956 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:01.956 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:01.956 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:02.790 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:02.863 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:02.863 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:02.863 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:02.864 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:03.744 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:03.822 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:03.822 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:03.822 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:03.822 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:03.942 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:04.020 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:04.021 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:04.021 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:04.022 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:04.022 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:04.022 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:04.133 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:04.208 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:04.208 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:04.209 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:04.209 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:04.356 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:04.429 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:04.430 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:04.430 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:04.430 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:04.528 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:04.610 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:04.611 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:04.611 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:04.611 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:04.823 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:04.877 Status: dzVents: Debug: Processing device-adapter for WaterTeller: Counter device adapter
2020-03-23 23:35:04.877 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:04.877 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:04.878 Status: dzVents: Debug: - Device: WaterTeller
2020-03-23 23:35:04.933 Status: dzVents: Info: Handling events for: "WaterTeller", value: "18446744073709538118"
2020-03-23 23:35:04.933 Status: dzVents: Info: ------ Start internal script: WaterTeller2InfluxDB_2: Device: "WaterTeller (ESP8266)", Index: 171
2020-03-23 23:35:04.934 Status: dzVents: Info: CHRISTIAN NEW value(Total):589 valueQuantity:Count counterDiff:0
2020-03-23 23:35:04.935 Status: dzVents: Info: ------ Finished WaterTeller2InfluxDB_2
2020-03-23 23:35:05.341 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:05.418 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:05.419 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:05.419 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:05.419 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:05.518 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:05.587 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:05.587 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:05.587 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:05.588 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:06.335 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:06.409 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:06.409 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:06.410 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:06.410 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:06.498 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:06.554 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:06.554 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:06.554 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:06.554 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:07.322 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:07.394 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:07.394 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:07.394 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:07.395 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:07.490 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:07.545 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:07.546 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:07.546 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:07.546 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:08.337 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:08.404 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:08.405 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:08.405 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:08.405 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:08.496 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:08.551 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:08.552 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:08.552 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:08.552 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:09.322 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:09.387 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:09.388 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:09.388 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:09.388 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:09.487 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:09.549 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:09.550 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:09.550 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:09.550 Status: dzVents: Debug: - Device: sonoff keukenkoof
2020-03-23 23:35:10.331 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:10.402 Status: dzVents: Debug: Processing device-adapter for sonoff keuken: Switch device adapter
2020-03-23 23:35:10.402 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:10.402 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:10.402 Status: dzVents: Debug: - Device: sonoff keuken
2020-03-23 23:35:10.489 Status: dzVents: Debug: Dumping domoticz data to C:\Program Files (x86)\Domoticz\scripts\dzVents\domoticzData.lua
2020-03-23 23:35:10.552 Status: dzVents: Debug: Processing device-adapter for sonoff keukenkoof: Switch device adapter
2020-03-23 23:35:10.553 Status: dzVents: Debug: dzVents version: 2.5.2
2020-03-23 23:35:10.553 Status: dzVents: Debug: Event triggers:
2020-03-23 23:35:10.553 Status: dzVents: Debug: - Device: sonoff keukenkoof
Last edited by Buteo72 on Tuesday 24 March 2020 22:13, edited 2 times in total.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Flash lights when fridge is left open

Post by waaren »

Buteo72 wrote: Monday 23 March 2020 23:37 I get the lights flashing with the code below, but only when lights are off.
I tried to set them off but the lamps are not reacting and are not set to off.
Someone any clue?
The switchOn().forSec(1).repeatAfterSec(1, 5) command is interpreted when the script is active. At that moment the state of the light is as it was when the script started. Any command in the script will only be passed to domoticz the moment the script finished. That is just the way the eventsystem works. (true for Blockly, classic Lua and dzVents)

try changing the logic in the script to

Code: Select all

return 
{
    on = 
    {
        timer = 
        {
            'every minute',              -- causes the script to be called every minute
       },
    },
 
    logging =
    {
        level = domoticz.LOG_DEBUG,    
        marker = 'Diepvriedoor alert',
    },
    
    execute = function(dz, timer)
        
        local flashRepeats = 5
        
        dz.log('======================== ', dz.LOG_DEBUG)
        dz.log('======================== ', dz.LOG_DEBUG)
        dz.log('======================== ', dz.LOG_DEBUG)
        dz.log('Diepvries trigger started ' .. timer.trigger, dz.LOG_DEBUG)

        local diepVriesDeur     = dz.devices('DiepvriesSensor')
        local sonoffKeuken      = dz.devices('sonoff keuken')
        local sonoffKeukenKoof  = dz.devices('sonoff keukenkoof')

        
        if (diepVriesDeur.state == 'Open' and diepVriesDeur.lastUpdate.minutesAgo > 1) then  -- > 1 to be changed to a higher value when script is final
            dz.log('Dievries trigger: hij staat open, laat de lampen knipperen... ', dz.LOG_DEBUG)
            --dz.notify('Dievriesdeur alert', 'De diepvriesdeur staat al meer dan 5 minuten open!', dz.PRIORITY_HIGH)
        
            --first turn off the lights if they are on
            sonoffKeuken.switchOff().checkFirst()
            sonoffKeukenKoof.switchOff().checkFirst()
            
            for i = 1, (flashRepeats * 2), 2 do -- 1 to 10 step 2 ==>> 1, 3, 5, 7, 9
                dz.log('Now scheduling lights on after ' .. i .. ' seconds... ', dz.LOG_DEBUG)
                sonoffKeuken.switchOn().afterSec(i)       
                sonoffKeukenKoof.switchOn().afterSec(i)

                dz.log('Now scheduling lights off after ' ..( i + 1) .. ' seconds... ', dz.LOG_DEBUG)
                sonoffKeuken.switchOff().afterSec(i + 1)
                sonoffKeukenKoof.switchOff().afterSec(i+1)
            end
            
             -- restore On state when state was active before script started
            if sonoffKeuken.active then sonoffKeuken.switchOn().afterSec(flashRepeats * 2 + 2) end 
            if sonoffKeukenKoof.active then sonoffKeukenKoof.switchOn().afterSec(flashRepeats * 2 + 2) end
            
        end
    end
}

Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Buteo72
Posts: 3
Joined: Monday 16 December 2019 18:43
Target OS: Windows
Domoticz version:
Contact:

Re: Flash lights when fridge is left open  [Solved]

Post by Buteo72 »

waaren wrote: Tuesday 24 March 2020 7:16 The switchOn().forSec(1).repeatAfterSec(1, 5) command is interpreted when the script is active. At that moment the state of the light is as it was when the script started. Any command in the script will only be passed to domoticz the moment the script finished. That is just the way the eventsystem works. (true for Blockly, classic Lua and dzVents)
Thanks for your time and solution! This works very wel. Also got to understand the basics behind the scipts.
I wasn't able to develop this script on my own, but I happy that I've learned something!

Thanks again!

Christian
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest