Page 1 of 1

Parameterised scripts

Posted: Friday 15 June 2018 10:31
by Andyf66
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.

Re: Parameterised scripts

Posted: Friday 15 June 2018 11:42
by waaren
@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..