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

Send HTTP-Request via Scene in HC3


Question

Posted (edited)

Hey everybody,

 

i just upgraded from HC2 to HC3 "the hard way"... so I excluded all devices from my HC2 and added them manually to HC3.

All devices are now available again and my next step is to re-build all my virtual devices and scenes. 

 

I had a Scene on my old HC2 that - once it was started manually - sends a simple HTTP request. The old HC2 code - that worked properly - was :

Please login or register to see this code.

 

I tried to copy it into a HC3 scene, but it does not really work.

The "Action" part of my HC3-scene now looks like this:

Please login or register to see this code.

 

The first line is just for test reasons. The scene is running. Device 187 goes from on to off and from off to on when you run the scene.

I also do not get any error messages when the scene is running. But the HTTP request does not work. It should start a AC unit in my sleeping room. But it does not start.

When i copy the URL and open it manuall via browser, the AC unit does react... so the URL itself is correct.

 

Any idea how to make this run the very very very easy way... (It´s to complex for me to put the IP, the Port, the URL in seperate variables and use them later to build this HTTP request using those variables.... I like to have everything in a minimum number of lines :-)

 

Thanks and greetings

Michael

Edited by missenberger
specified "HC3"

11 answers to this question

Recommended Posts

  • 0
Posted

Try this Lua code, it's very basic for a scene

 

Please login or register to see this code.

 

More information about HTTP request with the HC3

Please login or register to see this link.

about it.

  • 0
  • Inquirer
  • Posted

    Thank you Joep,

     

    I will try this later when my son is sleeping.

    I will let you know if it works (i am sure it does :-))

     

    But I checked your block and its phenomenal.

    I will for sure read this the next days. Its very good.. very impressive.

    You surely invested a lot of time for it and its worth every minute!

     

    • 0
    Posted
    24 minutes ago, missenberger said:

    I will let you know if it works (i am sure it does :-))

     

    If there are any problems just ask here, me or someone else from the community will help you.

     

    24 minutes ago, missenberger said:

    But I checked your block and its phenomenal.

    I will for sure read this the next days. Its very good.. very impressive.

     

    Thank you very much for you big compliment. 😎

    • 0
  • Inquirer
  • Posted

    Hello Joep (and of course others reading this),

     

    I just tried the LUA code from above and it´s kind of strange. 

    It does run. I do get status 200 back, so there is something going out reaching my Daikin device.

    But the Daikin device does not react. --> [SCENE205]: {"status":200,"data":"ret=PARAM NG","headers":{"Content-Type":"text/plain","Content-Length":"12"}}

     

    The PARAM NG probably means, that the GET-parameters are somehow wrong. But if I take the URL and cope it to my browsers adress line, it works fine. So the URL with the same parameters work when used from outside my HC3.

     

    Any ideas how to analyse / fix this problem?

    • 0
    Posted

    Try with an encoded url: http://192.168.178.75:80/aircon/set_control_info?pow%3D1%26mode%3D3%26stemp%3D22%26shum%3D0%26f_rate%3DA%26f_dir%3D3

    • 0
  • Inquirer
  • Posted

    This does not work either...  but funny thing: When i start the scene 4 times, I get different responses:
    [08.03.2023] [15:45:33] [DEBUG] [SCENE205]: {"status":200,"data":"ret=PARAM NG","headers":{"Content-Type":"text/plain","Content-Length":"12"}}

    [08.03.2023] [15:45:42] [DEBUG] [SCENE205]: {"status":200,"data":"ret=PARAM NG","headers":{"Content-Type":"text/plain","Content-Length":"12"}}

    [08.03.2023] [15:45:45] [DEBUG] [SCENE205]: {"data":"ret=PARAM NG","status":200,"headers":{"Content-Length":"12","Content-Type":"text/plain"}}

    [08.03.2023] [15:45:50] [DEBUG] [SCENE205]: {"status":200,"headers":{"Content-Type":"text/plain","Content-Length":"12"},"data":"ret=PARAM NG"}

     

    Same thing if I go back to the unencoded URL:
    [08.03.2023] [15:48:16] [DEBUG] [SCENE205]: {"data":"ret=PARAM NG","status":200,"headers":{"Content-Length":"12","Content-Type":"text/plain"}}

    [08.03.2023] [15:48:20] [DEBUG] [SCENE205]: {"headers":{"Content-Type":"text/plain","Content-Length":"12"},"data":"ret=PARAM NG","status":200}

    [08.03.2023] [15:48:33] [DEBUG] [SCENE205]: {"headers":{"Content-Type":"text/plain","Content-Length":"12"},"data":"ret=PARAM NG","status":200}

    [08.03.2023] [15:48:42] [DEBUG] [SCENE205]: {"data":"ret=PARAM NG","headers":{"Content-Length":"12","Content-Type":"text/plain"},"status":200}

     

    Very confusing....

    (at least I still have my HC2 / LOL)

    • 0
    Posted

    It's the same response, the headers parameters are not sorted. 😉

     

    I think you have to fiddle with http headers, like:

    1. headers = { Accept = "text/plain" } or
    2. headers = { Accept = "application/json" }

    Like:

     

    Please login or register to see this code.

     

    • 0
  • Inquirer
  • Posted

    I think I found a solution for it... it seems to work now (will have to test it later in detail). 

     

    The header was not the problem. The problem indeed was the encoding of the URL. I only encoded the GET-Parameters at the end of the URL with a function (i found here on the forum). Once I encode the whole URL with the same function (with http://...) it does not work anymore.

     

    Honestly... I do not really understand what´s happening here... and why. I am not really a programmer. I can read most code and with a good portion of trial and error I can also write code. But who cares :-)I am happy it works now and I can set up the needed scenes for my home automation.

    I will clean up the code tonight or the next 2-3 days, remove my test variables and comments and post the final result here. Maybe somebody else is having the same problem some day.

     

    Thank you Joep for directing me to the encoding topic.
    I would not have made it without your help.

     

     

    • 0
    Posted

    The browser does the encoding for you. Therefore it works in the browser url bar. In my example above I also only the parameters where encoded. I learned that the hard way too. 😀

    • 0
  • Inquirer
  • Posted

    As promised I will post the working solution here... which is 99% your solution, Joep.

    I have seen, that you only encoded the second part of the URL as well. That´s why i said, I do not understand what is happening and why.

    So... to give poetential searchers some more keywords. The following code is the complete action part of a scene, that sends one request to a Daikin Emura Aircondition with WIFI-Module (some people say, it only works for older models and newer ones do not support a RestAPI, but I do not have newer models and cannot test and confirm it. Mine are from 2018 or 2019.)

     

    The parameters at the end of the URL tell the AC-unit what to do (pow=0 means switch off, pow=1 means switch on. Mode=3 is Heating, Mode=4 means cooling. Temp is self explaining I guess. Just search for "set_control_info daikin" at Google.... there is a good, but unofficial documentation on github.

     

    Joep, again thank you very much.

     

    Please login or register to see this code.

     

    • Like 1
    • 0
    Posted
    On 7/3/2023 at 20:31, Joep said:

     

    Si tienes algún problema, pregunta aquí y yo o alguien más de la comunidad te ayudaremos.

     

     

    Muchas gracias por tu gran cumplido.  😎

     

     

    Buenos dias ,alguien sabria como hacer un dispositivo virtual para encender apagar detector moviento camaras dahua, lo consigo haciendo camaras con url modificadas ejemplo 

    http://admin:[email protected]:443/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=true.MUCHAS GRACIAS 

    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...