renssies / homebridge-am43-blinds

A homebridge plugin to control the AM43 based blind motors in HomeKit
MIT License
18 stars 6 forks source link

Overcomming 5 min motor autoshutdown #11

Closed bpelech closed 3 years ago

bpelech commented 4 years ago

Hi guys, I have huge window, more than 2m height. It takes about 18min to fully open or close the blinds. I discovered that there is some kind of auto shutdown timer inside the motor that shuts the motor after 5 mins. Therefore when I want to fully open or close the blinds I have to manually press up or down 3 times. I was hoping to overcome this auto shutdown via this plugin. Something like checking whether motor is still running and whether it’s inside the min and max possition.

Fyi, I bet you’ll be interested that this plugin works in the following setup:

bpelech commented 3 years ago

I went back and forth with my setups and currently I'm running dedicated homebridge from rpi (just a clean HB rpi setup with installed bluetooth libraries as described in the readme.md and installed this plugin from plugin screen inside the HB web ui). So far I am playing with a script to have periodic control over the blinds.

Idea is:

Sample of the control curl command: curl -s -X PUT http://homebridge.local:55555/characteristics --data {"characteristics":[{"aid":2,"iid":10,"value":61,"status":0}]} --header "Content-Type:Application/json" --header "authorization: 111-11-111"

Reading the current position: curl -s -X GET http://homebridge.local:55555/characteristics?id=2.11

Problem is, that I don't know which iid is the correct one to use. When calling the command: curl -s -X GET http://homebridge.local:55555/characteristics?id=2.$j in a loop where $j is 0-100 I get these readings: {"characteristics":[{"aid":2,"iid":3,"value":"renssies"}]} {"characteristics":[{"aid":2,"iid":4,"value":"AM43"}]} {"characteristics":[{"aid":2,"iid":5,"value":"AM43 Blind Motor"}]} {"characteristics":[{"aid":2,"iid":6,"value":"xxxxxxxxxxxx"}]} {"characteristics":[{"aid":2,"iid":7,"value":"0.3.0"}]} {"characteristics":[{"aid":2,"iid":9,"value":55}]} {"characteristics":[{"aid":2,"iid":10,"value":2}]} {"characteristics":[{"aid":2,"iid":11,"value":55}]} {"characteristics":[{"aid":2,"iid":14,"value":0}]} {"characteristics":[{"aid":2,"iid":15,"value":100}]} {"characteristics":[{"aid":2,"iid":16,"value":0}]} I assume that iid 9 or 11 is the current position and iid 10 or 14 are target positions. Iid 15 is the battery charge value.

Few months ago when I start playing with this script it kinda worked (but I had other issues with the plugin so I postpone playing with the script to switch to fully dedicated rpi HB). However now with dedicated clean setup I can't make the script to control the blinds.

Anyone to help?

bpelech commented 3 years ago

Found this command to check the iid setup: curl -X PUT http://homebridge.local:55555/accessories --header "Content-Type:Application/json" --header "authorization: 111-11-111"

Output is this: { "accessories":[ { "aid":1, "services":[ { "type":"3E", "iid":1, "characteristics":[ { "type":"14", "iid":2, "perms":[ "pw" ], "description":"Identify", "format":"bool" }, { "type":"20", "iid":3, "value":"homebridge.io", "perms":[ "pr" ], "description":"Manufacturer", "format":"string", "maxLen":64 }, { "type":"21", "iid":4, "value":"homebridge", "perms":[ "pr" ], "description":"Model", "format":"string", "maxLen":64 }, { "type":"23", "iid":5, "value":"Homebridge xxxx", "perms":[ "pr" ], "description":"Name", "format":"string", "maxLen":64 }, { "type":"30", "iid":6, "value":"11:11:11:11:11:11", "perms":[ "pr" ], "description":"Serial Number", "format":"string", "maxLen":64 }, { "type":"52", "iid":7, "value":"1.3.4", "perms":[ "pr" ], "description":"Firmware Revision", "format":"string" } ] }, { "type":"A2", "iid":2000000008, "characteristics":[ { "type":"37", "iid":9, "value":"1.1.0", "perms":[ "pr" ], "description":"Version", "format":"string", "maxLen":64 } ] } ] }, { "aid":2, "services":[ { "type":"3E", "iid":1, "characteristics":[ { "type":"14", "iid":2, "perms":[ "pw" ], "description":"Identify", "format":"bool" }, { "type":"20", "iid":3, "value":"renssies", "perms":[ "pr" ], "description":"Manufacturer", "format":"string", "maxLen":64 }, { "type":"21", "iid":4, "value":"AM43", "perms":[ "pr" ], "description":"Model", "format":"string", "maxLen":64 }, { "type":"23", "iid":5, "value":"AM43 Blind Motor", "perms":[ "pr" ], "description":"Name", "format":"string", "maxLen":64 }, { "type":"30", "iid":6, "value":"xxxxxxxxxxx", "perms":[ "pr" ], "description":"Serial Number", "format":"string", "maxLen":64 }, { "type":"52", "iid":7, "value":"0.3.0", "perms":[ "pr" ], "description":"Firmware Revision", "format":"string" } ] }, { "type":"8C", "iid":8, "characteristics":[ { "type":"6F", "iid":12, "perms":[ "pw" ], "description":"Hold Position", "format":"bool" }, { "type":"6D", "iid":9, "value":100, "perms":[ "ev", "pr" ], "description":"Current Position", "format":"uint8", "unit":"percentage", "minValue":0, "maxValue":100, "minStep":1 }, { "type":"72", "iid":10, "value":2, "perms":[ "ev", "pr" ], "description":"Position State", "format":"uint8", "minValue":0, "maxValue":2, "minStep":1, "valid-values":[ 0, 1, 2 ] }, { "type":"7C", "iid":11, "value":100, "perms":[ "ev", "pr", "pw" ], "description":"Target Position", "format":"uint8", "unit":"percentage", "minValue":0, "maxValue":100, "minStep":1 } ] }, { "type":"96", "iid":13, "characteristics":[ { "type":"8F", "iid":16, "value":0, "perms":[ "ev", "pr" ], "description":"Charging State", "format":"uint8", "minValue":0, "maxValue":2, "minStep":1, "valid-values":[ 0, 1, 2 ] }, { "type":"79", "iid":14, "value":0, "perms":[ "ev", "pr" ], "description":"Status Low Battery", "format":"uint8", "minValue":0, "maxValue":1, "minStep":1, "valid-values":[ 0, 1 ] }, { "type":"68", "iid":15, "value":100, "perms":[ "ev", "pr" ], "description":"Battery Level", "format":"uint8", "unit":"percentage", "minValue":0, "maxValue":100, "minStep":1 } ] } ] } ] }

bpelech commented 3 years ago

Hi guys, I figured it out.

I ended up using this plugin for it's super easy logic: https://github.com/cr3ative/homebridge-shell-switch In the config you just set it up this way:

{
            "accessory": "ShellSwitch",
            "name": "Blinds Up Switch",
            "onCmd": "/var/lib/homebridge/control/blinds_up.sh",
            "offCmd": "/var/lib/homebridge/control/blinds_down.sh"
 }

Plugin is calling two from these three scripts:

blinds_up.sh and blinds_down.sh just call the change_blinds.sh and set the parameter to 100 or 0 (target position).

blinds_up.sh:

#!/bin/bash
/bin/bash /var/lib/homebridge/control/change_blinds.sh 100

blinds_down.sh:

#!/bin/bash
/bin/bash /var/lib/homebridge/control/change_blinds.sh 0

change_blinds.sh:

#!/bin/bash
aid=2
CURRENT_POSITION_iid=9
TARGET_POSITION_iid=11
IP=192.168.0.109
PORT=55555
KEY=111-11-111
TARGET_POSITION=$1
CURRENT_POSITION=`curl -s -X GET http://$IP:$PORT/characteristics?id=$aid.$CURRENT_POSITION_iid | jq '..|.value?|select(. != null)'`
RUN_EVERY_SECONDS=10

echo "Current position: "$CURRENT_POSITION
echo "Target position: "$TARGET_POSITION

if ! [[ $TARGET_POSITION =~ ^[0-9]+$ ]] ; then
  echo "error: Target position is not a number!!!" >&2; exit 1
fi

while [ "$CURRENT_POSITION" != "$TARGET_POSITION" ]; do
  curl -s -X PUT http://$IP:$PORT/characteristics --data "{\"characteristics\":[{\"aid\":$aid,\"iid\":$TARGET_POSITION_iid,\"value\":$TARGET_POSITION}]}" --header "Content-Type:Application/json" --header "authorization: $KEY"
  echo "Calling curl to target position: "$TARGET_POSITION
  sleep $RUN_EVERY_SECONDS
  CURRENT_POSITION=`curl -s -X GET http://$IP:$PORT/characteristics?id=$aid.$CURRENT_POSITION_iid | jq '..|.value?|select(. != null)'`
  echo "Current position: "$CURRENT_POSITION
done

exit 0

Side notes:

Huge thanks to @renssies and his effort with this plugin! 💯💯💯

bpelech commented 3 years ago

I've put the scripts and manual to the github and this issue can be closed. Once again, thank you @renssies for great work! https://github.com/bpelech/homebridge-am43-blinds-script-control