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

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

Moderator: leecollings

Locked
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 »

Here is the table from the Guest Room thermostat in device.lua
{
["AddjMulti"]= 1.0,
["AddjMulti2"]= 1.0,
["AddjValue"]= 0.0,
["AddjValue2"]= 0.0,
["BatteryLevel"]= 255,
["CustomImage"]= 102,
["Data"]= "Off",
["Description"]= "",
["Favorite"]= 0,
["HardwareID"]= 5,
["HardwareName"]= "HM: Heating",
["HardwareType"]= "Dummy (Does nothing, use for virtual switches only)",
["HardwareTypeVal"]= 15,
["HaveDimmer"]= true,
["HaveGroupCmd"]= true,
["HaveTimeout"]= false,
["ID"]= "000140C0",
["Image"]= "Underfloor",
["IsSubDevice"]= false,
["LastUpdate"]= "2016-08-04 20:26:05",
["Level"]= 0,
["LevelInt"]= 0,
["MaxDimLevel"]= 100,
["Name"]= "Guest Room",
["Notifications"]= "false",
["PlanID"]= "0",
["PlanIDs"]= { 0 },
["Protected"]= false,
["ShowNotifications"]= true,
["SignalLevel"]= "-",
["Status"]= "Off",
["StrParam1"]= "",
["StrParam2"]= "",
["SubType"]= "Switch",
["SwitchType"]= "On/Off",
["SwitchTypeVal"]= 0,
["Timers"]= "false",
["Type"]= "Light/Switch",
["TypeImg"]= "lightbulb",
["Unit"]= 1,
["UsedByCamera"]= false,
["XOffset"]= "0",
["YOffset"]= "0",
["idx"]= "113"
},
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'll have to create the device as a Thermostat dummy instead of a switch. I think that would solve your problem.
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:

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

Post by dannybloe »

G3rard wrote:@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 :?

First of all, I'd make the script a bit shorter by using historical storage because that already stores the time for each sample (see help):

Code: Select all

return {
	active = true,
	on = {'Lamp keukenkastjes'},
	data = { previousClick = { history = true, maxItems = 1 } },
	execute = function(domoticz, switch)

		domoticz.data.previousClick.add('click');
		local previous = domoticz.data.previousClick.getLatest()
		
		if (previous.time.secondsAgo < 3) then
			domoticz.log('The switch was pressed 2 times in < 3 seconds!', domoticz.LOG_INFO)
		end
		
	end
}
I'm not sure though if Domoticz is fast enough to detect 3 short clicks right after each other.And maybe you should set it to <4. Not sure.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 wrote: First of all, I'd make the script a bit shorter by using historical storage because that already stores the time for each sample (see help):

Code: Select all

return {
	active = true,
	on = {'Lamp keukenkastjes'},
	data = { previousClick = { history = true, maxItems = 1 } },
	execute = function(domoticz, switch)

		domoticz.data.previousClick.add('click');
		local previous = domoticz.data.previousClick.getLatest()
		
		if (previous.time.secondsAgo < 3) then
			domoticz.log('The switch was pressed 2 times in < 3 seconds!', domoticz.LOG_INFO)
		end
		
	end
}
I'm not sure though if Domoticz is fast enough to detect 3 short clicks right after each other.And maybe you should set it to <4. Not sure.
Thanks for the response.
Running this code (only changed the name of the switch to Kaku schakelaar) gives the following error:

Code: Select all

2016-08-04 14:10:50.165 LUA: >>> Handler: Dubbelklik
2016-08-04 14:10:50.165 LUA: >>> Device: "Kaku schakelaar" Index: 338
2016-08-04 14:10:50.166 Error: EventSystem: in /home/gerard/domoticz/scripts/lua/script_device_main.lua: ...erard/domoticz/scripts/lua/dzVents/HistoricalStorage.lua:89: bad argument #1 to 'ipairs' (table expected, got string)
Any ideas how to fix this?

