• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Http sender 3th party

    How-To
    4
    12
    3.6k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      Mark
      last edited by

      Dear Phil,

      Thank you very much! The 2nd option works fine for me. It is now very easy to switch multiple points in domoticz.

      Thanks again!

      1 Reply Last reply Reply Quote 0
      • M
        Mark
        last edited by

        Here is an update of the above script. I have set the ID number of the lighting fixed.
        0_1523291097260_c2f0095c-5cb9-4205-a10f-d1e3299315ad-image.png

        I have slightly modified the script so that it can also be used to dim lighting.
        0_1523291028712_7b69447d-3025-42e4-aa59-033bae0d0aa7-image.png

        1 Reply Last reply Reply Quote 0
        • phildunlapP
          phildunlap
          last edited by

          Awesome! Glad you were able to do what you needed to!

          M 1 Reply Last reply Reply Quote 0
          • C
            cor
            last edited by

            Dear Phil and Mark,
            Dont know if you're still folowing this, trying to use your solution, and in the process maybe skipping a step, but i dont know yava script.

            I am using solution 2, the point i am referencing has state 1 or 2., trying to ad an extra variable. This is wat i got; is this a posibylity?

            var pointinfo = /(1|2)/.exec(p20.value);
            var info = "off"
            if (pointinfo = 1)
            var info = "on"
            if (pointinfo = 2)
            {
            var headers = {"Host":"192.168.178.12:8080"};
            var parameters = {
            "type":"command",
            "param":"switchlight",
            "idx":"7",
            "switchcmd": info
            };
            HttpBuilder.get("http://192.168.178.12:8080/json.htm", headers, parameters).resp(function(statusCode, headers, content) {
            // handle the response, maybe return "Success!" or whatever
            }).err(function(statusCode, headers, content) {
            // handle error responses
            }).execute();

            Hope to hear from you

            1 Reply Last reply Reply Quote 0
            • phildunlapP
              phildunlap
              last edited by

              Hi cor, welcome to the forum!

              It looks as though the first few lines of your script could be touched up. A single = is the assignment operator, where == is a comparison operator. Also I realize you are taking the regex from the previous examples, but if you just need to see if the value is 0 or 1 you can simply compare upon the value itself, like,

              var info = p20.value == 1 ? "off" : "on"; //set the value off only if p20.value is 1
              

              or if you don't want anything but a 1 to mean 'on' you could do,

              var info;
              if(p20.value == 1)
                info = "off";
              else if(p20.value == 2)
                info = "on";
              else
                throw "Unusable value in p20: " + p20.value; //cause a script error since bad input
              

              Everything else seems like it'd be the same as in Mark's usage.

              1 Reply Last reply Reply Quote 0
              • C
                cor
                last edited by

                thank you! wil play with it some more!

                1 Reply Last reply Reply Quote 0
                • M
                  Mark @phildunlap
                  last edited by

                  @phildunlap 2 years ago I received a script from you for switching lighting. I now want to use this for another command. I would like to execute the following command:

                  • http://192.168.178.66/relay/1?turn=on
                  • http://192.168.178.66/relay/1?turn=off

                  Can you help me with the right script?

                  1 Reply Last reply Reply Quote 0
                  • MattFoxM
                    MattFox
                    last edited by

                    I may be able to be of some assistance here...
                    Alter your url to be

                    http://192.168.178.66/relay/1
                    

                    And amend your parameters to have the 'turn' parameter

                    var parameters = {
                      "turn": relay.value==1?'on':'off'
                    }
                    

                    I'm not quite sure if you're using the exact same configuration as before with a virtual datasource point but in a nutshell, calling the query like that will give you your toggle command.
                    If however you want to keep the code consistent, just have 100 for on and 0 for off, this way you can recycle the old code and just amend your URL.

                    Fox

                    Do not follow where the path may lead; go instead where there is no path.
                    And leave a trail - Muriel Strode

                    M 1 Reply Last reply Reply Quote 0
                    • M
                      Mark @MattFox
                      last edited by

                      @mattfox said in Http sender 3th party:

                      var parameters = {
                      "turn": relay.value==1?'on':'off'

                      I have just tried the following script but unfortunately this does not work.

                      0_1581337538394_50387a64-d6fc-441a-9c43-29106808e16d-image.png

                      1 Reply Last reply Reply Quote 0
                      • MattFoxM
                        MattFox
                        last edited by MattFox

                        The url is inside the get call. Not the host part of the header.
                        You want to 'get' calll the page, you're calling the 192.168... at the root level of the server, not the relay page.

                        Secondly, your context point var is not used to correlate to being on or off. Since the point is an alphanumeric and not a numeric/binary, your parameters should be:

                        var parameters = {
                          "turn": info
                        }
                        

                        You're calling a script but I think you are unaware of how everything works. I take it it has been a long time since you've done this.

                        Do not follow where the path may lead; go instead where there is no path.
                        And leave a trail - Muriel Strode

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post