shelly-script-examples icon indicating copy to clipboard operation
shelly-script-examples copied to clipboard

Cover.stop is not working when invoked from a BT event

Open rafiw opened this issue 2 years ago • 0 comments

Hey, I have a problem using a script in shellyPlus25PM with Shelly DW BLU. I'm trying to write a script that will stops the cover in case there is something blocking it. The way I did it is by putting the door sensor between the cover lowest shutter steps and when an event from the sensor detected by the shelly2PM it will check the position and stop if the cover is not near the bottom. I used this script to decode the events https://github.com/.../shelly.../blob/main/ble-shelly-dw.js and added this function to invoke when close happens. I have two problems:

  1. state is stopped although cover is not stopped.
  2. the cover doesn't stop while checking this code many times it only stopped twice!! full logs here https://pastebin.com/aXjXk8Mj https://pastebin.com/zAVXhRvk device data https://pastebin.com/fx9e8bvX

also tried using Shelly.call("HTTP.GET",...) calling stop, but it also didn't respond

this is the function I wrote

var STOP_POSITION = 35;
function triggerClose() {
  var should_touch_ground = 42;
  var state = Shelly.getComponentStatus("cover:0").state
  if (Shelly.getComponentConfig("sys").device.profile !== "cover" ||
	  state === "stopped") {
	  //return;  BUG state is "stopped" although it's moving;
  }

  var current_pos = Shelly.getComponentStatus("cover:0").current_pos;
  console.log("current pos:"+ current_pos+" should:" + should_touch_ground);
  if (current_pos !== undefined && current_pos !== null && current_pos > STOP_POSITION) {
	  Shelly.call("Cover.Stop", {'id': 0});
  }
}

To Reproduce Steps to reproduce the behavior: get a shelly2plus and shelly DW sensor. add the script attached below. while the cover moved down stop in with you hand to trigger an event.

Expected behavior I expect the cover to stop but it doesn't. also I expect the state not to be stopped while the function runs.

Screenshots here is how I put the sensor in the cover https://ibb.co/jVgztkT

Device and script details (please complete the following information):

  • Firmware version 20231018-132958/1.0.7-beta2-g5d80465
  • Link to the script you were running https://pastebin.com/uZcKY3GL
  • If any external dependencies are necessary No

rafiw avatar Oct 28 '23 21:10 rafiw