Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

Question

Posted

Hi,

Does anyone know if it's possible to deactivate a switch by changing the RFProtectionState or by Disabling it using Lua or a VD?

I am trying to set the switch to automatically stop receiving RF activations once a scene has run.

Thanks...

Please login or register to see this attachment.

11 answers to this question

Recommended Posts

  • 0
Posted (edited)

 @Craig  Try this POST request; 

This works for me , but search the forum if you want another solution..

.

To study all commands available :

In empty browser type:   http://<HC-IP>/docs  to look at Fibaro FGHC rest api documentation.

 

Go to devices:  GET device object and find your device id.

Then go to devices: POST Call action and enter deviceID / actionName  / setProtection: and  body with args:

 

 

OFF =

{
  "args": [
    "0","0"
  ]
}

or 

 

ON=

{
  "args": [
    "0","1"
  ]
}    

 

Test POST to check setProtection change.

(see below picture)

 

Download

Please login or register to see this link.

 to get code for all GET -PUT-POST requests for future

projects.

Open new POST request and paste in Request URL from Fibaro FGHC  , looks like 

Please login or register to see this link.

.xx.xx:80/api/devices/162/action/setProtection.

Set Authorization to Basic Auth with :name :password HC2.

Set Body  to args copied from Fibaro FGHC request, set as raw with JSON (application/json) .

(see below picture).

When you are finished press Send (blue) to test and then Code (orange) to copy code for your VD.

Below is an example of Postman POST api. The Postman-Token will be generated by the app so the below script won't work as is..

 

Then:

Create virtual device with two buttons

Set IP adress in Virtual device to 127.0.0.1 with TCP port nr 11111

Paste your code In each button and change args at end to "0","0" =  (OFF)  and "0","1"  = (ON)

 

Example from Postman

POST /api/devices/162/action/setProtection HTTP/1.1
Host: 192.xxx.xx.xxx:80
Content-Type: application/json
Authorization: Basic xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
User-Agent: PostmanRuntime/7.13.0
Accept: */*
Cache-Control: no-cache
Postman-Token: dc1988a3-7df9-4e-b8877-993-ffec3c3f7129,51b33dec-0ce7-4b71-b72f-559cv7-9b6cb4
Host: 192.xxx.xx.xxx:80
accept-encoding: gzip, deflate
content-length: 48
Connection: keep-alive
cache-control: no-cache

{
    "args": [
        "0",
        "1"
    ]
}

 

Please login or register to see this image.

/monthly_2019_06/1722823320_Skjermbilde2019-06-12kl_04_43_38.png.05a014b19f41f8af1f269c237d2f2fab.png" alt="1722823320_Skjermbilde2019-06-12kl_04_43_38.png.05a014b19f41f8af1f269c237d2f2fab.png" />

 

 

Please login or register to see this attachment.

 

 

 

Edited by MARCUSP.I.L
  • 0
Guest dobsovicj
Posted

I would like to ask you what is the reason of this behavior/functionality?

  • 0
Posted (edited)

Hei @dobsovicj, it seem these functions are for limiting the access for the device, no commands from wave or no commands locally(switch).

To be honest i have never used the control protection but i can see where it might be needed.

Edited by MARCUSP.I.L
  • 0
  • Inquirer
  • Posted (edited)

    Hi @MARCUSP.I.L,

     

    Thank you for showing how to do the Post request.. It is very helpful..

     

    I'm finding that copying the Code for my VD results in an error (Screen shots below). I created the VD as suggested setting the IP address in Virtual device to 127.0.0.1 with TCP port 11111 but it doesn't seem to work.

    Also I noticed you have Test showing where as I don't. is this required?

    Can you let me know if I need to change it to another scrip? Not sure why it doesn't work in the VD when it works in Postmaster...

     

    Please login or register to see this attachment.

     

     

     

     

     

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Please login or register to see this attachment.

    Edited by Craig
    • 0
    Posted (edited)

     

    Set "String" tab before pasting in code. Dont use as Lua code..

     

     

    Please login or register to see this image.

    /monthly_2019_06/445404475_Skjermbilde2019-06-13kl_01_58_49.png.feee4420204d018dba372723c8a8d1fa.png" />

    Edited by MARCUSP.I.L
    • 0
  • Inquirer
  • Posted

    Works perfectly.. Thanks again @MARCUSP.I.L

    :)

    • 0
    Posted (edited)

    Good to hear. There are several ways to send Post -Get etc requests, some methods are with shorter coding and some are with debugging etc.

    I am a little new to all of this so i have chosen Postman , 1, because it works and i don't have to search on forum , 2. it's easier to understand compared to many suggestions on the Forum.

    I have also played with the postman app and added Tests in script so i can see results . I would like to find an easy way to change script to Lua so i can insert it in scenes etc..

    Will be looking online for more info on lua api's , let you know if i find a good solution .

    Edited by MARCUSP.I.L
    • 0
    Posted (edited)

    as this is built-in action, you can call it with fibaro:call as well, or api.post('xxxx'),no need to make it such complex.

    It might not always work, because for some devices one need to call it on first slave, some on the "remote control" (afaik like for RollerShutter3), and some just on the particular visible device 

    Edited by tinman
    • 0
  • Inquirer
  • Posted

    Hi @tinman,

    Can you provide an example of the fibaro:call or api.post('XXX') script where this works? I tried previously by was unable to get them to work.

    I was originally trying to get the switch to either change state to Disabled or RFProtected just using a scene but with no luck.

    Thanks...

    • 0
    Posted

    e.g. turn on/of RF protection

     

    Please login or register to see this code.

     

    or turn on/off local protection

     

    Please login or register to see this code.

     

    api.post is just api.post('/devices/xxx/action/setProtection', data), where data is like oyur args with /docs test, so nothing special, just simple syntax

     

    • Like 1
    • 0
    Posted (edited)

    Thanks for info @tinman it looks so much easier compared to my reply, i totally agree that my applied method is over the top and will not always work i.e. . slave -remote etc.

    Just wondering, how did you find your above info?

    I am new to api and find it difficult to sort out info on the forum , so i chose Postman, to at least , to get a better insight into commands

    What i struggle with are the many posts on the forum for scene api's.

    I can't find a clear cut guide to structure , 

    fex snippets from 2 scenes:

     

    Please login or register to see this code.

    or 

    Please login or register to see this code.

    I dont expect to "suddenly" understand the logic of it, but can you recommend a good site to learn more.

     

    Edited by MARCUSP.I.L

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Answer this question...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

    ×
    ×
    • Create New...