Run script only when device changed manualy.

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

Moderator: leecollings

Post Reply
OedzesG
Posts: 106
Joined: Monday 11 March 2019 0:14
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Run script only when device changed manualy.

Post by OedzesG »

Goodmorning DzVents Friends!

Short question...

In my house optimalisation system are 2 uservariables verry important: scene selector and Automatic or Manual mode.

When automatic mode is selected then my motion sensor or timmer event changes the scene.
But when i manualy change a device (for example livingroom dimmer) then i want to tur off automatic mode.

this works fine when i use this script:

Code: Select all

return {
		active = true,
		on = {
			devices = {'hue_group_keuken'}
		           
			},
				execute = function(domoticz, switch)
				    
		local hue_group_keuken          =  domoticz.devices('hue_group_keuken')
		local modus_switch              =  domoticz.devices('automatic_mode_woonkamer_keuken')
		local woonkamer_keuken_control  =  domoticz.variables('woonkamer_keuken_control')
		
		
		
	if         (woonkamer_keuken_control.value == ('Thuis') and hue_group_keuken.changed()) then 
	            modus_switch.switchOff()

    end 
end 
} 
(for updating the uservariable from the switch i use another script)

But i think you can gues that when my timer script is changing my hue_group_keuken lights, this script olso dectect the change and switch automatic mode off, how can i prevent this? and only make this script executing when i change manualy the hue_group_keuken lights?

thnx! in advanced.

(sorry for my bad englisch..)
elmortero
Posts: 247
Joined: Sunday 29 November 2015 20:46
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.9639
Location: Spain
Contact:

Re: Run script only when device changed manualy.

Post by elmortero »

HI.

I usually add something like (domoticz.devices('Keukenschakelaar').lastUpdate.minutesAgo > 30) to my IF loop
It assumes that if you haven't touched the switch (manually) for more than half an hour we can suppose that it was switched on automatically
Maxx
Posts: 58
Joined: Saturday 27 January 2018 20:59
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Contact:

Re: Run script only when device changed manualy.

Post by Maxx »

Hello,

I have been struggling with the same, I did the following trick(allthough not perfect):

You can detect what triggered your script, a timer or device. Whenever the timer triggered the script, you can set a variable to 1 for example.

When the device change triggers the script and the variable is 0, then you know it came from a manual action. When the variable is 1, it came from the timer.

The only problem is that sometimes the device change is detected quicker then the variable is set.

for example (not tested)

Code: Select all

return {
	on = {
		devices = {},
		timer = {},

	},
        data = {
            marker = {initial=0}
        },
	execute = function(domoticz, Item)
	    
	    if Item.isTimer then
	        Veranda.dimTo(60)
                domoticz.data.marker = 1
            end
        
        if Item.isDevice then
            if domoticz.data.marker == 1 then
                domoticz.log('Automatic action')
            elseif domoticz.data.marker == 0 then 
                domoticz.log('manual action')
            end
            domoticz.data.marker = 0
        end
	end
}
BOverdevest
Posts: 23
Joined: Wednesday 28 March 2018 20:56
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.11307
Location: Nederland
Contact:

Re: Run script only when device changed manualy.

Post by BOverdevest »

Have you tried to use the .silent() option in the Dzvents scripts that change the states?

See: https://www.domoticz.com/wiki/DzVents:_ ... nd_Options

with this option, the change in state won't trigger another event.

greetings
Bart
HUE, Tradfri, Zwave, RFXCOM, rooted TOON, PS4
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest