distinguish between manual setting and time based events

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

Moderator: leecollings

Post Reply
guenniac
Posts: 23
Joined: Wednesday 27 October 2021 18:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Aachen, Germany
Contact:

distinguish between manual setting and time based events

Post by guenniac »

I have several Fibaro Roller Shutters FGR223 in use. Domoticz is 2021.1 on Raspi 3 with Raspbian Buster.

Goal: I don't want the to be locked out on my terrace in the evening by an automatic shutter close.

Approach:
When I set the roller shutter manually via wall switch I disable time based events for a certain time period e.g. for 4 hours.

My main question:
Is it possible to distinguish between manual setting via wall switch/GUI and time events?

Use of door contacts is not wanted!


Thanks
Raspberry Pi 3B+
Raspbian GNU/Linux 12 (bookworm) / 6.1.61-v7+
Version: 2023.2
Build Hash: 19efd039c
Compile Date: 2023-07-21 17:23:44
dzVents Version: 3.1.8
Python Version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: distinguish between manual setting and time based events

Post by EddyG »

guenniac wrote: Tuesday 28 December 2021 11:04 Use of door contacts is not wanted!
So if you forget to set the switch you still will be locked out?
I use a door contact in a dzVents script, so a wallswitch could be used the same way in dzVents.
Check the switch before the shutdown of the shutter close.
guenniac
Posts: 23
Joined: Wednesday 27 October 2021 18:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Aachen, Germany
Contact:

Re: distinguish between manual setting and time based events

Post by guenniac »

Really my first try was with a door contact together with the Fibaro FGBS222 Smart Implant+ and a small power supply. But I couldn't get it working (guess there's a heating issue when the parts are placed in the wall behind the Roller shutter module and the switch).

The switch is a single, momentary switch, one push moves up the shutter. Another push stops the shutter.
A second switch is for moving down the shutter. So I have no stable state.
Raspberry Pi 3B+
Raspbian GNU/Linux 12 (bookworm) / 6.1.61-v7+
Version: 2023.2
Build Hash: 19efd039c
Compile Date: 2023-07-21 17:23:44
dzVents Version: 3.1.8
Python Version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: distinguish between manual setting and time based events

Post by rrozema »

If you set the timer on the device itself (i.e. via the 'timer' button) that is unconditional: there is no option to add checking for an additional switch or anything. But, if you have a (dummy) switch that switches on the timer, then have a script that switches the roller-shutters depending on the state of the switch, in this script you can add a condition like a 'disable' switch or something.

Assuming you have:
- 1 (dummy) switch "shutters" with a timer when you want to open and close the shutters automatically,
- 1 (dummy) switch "override timer" (switches between Auto and Open),
- 2 roller shutters "shutter 1" and "shutter 2" (no timers on these).

You could use a script like this:

Code: Select all

local SHUTTERS_NAME = "shutters"
local FORCE_OPEN_NAME = "override timer"
local SHUTTERS_NAMES = { "shutter 1", "shutter 2" }

return {
	on = {
		devices = {
			SHUTTERS_NAME,
			FORCE_OPEN_NAME
		}
	},
	execute = function(domoticz, device)
            shutters = domoticz.devices(SHUTTERS_NAME)
	    force_open = domoticz.devices(FORCE_OPEN_NAME)
	    
	    if nil == shutters then
	    	domoticz.log('Device ' .. SHUTTERS_NAME .. ' not found.', domoticz.LOG_ERROR)
	    elseif nil == force_open then
	    	domoticz.log('Device ' .. FORCE_OPEN_NAME .. ' not found.', domoticz.LOG_ERROR)
	    else
	        domoticz.devices(SHUTTERS_NAMES).forEach(
	                function(shutter)
	                    if shutters.bState or force_open.bState then
                            if shutter.level < 100 then
	                            shutter.setLevel(100)   -- open
	                        end
                        else
                            if shutter.level > 0 then
	                            shutter.setLevel(0)     -- close
	                        end
	                    end
                    end
	            )
	    end
	end
}
guenniac
Posts: 23
Joined: Wednesday 27 October 2021 18:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Aachen, Germany
Contact:

Re: distinguish between manual setting and time based events

Post by guenniac »

Thank you for giving me advice.
Meanwhile I have implemented a solution with a virtual switch. When switch is set then my time triggered shutter script does not execute.

I think about a countdown on this virtual switch in this way:
When the switch is pressed a timer value is set to 240 minutes. A countdown script counts the timer value down to 0. During that time the shutter script will not be executed.
Raspberry Pi 3B+
Raspbian GNU/Linux 12 (bookworm) / 6.1.61-v7+
Version: 2023.2
Build Hash: 19efd039c
Compile Date: 2023-07-21 17:23:44
dzVents Version: 3.1.8
Python Version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
EddyG
Posts: 1042
Joined: Monday 02 November 2015 5:54
Target OS: -
Domoticz version:

Re: distinguish between manual setting and time based events

Post by EddyG »

Please share the script how you solved that.
guenniac
Posts: 23
Joined: Wednesday 27 October 2021 18:13
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: Aachen, Germany
Contact:

Re: distinguish between manual setting and time based events

Post by guenniac »

Here is my approach:

Code for the Timeout counter and the virtual switch.
The code is triggered either by time interval to countdown the timeout value or device action(virtual switch, created via "Create Virtual Sensors")
For demo purpose I have set timer interval to 1 minute and the timeout value to 3 minutes.

Code: Select all

local INTERVAL = 5
local INTERVAL = 1
local TIMEOUT = 240
local TIMEOUT = 3

local PROG = 'lockRS'
local logToFile = true									
local tmpLogFile = '/var/log/domoticz/RS.log'           			

return {
	on = {
		devices = { 
		   	'RS Stop'
		},
	    	timer = { 
           		 'every ' .. INTERVAL .. ' minutes'
	    	},
	},
	data = {
	    	mailTo = { initial = 'root@localhost' }
    	},
	logging = { 
	   	level = domoticz.LOG_INFO, 
	    	marker = PROG
    	},

	execute = function(dz, item, info)

        local idxRSStop = dz.globalData.idxRSStop

        --dz.log('RS Stop')
        logheader = os.date('%Y-%m-%d %H:%M:%S ',os.time()) .. '-' .. PROG .. '-'
	    if item.isTimer then
	        if dz.globalData.RSStopTime > 0 then
                if (dz.globalData.RSStopTime - INTERVAL) <= 0 and dz.devices(idxRSStop).state == 'On' then 	-- reset timeout value
                    dz.globalData.RSStopTime = 0
                    dz.devices(idxRSStop).setState('Off').silent()
                    logtext = 'RS Timeout - reset by timer plan'
                else  																			-- count down timeout value
                    dz.globalData.RSStopTime = dz.globalData.RSStopTime - INTERVAL
                    logtext = 'RS Timeout - remaining ' .. tostring(dz.globalData.RSStopTime) .. ' minutes'
                end
            else 																				-- nothing to do
                return 0
            end
        elseif item.isDevice then  																-- virtual switch hit
            --item.dump()
            if item.state == 'On' then 																-- switch set on -> set timeout value 
                dz.globalData.RSStopTime = TIMEOUT
                logtext = 'RS Timeout - set to ' .. tostring(dz.globalData.RSStopTime) .. ' minutes'
            else  																				-- switch set off - reset timeout value
                logtext = 'RS Timeout - reset by manual action'
                dz.globalData.RSStopTime = 0
            end
        else
            logtext = info.scriptName .. ': Triggered by unknown event'
        end
        dz.log(logtext)
        dz.email('message from your lockRS script', logtext, dz.data.mailTo)
    	if logToFile then os.execute('echo ' .. logheader .. logtext .. ' >>' .. tmpLogFile) end
	end
}

And this is the relevant code snippet for the shutter. It prevents moving the 3 shutters 'RS Kueche' , 'RS WZ li' , 'RS WZ re' when virtual switch is 'On'

