use dzVents to calculate screen position?

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

Moderator: leecollings

Post Reply
renerene
Posts: 356
Joined: Wednesday 03 August 2016 11:36
Target OS: -
Domoticz version:
Contact:

use dzVents to calculate screen position?

Post by renerene »

I use Kaku controllers for my screens. Disadvantage: they do not give feedback on the position. With use of DzVents I want to make my own script, that can calculate the position, based on the time and state of the last two switch actions.
Lets say the screen is closed. It takes app. 20 seconds to open the screen. If thesecond last command was 'Open' and 10 seconds later there was another 'Open' command, I know the screen is 50% open.

Who can help me get started in Dzvents with storing and reading time(1) and value(2) of the last two commands per screen?
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: use dzVents to calculate screen position?

Post by dannybloe »

You can create a historical persistent variable in your script and store the state in the variable:

Code: Select all

return {
	on = { devices = 'myScreen' },
	data = { states = { history = true, maxItems = 10} },
	execute = function(domoticz, screen) 
		-- store the current state
		domoticz.data.states.add(screen.state)
		
		-- read the second last item
		if (domoticz.data.states.size > 1) then
			local secondLast = domoticz.data.states.get(2)
			if (secondLast.data == 'Open') then
				-- etc
			end
			
		end
	end
}
Just to give you an idea. The idea is that you store a stream of state changes and since it is a historical variable, every item you add has a time stamp. Check the doc.
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
DewGew
Posts: 581
Joined: Thursday 21 April 2016 12:01
Target OS: Raspberry Pi / ODroid
Domoticz version: V4.10618
Location: Sweden
Contact:

Re: use dzVents to calculate screen position?

Post by DewGew »

Did you manage to make this script? I have the same issue with my blinds.
Raspberry Pi 3 | domoticz | Aeon Labs Z-Stick GEN5 | RFlink gateway
NanoPi NEO-air | REGO6XX interface | Machinon theme | Homebridge | Domoticz Google Assistant | ideAlarm
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest