Http sender 3th party
-
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!
-
Here is an update of the above script. I have set the ID number of the lighting fixed.
I have slightly modified the script so that it can also be used to dim lighting.
-
Awesome! Glad you were able to do what you needed to!
-
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
-
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.
-
thank you! wil play with it some more!
-
@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:
Can you help me with the right script?
-
I may be able to be of some assistance here...
Alter your url to behttp://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
-
@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.
-
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.