A-OK AM43 Blinds motor

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
roblom
Posts: 402
Joined: Wednesday 26 February 2014 15:28
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: the Netherlands
Contact:

A-OK AM43 Blinds motor

Post by roblom »

Recently I bought a A-OK AM43 Blinds motor which has arrived. I installed it and works great.
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"
The "Action" options are
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
}
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: A-OK AM43 Blinds motor

Post by waaren »

roblom wrote: Tuesday 14 July 2020 23:02 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?
In theory yes but it is quite challenging to keep the virtual blind aligned with the physical blind if you need to ensure it will stil work if the two modes of operation can be (almost) simultaneously.
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?
A blind percentage could do that with the exception of battery status
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
jon205
Posts: 39
Joined: Monday 05 November 2018 16:17
Target OS: Linux
Domoticz version: 2022.2
Location: @home
Contact:

Re: A-OK AM43 Blinds motor

Post by jon205 »

Any news on this Roblom?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest