This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

PowerView Blind Control
#1
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:
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)
})
 
end

Br,
Mads
Reply
#2
Maybe try adding steps in slider settings. You can then use arrows to change by step.
------------------------------
Ctrl+F5
Reply
#3
You can also check whether the object value changed after sleeping.
Code:
local value = event.getvalue()

os.sleep(2)

if grp.getvalue(event.dst) == value then
  -- do something here
end
Reply


Forum Jump: