Parameterised scripts

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
Andyf66
Posts: 44
Joined: Wednesday 13 June 2018 12:13
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Parameterised scripts

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

Re: Parameterised scripts

Post 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..
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest