26.02.2022, 16:23 
		
	
	
		Hi,
 
I have a top-down/bottom-up blind that can be controlled with a hub named PowerView. Firstly, I tried to control it with relays since, in my opinion, it is better than a wireless connection, but unfortunately, I had some problems, so I started to control it with API through the PowerView hub. I am able to control it, but I have the problem that I am using a slide control from a touch panel to set the blind position. I use an event script, and each time I slide the slider a bit, it sends an event, which results in the blind moving in many smaller steps. I would like to only have one event, which then waits 2 seconds before it reads the target position for the blind.
Event from slider:
Blind function:
Br,
Mads
	
	
	
I have a top-down/bottom-up blind that can be controlled with a hub named PowerView. Firstly, I tried to control it with relays since, in my opinion, it is better than a wireless connection, but unfortunately, I had some problems, so I started to control it with API through the PowerView hub. I am able to control it, but I have the problem that I am using a slide control from a touch panel to set the blind position. I use an event script, and each time I slide the slider a bit, it sends an event, which results in the blind moving in many smaller steps. I would like to only have one event, which then waits 2 seconds before it reads the target position for the blind.
Event from slider:
Code:
require('user.Blind_TopDownBottomUp')
require('sem')
-- group address or name
addr = '0/2/7'
ShadeID = '63686'
semaphore = sem.open('eventlock')
timeout = 5 * 10
-- wait for unlock or 5 second timeout
while not semaphore:trywait() and timeout > 0 do
  sleep(0.1)
  timeout = timeout - 1
end
-- perform script actions
Blind(ShadeID, addr)
-- unlock semaphore
semaphore:post()Blind function:
Code:
-- blind (Top-down/Bottom-up)
function Blind(ShadeID, addr)
  require('ltn12')
  require('json')
    http = require('socket.http')
  
  local Bridge = '192.168.1.50'
  -- Blind Position
    Pos = grp.getvalue(addr)
    BlindPos = tostring(math.floor(Pos*655.35));
  
    
  url = 'http://' .. Bridge .. '/api/shades'
  
  
  res, code, headers, status = http.request(url)
  
  
  -- position1 is the bottom rail and it is 0 at the bottom and 65535 at the top
  -- position2 is the top rail and it is 65535 at the bottom and 0 at the top
  body = '{"shade":{"positions":{"posKind1":1,"position1":' .. BlindPos .. ',"posKind2":2,"position2":0}}}'
   
     -- Send position 
  res, code = http.request({
  url = 'http://' .. Bridge .. '/api/shades/' .. ShadeID,
  method = 'PUT',
  headers = {
    ['Content-Length'] = #body,
    ['Content-Type'] = 'application/json',
  },
  source = ltn12.source.string(body)
})
  
endBr,
Mads