Logic Machine Forum
PowerView Blind Control - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: PowerView Blind Control (/showthread.php?tid=3904)



PowerView Blind Control - madsroge90 - 26.02.2022

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


RE: PowerView Blind Control - Daniel - 28.02.2022

Maybe try adding steps in slider settings. You can then use arrows to change by step.


RE: PowerView Blind Control - admin - 28.02.2022

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