Page 1 of 1

IF Button is pressed on (even if on already) do somthing

Posted: Saturday 30 December 2017 3:34
by Evelen
Hi.

I have these wall switches that can be set to "on" or "off".
Now I just have JSON inside the device on "response by on" and "response by off", but this just works if I want to change one device, since that is what JSON supports.

I want in LUA:
IF "Button is pressed on (even if on already)"
DO: somthing

how do I write this?

Re: IF Button is pressed on (even if on already) do somthing

Posted: Saturday 30 December 2017 9:57
by SweetPants
Try a 'device' triggered dzVentz event like this

Code: Select all

return {
	on = {
		devices = {
			'Button'
		}
	},
	
    logging = {
        level = domoticz.LOG_INFO,
        marker = "dz_Test"
    },

	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was triggered', domoticz.LOG_INFO)
	end
}
It will be launced every time you push the button even if it is already in the selected state

Re: IF Button is pressed on (even if on already) do somthing

Posted: Saturday 30 December 2017 15:20
by Evelen
SweetPants wrote: Saturday 30 December 2017 9:57 Try a 'device' triggered dzVentz event like this

Code: Select all

return {
	on = {
		devices = {
			'Button'
		}
	},
	
    logging = {
        level = domoticz.LOG_INFO,
        marker = "dz_Test"
    },

	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was triggered', domoticz.LOG_INFO)
	end
}
It will be launced every time you push the button even if it is already in the selected state
Thanks, it works, changed the code a little:

Code: Select all

return {
	on = {
		devices = {
			266
		}
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was triggered', domoticz.LOG_INFO)
		
    --	   if (device.state == 'On') then
    --    	domoticz.log('It is On')
    --	   if (device.state == 'Off') then
    --       	domoticz.log('It is Off')
    --     end 

		 
	end
}
This part it what is not working (if activated):

Code: Select all

    --	   if (device.state == 'On') then
    --    	domoticz.log('It is On')
    --	   if (device.state == 'Off') then
    --       	domoticz.log('It is Off')
    --     end 
It gives the following error:

2017-12-30 15:17:56.918 Error: dzVents: Error: error loading module 'test' from file '/home/pi/domoticz/scripts/dzVents/generated_scripts/test.lua':
...e/pi/domoticz/scripts/dzVents/generated_scripts/test.lua:18: unexpected symbol near '}'


Can't really se why

Re: IF Button is pressed on (even if on already) do somthing

Posted: Saturday 30 December 2017 16:31
by waaren
Try this:

Code: Select all

return {
	on = {
		devices = {
			266
		}
	},
	execute = function(domoticz, device)
		domoticz.log('Device ' .. device.name .. ' was triggered', domoticz.LOG_INFO)
		
    	-- Added the missing end
	--
	if (device.state == 'On') then
      		domoticz.log('It is On')
	end
    	if (device.state == 'Off') then
      		domoticz.log('It is Off')
    	end 
	
	-- Should also give the desired result.
	domoticz.log('Device ' .. device.name .. ' state: ' .. device.state , domoticz.LOG_INFO)
		
		 
	end
}



Re: IF Button is pressed on (even if on already) do somthing

Posted: Saturday 30 December 2017 16:56
by SweetPants
you missed one 'end' as waaren said

Re: IF Button is pressed on (even if on already) do somthing

Posted: Saturday 30 December 2017 19:06
by Evelen
It works :)