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?
IF Button is pressed on (even if on already) do somthing
Moderator: leecollings
Re: IF Button is pressed on (even if on already) do somthing
Try a 'device' triggered dzVentz event like this
It will be launced every time you push the button even if it is already in the selected state
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
}
-
- 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
Thanks, it works, changed the code a little:SweetPants wrote: ↑Saturday 30 December 2017 9:57 Try a 'device' triggered dzVentz event like thisIt will be launced every time you push the button even if it is already in the selected stateCode: 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 }
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
}
Code: Select all
-- if (device.state == 'On') then
-- domoticz.log('It is On')
-- if (device.state == 'Off') then
-- domoticz.log('It is Off')
-- end
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
- 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
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
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Re: IF Button is pressed on (even if on already) do somthing
you missed one 'end' as waaren said
Who is online
Users browsing this forum: No registered users and 1 guest