I found this script
Now with this python script you can send bluetooth commands to control it. Some theory behind the script, it's using the following curl command
Code: Select all
curl -i http://localhost:5000/AM43BlindsAction/"Action"
number 0-100 --> Set blinds to position wanted
Open --> Opening blinds
Close --> Closing blinds
CheckStatus --> Get battery status, current position and light in %
I'm able to control it using my Raspberry Pi. Of course now I also want to integrate it in Domoticz. For a noob I came quite far already, if I say myself. I have the battery and light (sensor) percentage already in a virtual sensor.
The device has also physical buttons for up and down (and theoretical also the app that can control it) so there is a "position" parameter (number 0-100) that can be read out to indicate the current position.
So my question is, what's the best approach to let the position of the virtual device in domoticz keep in sync with the real position? Because when someone uses the physical buttons on the motor Domoticz should also update. I think this only can be done by using a time script that updates with a certain frequency but can this same virtual device then be used to control the blinds too?
Second question; is there a possibility to combine this data all together in one virtual device? So a position slider, open, stop, close button and a battery status?
The script I have currently (work in progress).
Code: Select all
--[[ Script to control A-OK AM43 Blinds
The needed python3 script can be found here
https://github.com/TheBazeman/A-OK-AM43-Blinds-Drive
The response to "CheckStatus" is
{
"Blinds1": [
{
"battery": 79,
"light": 0,
"macaddr": "02:BE:3A:9E:6E:0E",
"position": 0
}
],
"status": "OK"
}
]]--
return {
on = {
timer = {'every 1 minutes'},
httpResponses = { 'AM43-Blinds_Response' } -- Trigger the handle Json part
},
logging = {
level = domoticz.LOG_DEBUG, -- switch to LOG_ERROR when all OK
marker = 'AM43-Blinds'
},
execute = function(dz, item)
local Action = 'CheckStatus'
local BlindsDeviceBattery = dz.devices(1793) -- IDX number of virtual battery percentage device
local BlindsDeviceLight = dz.devices(1795) -- IDX number of virtual light percentage device
local BlindsDevicePosition = dz.devices(1796) -- IDX number of virtual Position percentage device
local function getBlindsStatus()
local url = 'http://localhost:5000/AM43BlindsAction' ..
"/" .. Action
dz.openURL (
{
url = url,
method = 'GET',
callback = 'AM43-Blinds_Response'
}
)
end
if (item.isHTTPResponse) then
-- local ResultData = item.data
if (item.ok) then
dz.log('HTTPResponse status is ok',dz.LOG_DEBUG)
local BlindsStatus = item.json.Blinds1[1]
if BlindsDeviceBattery then BlindsDeviceBattery.updatePercentage(BlindsStatus.battery) end
if BlindsDeviceLight then BlindsDeviceLight.updatePercentage(BlindsStatus.light) end
if BlindsDevicePosition then BlindsDevicePosition.updatePercentage(BlindsStatus.position) end
-- dz.log('ResultData is ' .. ResultData,dz.LOG_DEBUG)
dz.log('Battery = ' .. BlindsStatus.battery .. '%',dz.LOG_DEBUG)
dz.log('Light = ' .. BlindsStatus.light .. ' ',dz.LOG_DEBUG)
dz.log('macaddr = ' .. BlindsStatus.macaddr .. ' ',dz.LOG_DEBUG)
dz.log('position = ' .. BlindsStatus.position .. ' ',dz.LOG_DEBUG)
end
else
getBlindsStatus()
end
end
}