Introducing dzVents - Domoticz Lua file based event scripting made e-z!

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

Moderator: leecollings

Locked
dakipro
Posts: 49
Joined: Thursday 17 December 2015 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Norway
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dakipro »

yeah, I made a simple script that turns on and off every minute to test one of the new switches I made, so I am doing an
if(livingRoomLights.state == 'On') then
livingRoomLights.switchOff()
end
and else for switching on.
In Json there is json.htm?type=command&param=switchlight&idx=46&switchcmd=Toggle
so I was thinking maybe there is a similar function in Lua. But it is not a missing critical, just an very cool convenient feature :)
Raspberry Pi 2 B - MySensors (dimmers, switches, motion, temperature, lux, humidity sensors)
zWave (220v switches)
various 433 via RFLink
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

I think the json call does the same as what you would do manually with Lua.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

I thought this:

Code: Select all

 test = domoticz.devices["vIsDark"]
 
 test.setState( not test.state)
should work to toggle a variable, but got this:
2016-03-20 12:19:00.376 LUA: An error occured when calling event handler Night-and-Day
2016-03-20 12:19:00.377 LUA: /home/pi/domoticz/scripts/lua/Domoticz.lua:98: invalid value (boolean) at index 1 in table for 'concat'
... and little trace back. Any ideas?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Well, the state attribute is a string (like 'On' or 'Off'). You cannot negate strings, only booleans. So unfortunately this will not work.
But I'll add the necessary logic to dzVents soon. For now you have to write a few lines:

Code: Select all

if (device.state == 'On') then
	device.switchOff()
else
	device.switchOn()
end
I'll add

Code: Select all

device.toggleSwitch()
that checks the current state and finds the matching opposing state.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dakipro
Posts: 49
Joined: Thursday 17 December 2015 22:24
Target OS: Raspberry Pi / ODroid
Domoticz version: 3.5877
Location: Norway
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dakipro »

sounds great. Maybe it can be called device.switchToggle(), to be consistent to switchOn and switchOff
Raspberry Pi 2 B - MySensors (dimmers, switches, motion, temperature, lux, humidity sensors)
zWave (220v switches)
various 433 via RFLink
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

Agreed.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

.. or could write:

Code: Select all

test.setState(test.bState and "Off" or "On")
:oops:
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

dannybloe wrote:Agreed.
While you're it, could you add Normal and Alarm as opposites for my marmitek door/window sensors
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

You mean something like this: switchToNormal(), switchToAlarm()
And the toggles of course.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

dannybloe wrote:You mean something like this: switchToNormal(), switchToAlarm()
And the toggles of course.
Hmmm. Probably not since the devices are read-only.

I'm looking in domoticz.lua about line 170 where you booleanize some strings. I'm suggesting you add:

Code: Select all

state == "normal" or
and

Code: Select all

state == "alarm" or
... pretty please.

BTW I'm thinking you're going to be a hostage to fortune trying to implement your negate function because a) you'll find it hard to get a complete list of things to negate, and b) find it even harder to produce a correct list of their inverts for all devices.

By all means have a capability to Invert On to Off and vis versa but anything else is only going to complicate things, not necessarily the code but the documentation. Where do you stop in providing capabilities that can be done in native LUA fairly easily? Are you going to provide and a .increment and .decrement function because it takes two extra lines of code, or perhaps provide a .area or .circumference function? Where do you stop?

What might be handy, however, is a capability whereby users can have a library of functions that are accessible to each of their scripts. Such a library might include a users very own Negate function. I used to have LUA scripts that used the require function but I'm not sure if dzVents would preclude this. Used to be neat because I could write code that created LUA modules on the fly and then include them conditionally or at some future time. It proved useful to provide persistence before variables were introduced.

Keep up the good work. I really don't want to go back to native LUA.

Peter
Last edited by commodore white on Sunday 20 March 2016 20:53, edited 1 time in total.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by dannybloe »

commodore white wrote:
dannybloe wrote:You mean something like this: switchToNormal(), switchToAlarm()
And the toggles of course.
Hmmm. Probably not since the devices are read-only.

I'm looking in domoticz.lua about line 170 where you booleanize some strings. I'm suggesting you add:

Code: Select all

state == "normal" or
and

Code: Select all

state == "alarm" or
... pretty please.
Oh, yeah, already added that today. I recognize all the states I could find in the domoticz code.. I hope ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by NietGiftig »

commodore white wrote: What might be handy, however, is a capability whereby users can have a library of functions that are accessible to each of their scripts. Such a library might include a users very own Negate function.
.......
Keep up the good work. I really don't want to go back to native LUA.

Peter
Looks like a nice addition, i like structure.
But is this not already possible with :

Code: Select all

myLua = require("MyLUACode") -- Include the module with common functions 
Beware, I'm just beginning to discover lua
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by Westcott »

<shameless-plug>
A bit like this?
http://www.domoticz.com/forum/viewtopic ... 23&t=11151
</shameless-plug>
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
commodore white
Posts: 63
Joined: Sunday 14 July 2013 11:19
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Ipswich, UK
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by commodore white »

Looks like a nice addition, i like structure.
But is this not already possible with :

Code: Select all

myLua = require("MyLUACode") -- Include the module with common functions 
Beware, I'm just beginning to discover lua[/quote]

Yes, I'm already aware of the require function. However, I'm also aware that dzVents does things differently so I'm not sure where I'd have to put the require statement so that it didnt get executed repeatedly.

Danny already make the point of not putting too much code in the "active" clause since it gets executed every time a device triggers so I don't want to make matters worse.

Guess I'll just try it. Whats the worse that can happen, eh?
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by woody4165 »

Hi all

sorry for my "stupid" question. :?
To install dzVents from the dzVents-master zip files, do I need to copy only those files to the domoticz/scripts/lua folder

event_helpers.lua
script_time_main.lua
script_device_main.lua
Domoticz.lua
dzVents_settings.lua

and create a scripts folder within domoticz/scripts/lua ?

What about all the other files in the zip under dzVents folder?

Thanks
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by NietGiftig »

I think danny is busy with some changes in github
You only need those files, your own files go in the scripts folder inside the lua
folder
And do not forget to have the examples folder ready, make the jump somewhat easier
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by NietGiftig »

commodore white wrote: Danny already make the point of not putting too much code in the "active" clause since it gets executed every time a device triggers so I don't want to make matters worse.
Guess I'll just try it. Whats the worse that can happen, eh?
Yeah, read that to
Maybe you can place the require outside the execute function, in the beginning of your function.
But I don't know what the effect on the whole business is
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by woody4165 »

Thanks

If I put those files in the domoticz/scripts/lua I get all these errors in the log:

Code: Select all

2016-03-21 12:23:50.600 Error: EventSystem: in /home/pi/domoticz/scripts/lua/script_device_main.lua: /home/pi/domoticz/scripts/lua/EventHelpers.lua:4: module 'utils' not found:
no field package.preload['utils']
no file '/usr/local/share/lua/5.2/utils.lua'
no file '/usr/local/share/lua/5.2/utils/init.lua'
no file '/usr/local/lib/lua/5.2/utils.lua'
no file '/usr/local/lib/lua/5.2/utils/init.lua'
no file './utils.lua'
no file '/home/pi/domoticz/scripts/lua/utils.lua'
no file '/home/pi/domoticz/scripts/lua//dzVents/utils.lua'
no file '/usr/local/lib/lua/5.2/utils.so'
no file '/usr/local/lib/lua/5.2/loadall.so'
no file './utils.so'
And it keeps going this way.

I tried with naming the event_helper.lua (as written in GitHub installation description, as well renaming it as EventHelpers.lua overwriting the actual files.

What am I doing wrong?

Thanks
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
NietGiftig
Posts: 121
Joined: Sunday 11 October 2015 8:50
Target OS: Raspberry Pi / ODroid
Domoticz version: V3.6224
Location: Holland
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by NietGiftig »

use branch 0.9.13 master is rebuild i think
RPI-2 + SSD / ESPEasy Sensors & Switches / Sonoff / RFLink / Action Switches / TP-Link switch / Node-Red / Reacticz
woody4165
Posts: 476
Joined: Monday 14 March 2016 13:55
Target OS: Linux
Domoticz version: beta
Location: Rome, Italy
Contact:

Re: Introducing dzVents - Domoticz Lua file based event scripting made e-z!

Post by woody4165 »

I just downloaded the zip from github, but I get the same error.... :?
Cubietruck - Linux cubietruck 4.13.16 (Debian GNU/Linux 8 (jessie)) + Domoticz + RFLink, Xiaomi Gateway, Owl USB, Yeelight Color and B/W, ESP8266, Broadlink RM2, Netatmo Thermostat
Locked

Who is online

Users browsing this forum: No registered users and 1 guest