Code: Select all

            if ( name == 'RS Kueche' or name == 'RS WZ li' or name == 'RS WZ re') and dz.devices(idxRSStop).state == 'On' then
                logtext = ' ' .. name .. ' - action locked for ' .. timeout .. ' minutes - (switch "RS Stop" set, to enable normal behaviour: set switch "RS Stop" off)'
                dz.log(logtext)
        	if logToFile then os.execute('echo ' .. logheader .. logtext .. ' >>' .. tmpLogFile) end
            else
                dz.devices(id).setLevel(lev).withinMin(2)
                --dz.devices(id).setLevel(lev).silent()
                logtext = ' ' .. name .. ' level set from ' .. curLevel .. '% to ' .. lev .. '%'
                dz.log(logtext)
        	if logToFile then os.execute('echo ' .. logheader .. logtext .. ' >>' .. tmpLogFile) end
                --curLevel = dz.devices(id).level
                --logtext = ' ' .. name .. ' new level ' .. curLevel .. '%'
                --dz.log(logtext)
    		--if logToFile then os.execute('echo ' .. logheader .. logtext .. ' >>' .. tmpLogFile) end
    		end

Here is a sample log
2022-01-05 15:43:19.870 Status: User: Admin (IP: 192.168.11.21) initiated a switch command (377/RS Stop/On)
2022-01-05 15:43:20.034 Status: dzVents: Info: Handling events for: "RS Stop", value: "On"
2022-01-05 15:43:20.034 Status: dzVents: Info: lockRS: ------ Start internal script: lockRS: Device: "RS Stop (Virtual)", Index: 377
2022-01-05 15:43:20.035 Status: dzVents: Info: lockRS: RS Timeout - set to 3 minutes
2022-01-05 15:43:20.057 Status: dzVents: Info: lockRS: ------ Finished lockRS
2022-01-05 15:44:00.429 Status: dzVents: Info: lockRS: ------ Start internal script: lockRS:, trigger: "every 1 minutes"
2022-01-05 15:44:00.430 Status: dzVents: Info: lockRS: RS Timeout - remaining 2 minutes
2022-01-05 15:44:00.448 Status: dzVents: Info: lockRS: ------ Finished lockRS
2022-01-05 15:45:00.457 Status: dzVents: Info: lockRS: ------ Start internal script: lockRS:, trigger: "every 1 minutes"
2022-01-05 15:45:00.458 Status: dzVents: Info: lockRS: RS Timeout - remaining 1 minutes
2022-01-05 15:45:00.477 Status: dzVents: Info: lockRS: ------ Finished lockRS
2022-01-05 15:45:00.477 Status: dzVents: Info: setRSTimeBasedv6: ------ Start internal script: setRSTimeBasedv6:, trigger: "at 15:45"
2022-01-05 15:45:00.495 Status: dzVents: Info: setRSTimeBasedv6: RS Kueche - action locked for 1 minutes - (switch "RS Stop" set, to enable normal behaviour: set switch "RS Stop" off)
2022-01-05 15:45:00.514 Status: dzVents: Info: setRSTimeBasedv6: ------ Finished setRSTimeBasedv6
2022-01-05 15:46:00.471 Status: dzVents: Info: lockRS: ------ Start internal script: lockRS:, trigger: "every 1 minutes"
2022-01-05 15:46:00.493 Status: dzVents: Info: lockRS: RS Timeout - reset by timer plan
2022-01-05 15:46:00.549 Status: dzVents: Info: lockRS: ------ Finished lockRS
Raspberry Pi 3B+
Raspbian GNU/Linux 12 (bookworm) / 6.1.61-v7+
Version: 2023.2
Build Hash: 19efd039c
Compile Date: 2023-07-21 17:23:44
dzVents Version: 3.1.8
Python Version: 3.11.2 (main, Mar 13 2023, 12:18:29) [GCC 12.2.0]
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest