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

ble-shelly-btn.js missing Shelly.call

Open ronnikn opened this issue 1 year ago • 7 comments

Don't know if it's just me, but couldn't get the script to toggle the relay.

I had to add the following to get it to work.

Shelly.call("Switch.toggle", { id: 0});

ronnikn avatar Jul 30 '23 19:07 ronnikn

@ronnikn hello, can you show where did you put this command, also do you see any errors in the console. What device do you use and which firmware version it is running?

taulfsime avatar Jul 31 '23 05:07 taulfsime

@ronnikn hello, can you show where did you put this command, also do you see any errors in the console. What device do you use and which firmware version it is running?

Hi.

I'm using a Shelly Plus 1PM.

Tried both firmware 0.14.1 and 1.0.0-beta6. Replaced the Mac address with mine. Both firmware didn't work and nothing came up in the log. And no errors when I started the script. (Websocket debug is enabled)

Found out if deleted or // "shelly_blu_name_prefix: "SBBT"," it showed addr, rssi, Button, battery in the log. But didn't toggle the relay.

I'm very noobish at Scripting but couldn't find any code that looked like et should toggle the rely.

Therefor I tried to replace this:

function onButtonPress(BTHparsed) { print("Button pressed, emitting event"); Shelly.emitEvent("BLU_BUTTON", { addr: BTHparsed.addr, rssi: BTHparsed.rssi, Button: BTHparsed.Button, Battery: BTHparsed.Battery,

With this:

function onButtonPress() { print("button pushed"); Shelly.call("Switch.toggle", { id: 0});

And then it worked, but only if I // the line shelly_blu_name_prefix: "SBBT","

You can se the code here https://pastebin.com/49Mkshaw

ronnikn avatar Jul 31 '23 06:07 ronnikn

@ronnikn can I ask you to use https://github.com/ALLTERCO/shelly-script-examples/blob/main/ble-shelly-blu.js script, it should work fine and then you can run this script as well https://github.com/ALLTERCO/shelly-script-examples/blob/main/ble-events-handler.js to handle all ble events and execute automations based on some conditions

taulfsime avatar Aug 03 '23 05:08 taulfsime

I got it to work with ble-shelly-blu.js and ble-events-handler.js. But only if I deleted " mac: "12:34:56:78:90:AB"," under conditions: { even thoug i typed in the buttons mac adress.

Can You tell me what's the idea with the ble-shelly-btn.js if ith dosn't work and why should I use two scripts, when I can settle with only one?

Here is the discription from ble-shelly-btn.js /**

  • This script uses the BLE scan functionality in scripting
  • Selects Shelly BLU Buttons from the aired advertisements, decodes
  • the service data payload and toggles a relay on the device on
  • button push */

It says it should toggle the relay, but no such code is ine this script?

Thats why I added in Shelly.call("Switch.toggle", { id: 0});

ronnikn avatar Aug 04 '23 13:08 ronnikn

The MAC address should contain only lower case letter as it is presented in the data.

The latest ble example is separated in 2 scripts, first because there is a limit on the script length and second because the handler can be used for all types of events, not only for ble and third because the event emitter (ble-Shelly-blu example) can be used only to emit events and then use them in Mqtt or any other device channel.

Don't know what you are exactly doing but the ble-Shelly-btn script works as expected on my device

taulfsime avatar Aug 04 '23 18:08 taulfsime

Thanks for trying to help me undestand this :)

I did type the mac adress in lower case . the example I postet before was from the code in ble-events-handler.js, which actually is in Upper case .. :)

But just to clarify.

If You copy paste code from ble-shelly-btn.js and changes nothing but the mac adress in "addr:" and You have no other script running. You can get the blu button1 to toggle the relay on Your Shelly device??

If You use and have both ble-shelly-blu.js and ble-events-handler.js running and You changed nothing but the mac adress under " conditions:" in the handler it also works for You?

ronnikn avatar Aug 04 '23 19:08 ronnikn

Updated with https://github.com/ALLTERCO/shelly-script-examples/pull/98

taulfsime avatar May 04 '24 16:05 taulfsime