Page 1 of 1

Run script only when device changed manualy.

Posted: Monday 16 September 2019 9:18
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..)

Re: Run script only when device changed manualy.

Posted: Monday 16 September 2019 12:04
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

Re: Run script only when device changed manualy.

Posted: Monday 16 September 2019 18:01
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
}

Re: Run script only when device changed manualy.

Posted: Friday 04 October 2019 22:11
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