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

Moderator: leecollings

Post Reply
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

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

Post 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?
SweetPants

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

Post 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
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

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

Post 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
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

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

Post 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
}


Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
SweetPants

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

Post by SweetPants »

you missed one 'end' as waaren said
Evelen
Posts: 234
Joined: Thursday 09 July 2015 12:03
Target OS: Linux
Domoticz version: 2.4538
Location: Norway
Contact:

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

Post by Evelen »

It works :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest