Page 1 of 1

Am I doing this wrong?

Posted: Wednesday 29 May 2024 13:03
by paul402
This post is not about criticism. It may be that I cannot see the wood for the trees and need help.

So I have a single perfectly running python script that controls 35 IP devices with over 100 command rules. I send the results to Domoticz dummy devices for display using json.
The python initial command rule data is pulled into an array and various subroutines do magic to send up.down/stop on/off etc at the appropriate times.
I wanted to bring the functionality into Dzvents...
There are no arrays or subroutines that I can find....
It seems impossible to directly replicate one python script with one Dzvents script.
The, as far as I can tell, lack of subroutines makes my Dzvents script(s) incredibly verbose and the lack of arrays means that I need at least one script for every device.

So what have I got so badly wrong or misunderstood? Will I be better off using LUA or something else?
Again this is not criticism of Dzvents. I either need educating or need to use a different tool.

Re: Am I doing this wrong?

Posted: Wednesday 29 May 2024 13:15
by jvdz
dzvents is LUA and LUA can have functions, so I am a little lost what it is you are looking for. Any "simple" example snippet in python you can share to shows what it is you do not understand how to translate into LUA?

Re: Am I doing this wrong?

Posted: Wednesday 29 May 2024 13:25
by janpep
I guess it is not so difficult. In dzVents you can use the lua script language. You can create arrays as you like. (Find examples here). Also you can create local or global functions.
May be I can point you to my new script with examples of all these things in Script for Airplanes.live api.

Re: Am I doing this wrong?

Posted: Wednesday 29 May 2024 14:22
by paul402
Well thanks for the answers.
@jvdz how do functions = subroutines. I cannot find this functionality.
Anyhow here is a very simplified schema of my python script.

Code: Select all

Python
setup array
read in data (tuples)

=========
example data for one shutter device
# device, time1, time2, offset-time, up/down-on/off, stopafterseconds,firedtoday
(1,"07:30","0",0,0,10,0),
(1,"08:00","09:00",35,0,0,0),
(1,"16:00","23:00",0,1,14,0),
(1,"17:00","23:00",70,1,13,0),
(1,"23:59","0",0,3,0,0 ),
=========        

setup array2
subroutine setup action times for +-100 rules (array2) (could use single array)
every minute
index through array2 
    if rule=time now then
        subroutine for http command or
        subroutine for 433Mhz device (receive only) or
        subroutine for Zigbee device
        and
        subroutine for json command for domoticz dummy devices
        various other subroutines for housekeeping emailing telegram
@janpep the example link for lua array examples gives me 3 large black circles! :)
Anyhow I just found this https://www.domoticz.com/wiki/LUA_commands which I didn't know existed and I guess will help a lot and also mentions "local functions" of which I was also not aware.

Thank you for your patience.

Re: Am I doing this wrong?

Posted: Wednesday 29 May 2024 14:30
by janpep
As you spoke about dzVents, also see https://www.domoticz.com/wiki/DzVents:_ ... _scripting