I currently use a LUA script to detect double click, which needs to be done within 3 seconds. That works, but indeed you can't double click to soon after the first click because that second click then won't be noticed.
Not using Domoticz anymore
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 »

G3rard wrote:
dannybloe wrote: First of all, I'd make the script a bit shorter by using historical storage because that already stores the time for each sample (see help):

Code: Select all

return {
	active = true,
	on = {'Lamp keukenkastjes'},
	data = { previousClick = { history = true, maxItems = 1 } },
	execute = function(domoticz, switch)

		domoticz.data.previousClick.add('click');
		local previous = domoticz.data.previousClick.getLatest()
		
		if (previous.time.secondsAgo < 3) then
			domoticz.log('The switch was pressed 2 times in < 3 seconds!', domoticz.LOG_INFO)
		end
		
	end
}
I'm not sure though if Domoticz is fast enough to detect 3 short clicks right after each other.And maybe you should set it to <4. Not sure.
Thanks for the response.
Running this code (only changed the name of the switch to Kaku schakelaar) gives the following error:

Code: Select all

2016-08-04 14:10:50.165 LUA: >>> Handler: Dubbelklik
2016-08-04 14:10:50.165 LUA: >>> Device: "Kaku schakelaar" Index: 338
2016-08-04 14:10:50.166 Error: EventSystem: in /home/gerard/domoticz/scripts/lua/script_device_main.lua: ...erard/domoticz/scripts/lua/dzVents/HistoricalStorage.lua:89: bad argument #1 to 'ipairs' (table expected, got string)
Any ideas how to fix this?

I currently use a LUA script to detect double click, which needs to be done within 3 seconds. That works, but indeed you can't double click to soon after the first click because that second click then won't be noticed.
Ah, I guess that's becuase the name of the variable is the same but of a different type. Try to remove the side-car file in scripts/storage (__data_yourscript1.lua) or rename the variable in you script.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

Yeah, renamed the variable, that works :)

But now it doesn't detect a doubleclick between 3 seconds. If I print previous.time.secondsAgo to the log it's always 0.
And the second press is detected and between 3 seconds :?

Code: Select all

2016-08-04 14:37:27.906 LUA: -----------------------------------------------------
2016-08-04 14:37:27.906 LUA: <<< Done 
2016-08-04 14:37:27.905 LUA: 0
2016-08-04 14:37:27.905 LUA: >>> Device: "Kaku schakelaar" Index: 338
2016-08-04 14:37:27.905 LUA: >>> Handler: Dubbelklik
2016-08-04 14:37:27.905 LUA: =====================================================
2016-08-04 14:37:26.257 RFXCOM: Lighting 2 | Kaku schakelaar 
2016-08-04 14:37:26.282 LUA: -----------------------------------------------------
2016-08-04 14:37:26.282 LUA: <<< Done 
2016-08-04 14:37:26.282 LUA: 0
2016-08-04 14:37:26.281 LUA: >>> Device: "Kaku schakelaar" Index: 338
2016-08-04 14:37:26.281 LUA: >>> Handler: Dubbelklik
2016-08-04 14:37:26.281 LUA: =====================================================
Not using Domoticz anymore
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 »

Ah, my bad. Of course it is always 0 because at the beginning of the script I overwrite the only value in the historical queue ;-)
Of course you need to do the add afterwards:

Code: Select all

return {
	active = true,
	on = {'Lamp keukenkastjes'},
	data = { previousClick = { history = true, maxItems = 1 } },
	execute = function(domoticz, switch)
		
		local previous = domoticz.data.previousClick.getLatest()
		
		if (previous and previous.time.secondsAgo < 3) then
			domoticz.log('The switch was pressed 2 times in < 3 seconds!', domoticz.LOG_INFO)
		end
		
		domoticz.data.previousClick.add('click');
		
	end
}
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

Ah, of course, that did the trick. Thanks!
Not using Domoticz anymore
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 »

Ain't that a nice short script? Almost reads like nice poem :lol:
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

Yep and I don't need an user variable anymore as in the old LUA script 8-)
Not using Domoticz anymore
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 »

Thanks, I now have it working but when the thermostat is updated it triggers two events, one with the device name and another with device name _Utility
Is there any way I get dzVents to ignore device name_Utility event?

Code: Select all

2016-08-05 10:21:49.046 LUA: Handling events for: "Master Room_Utility", value: "20" 
2016-08-05 10:21:49.046 LUA: ===================================================== 
2016-08-05 10:21:49.046 LUA: >>> Handler: Neo 
2016-08-05 10:21:49.046 LUA: >>> Device: "Master Room" Index: 96 
2016-08-05 10:21:49.046 LUA: ..................................................... 
2016-08-05 10:21:49.047 LUA: Master Room 
2016-08-05 10:21:49.047 LUA: Thermostat 
2016-08-05 10:21:49.047 LUA: 20 
2016-08-05 10:21:49.047 LUA: python /home/pi/domoticz/scripts/python/NeoHub.py -s -x 20 --StatName 'Master Room' 
2016-08-05 10:21:49.048 LUA: ..................................................... 
2016-08-05 10:21:49.048 LUA: <<< Done 
2016-08-05 10:21:49.048 LUA: ----------------------------------------------------- 
2016-08-05 10:21:48.982 (NeoHub) Thermostat (Master Room) 

And

2016-08-05 10:21:47.830 LUA: Handling events for: "Master Room", value: "20.00" 
2016-08-05 10:21:47.830 LUA: ===================================================== 
2016-08-05 10:21:47.830 LUA: >>> Handler: Neo 
2016-08-05 10:21:47.830 LUA: >>> Device: "Master Room" Index: 96 
2016-08-05 10:21:47.830 LUA: ..................................................... 
2016-08-05 10:21:47.830 LUA: Master Room 
2016-08-05 10:21:47.830 LUA: Thermostat 
2016-08-05 10:21:47.831 LUA: 20 
2016-08-05 10:21:47.831 LUA: python /home/pi/domoticz/scripts/python/NeoHub.py -s -x 20 --StatName 'Master Room' 
2016-08-05 10:21:47.831 LUA: ..................................................... 
2016-08-05 10:21:47.832 LUA: <<< Done 
2016-08-05 10:21:47.832 LUA: ----------------------------------------------------- 
2016-08-05 10:21:47.770 (NeoHub) Thermostat (Master 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 »

ddahya wrote:Thanks, I now have it working but when the thermostat is updated it triggers two events, one with the device name and another with device name _Utility
Is there any way I get dzVents to ignore device name_Utility event?

Code: Select all

2016-08-05 10:21:49.046 LUA: Handling events for: "Master Room_Utility", value: "20" 
2016-08-05 10:21:49.046 LUA: ===================================================== 
2016-08-05 10:21:49.046 LUA: >>> Handler: Neo 
2016-08-05 10:21:49.046 LUA: >>> Device: "Master Room" Index: 96 
2016-08-05 10:21:49.046 LUA: ..................................................... 
2016-08-05 10:21:49.047 LUA: Master Room 
2016-08-05 10:21:49.047 LUA: Thermostat 
2016-08-05 10:21:49.047 LUA: 20 
2016-08-05 10:21:49.047 LUA: python /home/pi/domoticz/scripts/python/NeoHub.py -s -x 20 --StatName 'Master Room' 
2016-08-05 10:21:49.048 LUA: ..................................................... 
2016-08-05 10:21:49.048 LUA: <<< Done 
2016-08-05 10:21:49.048 LUA: ----------------------------------------------------- 
2016-08-05 10:21:48.982 (NeoHub) Thermostat (Master Room) 

And

2016-08-05 10:21:47.830 LUA: Handling events for: "Master Room", value: "20.00" 
2016-08-05 10:21:47.830 LUA: ===================================================== 
2016-08-05 10:21:47.830 LUA: >>> Handler: Neo 
2016-08-05 10:21:47.830 LUA: >>> Device: "Master Room" Index: 96 
2016-08-05 10:21:47.830 LUA: ..................................................... 
2016-08-05 10:21:47.830 LUA: Master Room 
2016-08-05 10:21:47.830 LUA: Thermostat 
2016-08-05 10:21:47.831 LUA: 20 
2016-08-05 10:21:47.831 LUA: python /home/pi/domoticz/scripts/python/NeoHub.py -s -x 20 --StatName 'Master Room' 
2016-08-05 10:21:47.831 LUA: ..................................................... 
2016-08-05 10:21:47.832 LUA: <<< Done 
2016-08-05 10:21:47.832 LUA: ----------------------------------------------------- 
2016-08-05 10:21:47.770 (NeoHub) Thermostat (Master Room) 
That's weird. This should not happen as there is a check that the same device isn't triggered twice in this case. Just to make sure, are you on the latest version of dzVents? Could you try the dev branch (download)?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

Thanks that done the trick, i was running dzVents 1.1.1.

Just wanted to know if you are about to assist with my script. What i want it to do is if the targettemp is different to the previousTemp then run the os.execute command. if the targettemp and previousTemp are the same then do nothing, end

Thanks again for all your help.

Code: Select all

return {
   active = true,
   on = {
      'Dining'  -- Thermostat Device Names as seen in App
   },
   data = {
      previousTemp = { initial = 20 },
   },
   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 '..TargetTemp..' --StatName '.."'"..device.name.."'")
     
      end
	domoticz.log(device.name, domoticz_LOG_INFO)
	domoticz.log(device.deviceType, domoticz_LOG_INFO)
	domoticz.log(TargetTemp, domoticz_LOG_INFO)
	domoticz.log(previousTemp, domoticz_LOG_INFO)
	domoticz.log('python /home/pi/domoticz/scripts/python/NeoHub.py -s -x  '..tonumber(TargetTemp)..' --StatName '..  "'"..device.name.."'")

        domoticz.data['prevousTemp'] = TargetTemp
      
   end
}
This is whats its currently doing, the new TargetTemp is 23 and the previousTemp is 24

Code: Select all

 2016-08-05 21:26:08.859 LUA: Handling events for: "Dining", value: "23.00"
2016-08-05 21:26:08.859 LUA: =====================================================
2016-08-05 21:26:08.859 LUA: >>> Handler: neo
2016-08-05 21:26:08.859 LUA: >>> Device: "Dining" Index: 111
2016-08-05 21:26:08.859 LUA: .....................................................
2016-08-05 21:26:14.202 LUA: Dining
2016-08-05 21:26:14.202 LUA: Thermostat
2016-08-05 21:26:14.202 LUA: 24
2016-08-05 21:26:14.202 LUA: 20
2016-08-05 21:26:14.202 LUA: python /home/pi/domoticz/scripts/python/NeoHubInterface.py -s -x 24 --StatName 'Dining'
2016-08-05 21:26:14.203 LUA: .....................................................
2016-08-05 21:26:14.203 LUA: <<< Done
2016-08-05 21:26:14.203 LUA: -----------------------------------------------------
2016-08-05 21:26:08.758 (HM: Heating) Thermostat (Dining) 
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 »

ddahya wrote:Thanks that done the trick, i was running dzVents 1.1.1.

Just wanted to know if you are about to assist with my script. What i want it to do is if the targettemp is different to the previousTemp then run the os.execute command. if the targettemp and previousTemp are the same then do nothing, end

Thanks again for all your help.

Code: Select all

return {
   active = true,
   on = {
      'Dining'  -- Thermostat Device Names as seen in App
   },
   data = {
      previousTemp = { initial = 20 },
   },
   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 '..TargetTemp..' --StatName '.."'"..device.name.."'")
     
      end
	domoticz.log(device.name, domoticz_LOG_INFO)
	domoticz.log(device.deviceType, domoticz_LOG_INFO)
	domoticz.log(TargetTemp, domoticz_LOG_INFO)
	domoticz.log(previousTemp, domoticz_LOG_INFO)
	domoticz.log('python /home/pi/domoticz/scripts/python/NeoHub.py -s -x  '..tonumber(TargetTemp)..' --StatName '..  "'"..device.name.."'")

        domoticz.data['prevousTemp'] = TargetTemp
      
   end
}
This is whats its currently doing, the new TargetTemp is 23 and the previousTemp is 24

Code: Select all

 2016-08-05 21:26:08.859 LUA: Handling events for: "Dining", value: "23.00"
2016-08-05 21:26:08.859 LUA: =====================================================
2016-08-05 21:26:08.859 LUA: >>> Handler: neo
2016-08-05 21:26:08.859 LUA: >>> Device: "Dining" Index: 111
2016-08-05 21:26:08.859 LUA: .....................................................
2016-08-05 21:26:14.202 LUA: Dining
2016-08-05 21:26:14.202 LUA: Thermostat
2016-08-05 21:26:14.202 LUA: 24
2016-08-05 21:26:14.202 LUA: 20
2016-08-05 21:26:14.202 LUA: python /home/pi/domoticz/scripts/python/NeoHubInterface.py -s -x 24 --StatName 'Dining'
2016-08-05 21:26:14.203 LUA: .....................................................
2016-08-05 21:26:14.203 LUA: <<< Done
2016-08-05 21:26:14.203 LUA: -----------------------------------------------------
2016-08-05 21:26:08.758 (HM: Heating) Thermostat (Dining) 
I suspect it has something to do with the typo you made in the last line:

Code: Select all

domoticz.data['prevousTemp'] = TargetTemp
Guess that should be:

Code: Select all

domoticz.data['previousTemp'] = TargetTemp
If that isn't the case, could you add this line in your script:

Code: Select all

domoticz.logDevice(device)
I'm curious what all the device attributes are.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

Here is the device attributes for my Dining thermostat in my prod machine.

Code: Select all

 2016-08-06 11:02:13.443 LUA: Handling events for: "Dining_Utility", value: "22"
2016-08-06 11:02:13.443 LUA: =====================================================
2016-08-06 11:02:13.443 LUA: >>> Handler: neohub
2016-08-06 11:02:13.443 LUA: >>> Device: "Dining" Index: 111
2016-08-06 11:02:13.443 LUA: .....................................................
2016-08-06 11:02:13.444 LUA: Dining
2016-08-06 11:02:13.444 LUA: Thermostat
2016-08-06 11:02:13.444 LUA: 23
2016-08-06 11:02:13.444 LUA: 23
2016-08-06 11:02:13.444 LUA: python /home/pi/domoticz/scripts/python/NeoHub.py -s -x 23 --StatName 'Dining'
2016-08-06 11:02:13.444 LUA: > hardwareId: 5
2016-08-06 11:02:13.444 LUA: > setPoint: 23
2016-08-06 11:02:13.444 LUA: > counterTotal:
2016-08-06 11:02:13.444 LUA: > counterToday:
2016-08-06 11:02:13.444 LUA: > timedOut: false
2016-08-06 11:02:13.444 LUA: > batteryLevel: 255
2016-08-06 11:02:13.444 LUA: > hardwareTypeVal: 15
2016-08-06 11:02:13.445 LUA: > id: 111
2016-08-06 11:02:13.445 LUA: > hardwareTypeValue: 15
2016-08-06 11:02:13.445 LUA: > hardwareType: Dummy (Does nothing, use for virtual switches only)
2016-08-06 11:02:13.445 LUA: > deviceType: Thermostat
2016-08-06 11:02:13.445 LUA: > deviceSubType: SetPoint
2016-08-06 11:02:13.445 LUA: > description:
2016-08-06 11:02:13.445 LUA: > signalLevel: -
2016-08-06 11:02:13.445 LUA: > name: Dining
2016-08-06 11:02:13.445 LUA: > changed: false
2016-08-06 11:02:13.445 LUA: > rawData:
2016-08-06 11:02:13.445 LUA: > 1: 23.0
2016-08-06 11:02:13.445 LUA: > lastUpdate:
2016-08-06 11:02:13.445 LUA: > month: 8
2016-08-06 11:02:13.445 LUA: > year: 2016
2016-08-06 11:02:13.445 LUA: > day: 6
2016-08-06 11:02:13.446 LUA: > raw: 2016-08-06 10:59:04
2016-08-06 11:02:13.446 LUA: > hoursAgo: 0
2016-08-06 11:02:13.446 LUA: > rawTime: 10:59:4
2016-08-06 11:02:13.446 LUA: > minutesAgo: 3
2016-08-06 11:02:13.446 LUA: > rawDate: 2016-8-6
2016-08-06 11:02:13.446 LUA: > isdst: false
2016-08-06 11:02:13.446 LUA: > yday: 219
2016-08-06 11:02:13.446 LUA: > current:
2016-08-06 11:02:13.446 LUA: > sec: 13
2016-08-06 11:02:13.446 LUA: > year: 2016
2016-08-06 11:02:13.446 LUA: > isdst: false
2016-08-06 11:02:13.446 LUA: > yday: 219
2016-08-06 11:02:13.446 LUA: > day: 6
2016-08-06 11:02:13.446 LUA: > wday: 7
2016-08-06 11:02:13.446 LUA: > month: 8
2016-08-06 11:02:13.447 LUA: > hour: 11
2016-08-06 11:02:13.447 LUA: > min: 2
2016-08-06 11:02:13.447 LUA: > sec: 4
2016-08-06 11:02:13.447 LUA: > secondsAgo: 189
2016-08-06 11:02:13.447 LUA: > isToday: true
2016-08-06 11:02:13.447 LUA: > wday: 7
2016-08-06 11:02:13.447 LUA: > hour: 10
2016-08-06 11:02:13.447 LUA: > min: 59
2016-08-06 11:02:13.447 LUA: > hardwareName: HM: Heating
2016-08-06 11:02:13.448 LUA: .....................................................
2016-08-06 11:02:13.448 LUA: <<< Done
2016-08-06 11:02:13.448 LUA: ----------------------------------------------------- 
Here is the device attributes for the same device "Dining" thermostat in my POC machine.

Code: Select all

 2016-08-06 10:40:15.335 LUA: Handling events for: "Dining_Utility", value: "23"
2016-08-06 10:40:15.335 LUA: =====================================================
2016-08-06 10:40:15.335 LUA: >>> Handler: Neo
2016-08-06 10:40:15.335 LUA: >>> Device: "Dining" Index: 94
2016-08-06 10:40:15.335 LUA: .....................................................
2016-08-06 10:40:20.638 LUA: python /home/pi/domoticz/scripts/python/NeoHubInterface.py -s -x 23 --StatName 'Dining'
2016-08-06 10:40:20.638 LUA: > counterTotal:
2016-08-06 10:40:20.638 LUA: > hardwareTypeValue: 15
2016-08-06 10:40:20.638 LUA: > lastUpdate:
2016-08-06 10:40:20.638 LUA: > minutesAgo: 0
2016-08-06 10:40:20.639 LUA: > month: 8
2016-08-06 10:40:20.639 LUA: > rawTime: 10:40:15
2016-08-06 10:40:20.639 LUA: > isToday: true
2016-08-06 10:40:20.639 LUA: > secondsAgo: 0
2016-08-06 10:40:20.639 LUA: > current:
2016-08-06 10:40:20.639 LUA: > month: 8
2016-08-06 10:40:20.639 LUA: > min: 40
2016-08-06 10:40:20.639 LUA: > yday: 219
2016-08-06 10:40:20.639 LUA: > year: 2016
2016-08-06 10:40:20.639 LUA: > hour: 10
2016-08-06 10:40:20.639 LUA: > isdst: false
2016-08-06 10:40:20.640 LUA: > wday: 7
2016-08-06 10:40:20.640 LUA: > day: 6
2016-08-06 10:40:20.640 LUA: > sec: 15
2016-08-06 10:40:20.640 LUA: > isdst: false
2016-08-06 10:40:20.640 LUA: > sec: 15
2016-08-06 10:40:20.640 LUA: > hoursAgo: 0
2016-08-06 10:40:20.640 LUA: > wday: 7
2016-08-06 10:40:20.640 LUA: > yday: 219
2016-08-06 10:40:20.640 LUA: > year: 2016
2016-08-06 10:40:20.640 LUA: > rawDate: 2016-8-6
2016-08-06 10:40:20.640 LUA: > min: 40
2016-08-06 10:40:20.641 LUA: > raw: 2016-08-06 10:40:15
2016-08-06 10:40:20.641 LUA: > hour: 10
2016-08-06 10:40:20.641 LUA: > day: 6
2016-08-06 10:40:20.641 LUA: > deviceSubType: SetPoint
2016-08-06 10:40:20.641 LUA: > hardwareType: Dummy (Does nothing, use for virtual switches only)
2016-08-06 10:40:20.641 LUA: > hardwareName: NeoHub
2016-08-06 10:40:20.641 LUA: > changed: true
2016-08-06 10:40:20.641 LUA: > utility: 23
2016-08-06 10:40:20.641 LUA: > bState: false
2016-08-06 10:40:20.641 LUA: > timedOut: true
2016-08-06 10:40:20.641 LUA: > rawData:
2016-08-06 10:40:20.641 LUA: > 1: 23.00
2016-08-06 10:40:20.642 LUA: > description:
2016-08-06 10:40:20.642 LUA: > signalLevel: -
2016-08-06 10:40:20.642 LUA: > setPoint: 23
2016-08-06 10:40:20.642 LUA: > state: 23.00
2016-08-06 10:40:20.642 LUA: > hardwareId: 10
2016-08-06 10:40:20.642 LUA: > counterToday:
2016-08-06 10:40:20.642 LUA: > hardwareTypeVal: 15
2016-08-06 10:40:20.642 LUA: > name: Dining
2016-08-06 10:40:20.642 LUA: > batteryLevel: 255
2016-08-06 10:40:20.643 LUA: > deviceType: Thermostat
2016-08-06 10:40:20.643 LUA: > _sValues: 23.00
2016-08-06 10:40:20.643 LUA: > id: 94
2016-08-06 10:40:20.644 LUA: .....................................................
2016-08-06 10:40:20.644 LUA: <<< Done
They are both running the same version of dzVents, the new dev branch supplied in an earlier post.
Looks like the POC machine as a few more attributes then my prod machine.

Version of Domoticz running on pi
POC machine is running an older version 3.5231
Prod machine is running 3.5406
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 »

Could be because Domoticz sometimes swallows log messages when they come too fast or too many. Might be differen each time you run the script. But does it work now?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
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 »

dannybloe wrote:Could be because Domoticz sometimes swallows log messages when they come too fast or too many. Might be differen each time you run the script. But does it work now?
Its working on my PoC machine but not my Prod box.
If you look at the device attributes from my prod machine it's missing,

2016-08-06 10:40:20.641 LUA: > utility: 23
2016-08-06 10:40:20.642 LUA: > state: 23.00
2016-08-06 10:40:20.643 LUA: > _sValues: 23.00

these are in the PoC box.
Abbell
Posts: 3
Joined: Saturday 06 August 2016 5:27
Target OS: -
Domoticz version:
Contact:

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

Post by Abbell »

First let me state that I do not write LUAs. This is simply because I have never written one. I think it is about time. I have been teaching myself Arduino sketches over the last four weeks. Now it is time to work on these.

I have created several Blocky scripts that all work without issue. This time I need to create a script that can take into account pauses. I have a simple meter that reads my washing machine wattage. The problem I encounter is that when I try to account for the moments in the script when the wattage drops for sort periods it fails to ignore the time period of these drops. I installed dzVents to help with the timing, but the implementation escapes me.

The Blocky script turns on the washer switch once the wattage goes above 50w.
If the switch is on and the wattage drops below 50w it turns on a washer timer after 300sec
If the switch is on and the wattage drops below 50w and the washer timer is on then it turns off the switch

The issue arises that the timer is an absolute. Can I use dzVents to check when the last time the wattage dropped below 50w more than a set time to turn the washer switch off?

In advance, I greatly appreciate the insights offered.
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 »

ddahya wrote:
dannybloe wrote:Could be because Domoticz sometimes swallows log messages when they come too fast or too many. Might be differen each time you run the script. But does it work now?
Its working on my PoC machine but not my Prod box.
If you look at the device attributes from my prod machine it's missing,

2016-08-06 10:40:20.641 LUA: > utility: 23
2016-08-06 10:40:20.642 LUA: > state: 23.00
2016-08-06 10:40:20.643 LUA: > _sValues: 23.00

these are in the PoC box.
That's really strange. Can you try to give the device the same name in production as it has on your poc machine? There must be some discrepancy between the two machines. I suspect the naming may be the culprit as Domoticz doesn't use ids but names in the Lua tables it provides to the scripts. I have to do some juggling to match all those tables to the same devices but it's all done by name.
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:

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

Post by dannybloe »

Abbell wrote:First let me state that I do not write LUAs. This is simply because I have never written one. I think it is about time. I have been teaching myself Arduino sketches over the last four weeks. Now it is time to work on these.

I have created several Blocky scripts that all work without issue. This time I need to create a script that can take into account pauses. I have a simple meter that reads my washing machine wattage. The problem I encounter is that when I try to account for the moments in the script when the wattage drops for sort periods it fails to ignore the time period of these drops. I installed dzVents to help with the timing, but the implementation escapes me.

The Blocky script turns on the washer switch once the wattage goes above 50w.
If the switch is on and the wattage drops below 50w it turns on a washer timer after 300sec
If the switch is on and the wattage drops below 50w and the washer timer is on then it turns off the switch

The issue arises that the timer is an absolute. Can I use dzVents to check when the last time the wattage dropped below 50w more than a set time to turn the washer switch off?

In advance, I greatly appreciate the insights offered.
Ah, I love this one. There are several ways to do it and I think this one is the simplest. It uses one historical data point previous that holds only one value (high or low). Advantage of using historical data variables is that it stores a time-stamp each time you add a value to the history. In our case we only store one value though as we are only interested in when we go from high to low. So we only set a new value when we go from high usage to low or vice versa. Each cycle the script is run we check the current usage and if the previous value is 'low' then we inspect when that 'low' value was written (previousState.time.secondsAgo):

Code: Select all

local THRESHOLD_USAGE = 50 -- watt
local THRESHOLD_TIME = 300 -- seconds

return {
	active = true,
	on = { 'MachineUsage' },
	data = { 
		previous = { history = true, maxItems = 1 } -- holds 'high' or 'low' 
	},
	execute = function(domoticz, usage)

		if (domoticz.data.previous.size == 0) then
			-- initialize to 'low'
			domoticz.data.previous.add('low')
		end

		local previousState = domoticz.data.previous.getLatest()
		local machineBusy = domoticz.devices['MachineBusySwitch']
		local current = usage.WActual  -- may need usage.utility here instead
				
		if (current > THRESHOLD_USAGE and (previousState.data == 'low')) then
			-- going from low to high
			domoticz.data.previous.add('high')
			if (machineBusy.state == 'Off') then
				machineBusy.switchOn()
			end
		end
			
		if (current <= THRESHOLD_USAGE) then

			-- check if we dropped from high to low 
			if (previousState.data == 'high') then
				-- we go from high to low, store this moment
				domoticz.data.previous.add('low')
			else
				-- we were already low
				if (previousState.time.secondsAgo > THRESHOLD_TIME and machineBusy.state == 'On') then
					-- program is finished
					machineBusy.switchOff()
					domoticz.notify('Washing machine', 'Washing machine is ready', domoticz.PRIORITY_NORMAL)
				end
			end
		end
		
	end
}
Oh, and this is untested code ;-)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
Locked

Who is online

Users browsing this forum: No registered users and 1 guest