Page 1 of 1

use dzVents to calculate screen position?

Posted: Friday 22 December 2017 17:47
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?

Re: use dzVents to calculate screen position?

Posted: Saturday 23 December 2017 13:52
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.

Re: use dzVents to calculate screen position?

Posted: Wednesday 03 January 2018 11:17
by DewGew
Did you manage to make this script? I have the same issue with my blinds.