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

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

Moderator: leecollings

Locked
fhwessels
Posts: 24
Joined: Sunday 12 April 2015 9:09
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Johannesburg South Africa
Contact:

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

Post by fhwessels »

dannybloe wrote:

So, until I make this feature (which is an interesting idea) you have to check the time yourself (and remove the timer setting completely). You can use dzVents domoticz.time property:

CODE: SELECT ALL

if (domoticz.time.hour > 0 and domoticz.time.hour < 6) then
...
end




But it would be nice if you can define a trigger and combine a time constraint. I'll consider it for 1.1.

I did this and it is not working. I don't get any errors in the log is there something wrong with my code?

Code: Select all

return{
active = true,

on = {
      236,    -- index of the device - 39 book motion led 237 pir 236
	 
        	 
		},
		
   execute = function(domoticz, mySwitch) 
    if (domoticz.time.hour > 19 and domoticz.time.hour < 6) then    
      if (domoticz.devices[236].state == 'On') then
         domoticz.devices[237].dimTo(20)
      end
	end  
      if(domoticz.devices[236].lastUpdate.minutesAgo > 1) then
         domoticz.devices[237].switchOff()
      end
   end
   }

thanks


Francois
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, I'm not sure. The first if-statement I get. As soon as the pir detects motion at night, you turn on a light. Now, how is the light turned off? If the pir isn't activated again, then this script will not be executed so the second if-statement won't do anything. Unless the pir also triggers the script when it doesn't see any motion anymore ( I know they exist). But let's assume the pir only triggers when it sees something. In that case you indeed need a timer as well. This is what I would write:

Code: Select all

return {
	active = true,
	on = {
		236,    -- index of the device - 39 book motion led 237 pir 236
		timer = { 'at 20:*', 'at 21:*', 'at 22:*', 'at 23:*', 'at 00:*', 'at 01:*', 'at 02:*', 'at 03:*', 'at 04:*', 'at 05:*', 
			'at 06:01'} -- the last one is to make sure the light is turned of when the pir turned it on at 05:59 exactly'
	},
	execute = function(domoticz, pir)
		local light = domoticz.devices[237]

		if (domoticz.time.hour > 19 and domoticz.time.hour < 6 and pir.state == 'Motion' then
			light.dimTo(20)
		end
		
		if (light.state == 'On' and pir.lastUpdate.minutesAgo > 1) then 
			-- only do anything if the light is indeed On. Otherwise you will keep sending commands to Domoticz.
			light.switchOff() 
		end
	end
}
I suspect that with pir's domoticz sends the Motion state and not the On state. That could also be the reason why it didn't work for you. Best practice when things don't work is to print information to the domoticz log. You could call domoticz.logDevice( domoticz.device[...] ) to get a full dump of the device state in the log or you could log anything else using domoticz.log(....). I alway check if the script is executed at all, and I put log statements in the if branches to see if you get there as well, and print ohter information like in your case the actual state (domoticz.log(pir.state)) or domoticz.log(domoticz.time.hour). That way you see what is happening.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

1.0 Released

Post by dannybloe »

Just to let you peepz know. 1.0 was released yesterday.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
micke
Posts: 1
Joined: Thursday 02 June 2016 9:36
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by micke »

fhwessels wrote:
I did this and it is not working. I don't get any errors in the log is there something wrong with my code?

Code: Select all

return{
active = true,

on = {
      236,    -- index of the device - 39 book motion led 237 pir 236
	 
        	 
		},
		
   execute = function(domoticz, mySwitch) 
    if (domoticz.time.hour > 19 and domoticz.time.hour < 6) then    
      if (domoticz.devices[236].state == 'On') then
         domoticz.devices[237].dimTo(20)
      end
	end  
      if(domoticz.devices[236].lastUpdate.minutesAgo > 1) then
         domoticz.devices[237].switchOff()
      end
   end
   }
Francois,

You can't have a domoticz.time.hour that is both greater than 19 and smaller than 6. Change the 'and' to 'or'.

/Micke
kiwi
Posts: 14
Joined: Thursday 28 January 2016 13:41
Target OS: Linux
Domoticz version:
Contact:

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

Post by kiwi »

Hi there,

I am trying to use dzVents on my FreeBSD port of domoticz. For unknown reasons domoticz doesn't seems to load the files, so I am puzzled :/
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 »

Just some checks:
  • Make sure you have the dzVents folder in the correct place with all its contents (../domoticz/scripts/lua/dzVents)
  • put both scripts script_device.main.lua and script_time_main.lua in your Lua script folder (../domoticz/scripts/lua) and
  • Rename the settings file to dzVents_settings.lua (and set the http parameters inside to correct ip address etc).
  • Created a subfolder 'scripts' inside your Lua folder (../domoticz/scripts/lua/scripts) and
  • in there create a script file according to the examples/generic.lua (edited to your needs).
  • Make sure the script is active: active=true
If that still doesn't work try to see if Domoticz calls script_time_main.lua. Check the logs or put a print statement in there. That file must be found, that's just basic Domoticz functionality.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
kiwi
Posts: 14
Joined: Thursday 28 January 2016 13:41
Target OS: Linux
Domoticz version:
Contact:

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

Post by kiwi »

Hi,
I make it step by step and it works. I used previously symlinks but it seems that domoticz doesn't like it.
Bororo
Posts: 8
Joined: Thursday 09 June 2016 21:06
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by Bororo »

Can somebody publish working example for sending temperature and humidity data from Oregon sensors to Thingspeak only if values changed, please? I think it will be appreciated by many beginners. Thank you.
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 guess something like this. I don't know the urls for posting to thingspeak but this would probably get you started.

Code: Select all

return {
	active = true,
	on = {
		'myTempHumDevice'
	},
	data = {
		previousTemp = { initial = nil },
		previousHum = { initial = nil }
	},
	execute = function(domoticz, myTempHumDevice)
		local previousTemp = domoticz.data['previousTemp']
		local previousHum = domoticz.data['previousHum']
		
		local currentTemp = myTempHumDevice.temperature;
		local currentHum = myTempHumDevice.humidity;
		
		if (currentTemp and previousTemp ~= currentTemp) then
			-- send the currentTemp to thingspeak
			domoticz.openURL('http:// ... ') -- construct your url
		end
		
		if (currentHum and previousHum ~= currentHum) then
			-- send the currentHum to thingspeak
			domoticz.openURL('http:// .... ') -- construct your url
		end
		
		domoticz.data['prevousTemp'] = currentTemp
		domoticz.data['prevousHum'] = currentHum
		
	end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
svenker
Posts: 36
Joined: Tuesday 06 October 2015 10:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Contact:

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

Post by svenker »

Hello,

Thanks for this easy tool. Really practicale.

Is there a way to use the EzVents tool with the integrate LUA tool of Domoticz ?
It would be really cool to do all LUA scripts directly from the Web Browser versus using Notepad etc and then upload it via FTP.

May be it is working and it is just me that doesn't know how to use it.

Sam
dhanjel
Posts: 102
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

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

Post by dhanjel »

Another idea is to share the folder with the scripts on your network (I assume that you only develop on your local network), and then use a more pleasant editor. As a .Net developer, I really enjoy Visual Studio Code, which is free.
https://code.visualstudio.com/c?utm_exp ... ogle.se%2F
But of course there are a lot of other editors as well.
svenker
Posts: 36
Joined: Tuesday 06 October 2015 10:22
Target OS: Raspberry Pi / ODroid
Domoticz version: Latest
Contact:

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

Post by svenker »

Hello dhanjel,

Thanks for the idea. I have just done that and it works very well :-)

It would be still VERY cool to get it directly via Domoticz in the "Events" page.

Thanks anyway !
Rgds
Sam
dhanjel
Posts: 102
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

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

Post by dhanjel »

Yes, it would be convinient :)
Guess I am old fashioned and want to work outside the browser ;)
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 »

Yeah, same applies for me. External editors are way better. I use WebStorm with the Lua plug-in. Works like a charm.
Anyhow, first step is to get dzVents integrated into Domoticz. I'm currently preparing that with gizmocus. Then we can see how we can have the internal event system use it too. Shouldn't be so hard but requires some C++ programming that I cannot do myself.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
julianmclean
Posts: 20
Joined: Wednesday 08 October 2014 21:52
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by julianmclean »

Firstly, just want to say that dzVents is excellent, and together with the new selector switches in Domoticz, I have just re-written all of my previous logic (spread across Blockly and Lua scripts) into dzVents. In the process of doing this I've managed to make a lot of simplifications, remove a load dummy switches that were used to supplement the blockly/lua, and generally get everything in a much more manageable state. So, many thanks to the developer(s) on this - it really is a major enhancement for the Domoticz environment.

Regarding the points above about integration into Domoticz UI, whilst I am also "old school" and generally develop either directly in vi over SSH or IDE via samba share, it would be great to be able to edit scripts in the browser occasionally, especially when noticing a problem away from home, without having to VPN in, yadda, yadda.

I was actually wondering if anyone knew of a decent, simple browser-based text editor that could be deployed on the Domoticz box (Node.js based would be ideal) and allows simple browsing, opening, creating/editing and saving of the scripts files? I've seen similar things baked into other unrelated platforms, but a quick web search is not turning much up. What would be really good is to have something like this integrated into the Domoticz UI so it's just another menu option to browse and edit script files.
dhanjel
Posts: 102
Joined: Tuesday 05 August 2014 22:16
Target OS: Linux
Domoticz version: 3.5146
Location: Sweden
Contact:

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

Post by dhanjel »

I really don´t get why this isn´t working. Only thing in the log is GCM:

Code: Select all

domoticz.sendCommand('Security Panel', 'Arm Away')
Has anyone else tried to arm from a dzVents script?
User avatar
G3rard
Posts: 669
Joined: Wednesday 04 March 2015 22:15
Target OS: -
Domoticz version: No
Location: The Netherlands
Contact:

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

Post by G3rard »

@dannybloe, just installed dzVents and it looks great! Thanks for all the effort you have put into this.

I have a question regarding the LUA script below which I am currently using. I store a timestamp in a user variable to determine if a switch is pressed 2 times within 3 seconds.
I want to change this script to dzVents, but I am not sure how to change the lastUpdate correctly as described on GitHub.

Old LUA script:

Code: Select all

commandArray = {}

package.path = package.path .. ';' .. '/volume1/@appstore/domoticz/var/scripts/lua/functions/functions.lua'  -- dir functions lua script
local fs = require("functions");    --load functions lua script

TimeBetweenPresses = 3              --max time between presses (in seconds)

if (devicechanged['Lamp keukenkastjes'] == 'Off') then
    if (fs.timedifference(uservariables_lastupdate['Dubbelklikschakelaar']) < TimeBetweenPresses ) then
        --print('Twee keer gedrukt binnen de tijd')
        if (otherdevices['Lux Kamer gang'] == 'Off') then
            --print('Lampen zijn al uit...')
        else
            commandArray['Group:Lampen kamer'] = 'Off'
        end
		commandArray['Variable:Dubbelklikschakelaar']=tostring(os.time())
	else
		--print('Te lang er tussen')
		commandArray['Variable:Dubbelklikschakelaar']=tostring(os.time())
	end
end

return commandArray
dzVents script:

Code: Select all

return {
        active = true,
        on = {
            'Lamp keukenkastjes'
        },
		data = {
			--counter = { initial = 1 },
			previousClick = { initial = nil }
		},
        execute = function(domoticz, switch)
			--calculate the difference in seconds between previous and current click
			print('Vorige tijdstip: ' .. domoticz.data.previousClick)
			local hoursAgo, minsAgo, secsAgo = string.match(domoticz.data.previousClick, "(%d+):(%d+):(%d+)")
			local timestamp = hoursAgo*3600 + minsAgo*60 + secsAgo
			domoticz.data.previousClick = switch.lastUpdate.raw
			local hoursAgo2, minsAgo2, secsAgo2 = string.match(domoticz.data.previousClick, "(%d+):(%d+):(%d+)")
			local timestamp2 = hoursAgo2*3600 + minsAgo2*60 + secsAgo2
			print('Huidige tijdstip: ' .. domoticz.data.previousClick)
			local difference = timestamp2 - timestamp
			print('Verschil: ' .. difference)
			if (difference < 3) then
				print('The switch was pressed 2 times in < 3 seconds!')
				--if (domoticz.data.counter == 2) then
					--domoticz.data.counter = 1 -- reset the counter
				--else
					--domoticz.data.counter = domoticz.data.counter + 1
				--end
			else
				print('Niet binnen de tijd')
			end
        end
    }
I tried to use lastUpdate.secondsAgo but that always returns 0 seconds. So I used lastUpdate.raw and calculate the difference, but I think this can be done easier. What am I doing wrong here :?
Not using Domoticz anymore
digimate
Posts: 19
Joined: Tuesday 02 February 2016 20:20
Target OS: Raspberry Pi / ODroid
Domoticz version: lastbeta
Contact:

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

Post by digimate »

dannybloe wrote:Anyhow, first step is to get dzVents integrated into Domoticz. I'm currently preparing that with gizmocus.
Great news!!! Will it then also be available for Synology 'users'? When? ;-)

Thanks for your efforts!

Sincerely, Nico
Synology DS716+. Domotica devices (on about 30): KaKu (and other 433MHz devices), Z-Wave, Mi-Light, Xiaomi.
ddahya
Posts: 22
Joined: Monday 21 March 2016 1:04
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by ddahya »

Hi Guys,

Just wanted to know if someone could please help with my dzVents script. This is my first attempt to creating a script.

What I want to script to achieve is if the changed value of the thermostat is the same as the previous value then do nothing, if the value is different to the previous then execute a python command with new value and device name.

First attempt at script.

return {
active = true,
on = {
'Dining', 'Guest Room' -- Thermostat Device Names as seen in App
},
data = {
previousTemp = { initial = nil },
},
execute = function(domoticz, device)
local previousTemp = domoticz.data['previousTemp']

local TargetTemp = device.setPoint;

if (TargetTemp and previousTemp ~= TargetTemp) then
-- send the TargetTemp to NeoHub
os.execute('python /home/pi/domoticz/scripts/python/NeoHub.py -s -x '..tonumber(TargetTemp)..' --StatName '.. "'"..deviceName.."'")

end

-- Added some logging for troubleshooting
domoticz.log(deviceName, domoticz_LOG_INFO)
domoticz.log(device.deviceType, domoticz_LOG_INFO)
domoticz.log(TargetTemp, domoticz_LOG_INFO)
domoticz.data['prevousTemp'] = TargetTemp

end
}

Log from Domoticz –
- the device is showing up as a Light/Switch and not a thermostat.
-

2016-08-04 20:02:41.790 LUA: Handling events for: "Guest Room", value: "23.00"
2016-08-04 20:02:41.790 LUA: =====================================================
2016-08-04 20:02:41.790 LUA: >>> Handler: Neo
2016-08-04 20:02:41.790 LUA: >>> Device: "Guest Room" Index: 113
2016-08-04 20:02:41.790 LUA: .....................................................
2016-08-04 20:02:41.791 LUA: Light/Switch
2016-08-04 20:02:41.792 LUA: .....................................................
2016-08-04 20:02:41.792 LUA: <<< Done
2016-08-04 20:02:41.792 LUA: -----------------------------------------------------
2016-08-04 20:02:41.666 (HM: Heating) Thermostat (Guest Room)
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 »

Can you find the device in the devices.lua file and post the table for that device. Then we can see how Domoticz types the device. If it is indeed a switch type then setPoint will not be set. You may have to use one of the other device attributes to get the setpoint.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Locked

Who is online

Users browsing this forum: No registered users and 0 guests