Parameterised scripts

Easy to use, 100% Lua-based event scripting framework.
Post Reply
Andyf66
Posts: 24
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Parameterised scripts

Post by Andyf66 » Friday 15 June 2018 10:31

As I get further into Domoticz Im appreciating the power of dzvents. I've developed a bunch of scripts to work with PIR sensors in various rooms. As I've refined my code these scripts basically all do the same thing, but with different devices.

Rather than having a script for my bathroom, a script for the hallway etc, all containing duplicated identical logic but different devices, is it possible to have a 'generic' PIR device script that is called with parameters to specify the PIR/scenes to activate etc, so the logic is only contained in a single script?
I guess I could keep the 'on = {' section specific to each situation, but within the 'execute = {' call out to a parameterised generic helper function that contains the main bulk of the logic?

TIA

Andy.

User avatar
waaren
Posts: 709
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Parameterised scripts

Post by waaren » Friday 15 June 2018 11:42

@Andyf66 ,

There are many ways to accomplish this varying from using wildcards in the on = section for the activation part, to the use of arrays, groups or description fields to identify what action should be taken for which device. Also possibilities to use datafiles, require (function) modules, global data with helper functions etc, etc..

it is more a matter of choice stress (which is probably a bad translation of the Dutch keuzestress :lol: ) than a lack of options..
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests