Help wanted with LUA/dzVents
Moderator: leecollings
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Help wanted with LUA/dzVents
Hi everyone,
I want to create a script set all smoke detectors I have to 'Panic' using Lua/dzvents.
More than help with actual writing I would like some ideas/feedback on how the logic should be handled.
I want to use a wild-card for the triggering 'smd*' but I surely don't want to create a loop when activating the 'Panic' modes which will then trigger the script again, since at that moment *all* detectors will have a changed status to 'panic' and so on..
I have no scripting/programming experience and only started with Lua a little while ago because Blockly does not serve my needs.
Thanks in advance,
Olivier
PS: I know I can write separate script for each detector and the trigger all but that one to avoid the loop, but if possible I would like to avoid having a multitude of scripts.
I want to create a script set all smoke detectors I have to 'Panic' using Lua/dzvents.
More than help with actual writing I would like some ideas/feedback on how the logic should be handled.
I want to use a wild-card for the triggering 'smd*' but I surely don't want to create a loop when activating the 'Panic' modes which will then trigger the script again, since at that moment *all* detectors will have a changed status to 'panic' and so on..
I have no scripting/programming experience and only started with Lua a little while ago because Blockly does not serve my needs.
Thanks in advance,
Olivier
PS: I know I can write separate script for each detector and the trigger all but that one to avoid the loop, but if possible I would like to avoid having a multitude of scripts.
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
What would cause a loop then? What is the exact chain of events? One detector detects smoke and then all other detectors should start to panic?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
That is indeed what I want. If smoke is detected, warning everybody in the house by activating the alarm of all detectors.dannybloe wrote: One detector detects smoke and then all other detectors should start to panic?
But wouldn't this trigger the script again, and again...?
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
I'd do something like this. By checking if the state isn't already Panic only then you set it to Panic (this prevents the looping).
I don't have smoke detectors myself so it could be that this doesn't work 
Of course there are many ways that lead to Rome...
Or if you want to make it less generic:
Code: Select all
local detectors = {
['smokeDetector1'] = true,
['smokeDetector2'] = true,
['smokeDetector3'] = true
}
return {
active = true,
on = {
'smokeDetector*'
},
execute = function(domoticz, smokeDetector)
if (smokeDetector.status == 'Panic') then
-- filter all devices based on the detectors list above
-- and only those that aren't already in Panic mode
domoticz.devices.filter(function(device)
-- return true for non-panic devices and with the proper name
return detectors[device.name] == true and device.state ~= 'Panic'
end).forEach(function(detector)
-- set to panic
detector.setState('Panic')
end)
end
end
}
Of course there are many ways that lead to Rome...
Or if you want to make it less generic:
Code: Select all
return {
active = true,
on = {
'smokeDetector1',
'smokeDetector2,'
'smokeDetector3'
},
execute = function(domoticz, smokeDetector)
if (smokeDetector.status == 'Panic') then
if (domoticz.devices['smokeDetector1'].state ~= 'Panic') then
domoticz.devices['smokeDetector1'].setState('Panic')
end
if (domoticz.devices['smokeDetector2'].state ~= 'Panic') then
domoticz.devices['smokeDetector2'].setState('Panic')
end
if (domoticz.devices['smokeDetector3'].state ~= 'Panic') then
domoticz.devices['smokeDetector3'].setState('Panic')
end
end
end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
Ok Danny, this is a big help.
Looks good, as soon as I am alone in the house I can do a test (my partner would kick me out of the house if I test this while she is home (too loud).
Actually my biggest mistake was forgetting that you can put several devices in the on = { } part and that I would have to have a script for each detector.
I knew this, just did not think about it.
BTW: I really like what you have created with dzVents, makes scripting life so much easier.
Looks good, as soon as I am alone in the house I can do a test (my partner would kick me out of the house if I test this while she is home (too loud).
Actually my biggest mistake was forgetting that you can put several devices in the on = { } part and that I would have to have a script for each detector.
I knew this, just did not think about it.
BTW: I really like what you have created with dzVents, makes scripting life so much easier.
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
elmortero wrote:Ok Danny, this is a big help.
Looks good, as soon as I am alone in the house I can do a test (my partner would kick me out of the house if I test this while she is home (too loud)
I'm not exactly sure if setState('Panic') is the way to go though. Let me know if it works.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
It makes sense that way, but if it is not, I'll use the json approach, or create scene and activate that one.
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
That should not be needed. As far as I know you can send all commands using dzVents without json. If not then I'll add it.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
Hi Danny,
Tried it today, but it failed.
Seems to be ineed something with the .setState('Panic') because when I replace that with a virtual switch it works.
In this topic http://www.domoticz.com/forum/viewtopic ... son#p44652
Eduard said it works with /json.htm?type=command¶m=switchlight&idx=3&switchcmd=On
So I guess instead of setState('Panic') I should use switchOn()
Hope to find some alone time this weekend to test but I feel confident that this will be it.
Update: just tried it, not working, no error messages.
Tried it today, but it failed.
Seems to be ineed something with the .setState('Panic') because when I replace that with a virtual switch it works.
In this topic http://www.domoticz.com/forum/viewtopic ... son#p44652
Eduard said it works with /json.htm?type=command¶m=switchlight&idx=3&switchcmd=On
So I guess instead of setState('Panic') I should use switchOn()
Hope to find some alone time this weekend to test but I feel confident that this will be it.
Update: just tried it, not working, no error messages.
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
Strange.I couldn't find much information regarding this kind of 'switch' It should be possible.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
It is odd indeed.
As soon as I can I will do some more tests.
For now, in order to have this working, I will have to use Blockly (thought I'd seen the last of that
)
As soon as I can I will do some more tests.
For now, in order to have this working, I will have to use Blockly (thought I'd seen the last of that
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
Would be interesting to know what Blockly sends to Domoticz (internally) as the value.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
Finally been able to test.
The switchOn() does the trick, as for the check to the current status, 'Panic' is not how check.
This seems to work:
Thanks a lot for the support
The switchOn() does the trick, as for the check to the current status, 'Panic' is not how check.
This seems to work:
Code: Select all
return {
active = true,
on = {
'smd-bedroom',
'smd-hall',
'smd-guest',
'smd-salon',
'smd-kitchen'
},
execute = function(domoticz)
local bedroom = domoticz.devices['smd-bedroom']
local hall = domoticz.devices['smd-hall']
local guest = domoticz.devices['smd-guest']
local salon = domoticz.devices['smd-salon']
local kitchen = domoticz.devices['smd-kitchen']
if (bedroom.changed and bedroom.status == 'On')
or (hall.changed and hall.status == 'On')
or (guest.changed and guest.status == 'On')
or (salon.changed and salon.status == 'On')
or (kitchen.changed and kitchen.status == 'On')
then
if kitchen.state == 'Off' then
kitchen.switchOn()
end
if (hall.state ~= 'On') then
hall.switchOn()
end
if (guest.state ~= 'On') then
guest.switchOn()
end
if (salon.state ~= 'On') then
salon.switchOn()
end
if (bedroom.state ~= 'On') then
bedroom.switchOn()
end
end
--- end
end
}
-
dannybloe
- Posts: 1355
- Joined: Friday 29 August 2014 11:26
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Ermelo
- Contact:
Re: Help wanted with LUA/dzVents
Great. Nice to see how the code is so much more readable than without dzVents. That was the main purpose of making it.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
-
elmortero
- Posts: 248
- Joined: Sunday 29 November 2015 20:46
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 3.9639
- Location: Spain
- Contact:
Re: Help wanted with LUA/dzVents
That is why I like it.
I have no coding experience and I learn from examples (that is why I am sometimes lost in manuals..and ask for help).
So when I had to go from Blockly to Lua I was hesitating. But then just after that I you came with dzvents and I liked the posibilities (but had to overcome my resitance to start learning that)
Very glad you put the effort into making it and really grateful.
With the smokedetector thing solved I have everything converted to dzVents scripts.
I have no coding experience and I learn from examples (that is why I am sometimes lost in manuals..and ask for help).
So when I had to go from Blockly to Lua I was hesitating. But then just after that I you came with dzvents and I liked the posibilities (but had to overcome my resitance to start learning that)
Very glad you put the effort into making it and really grateful.
With the smokedetector thing solved I have everything converted to dzVents scripts.
Who is online
Users browsing this forum: No registered users and 1 guest