-
Autor
I have a device on my network that allows me to turn it on and off via a web service and I would like to do that when the power reading on the shelly reaches zero. My issue is I keep getting an invalid request from the Shelly.call command. I was hoping someone could give me a suggestion.
I was able to get a web call to work in Postman and also in Home Assistant using these parameters.
Code
url: "http://<INTERNAL_IP>/php/controls.php"
method: POST
payload: "makeup=false&filtration=false&iaq=false&whf=false&cooling=false&heating=false&heater=true&manual=false"
content_type: "application/x-www-form-urlencoded"
But when I translated that to a Shelly script I cannot seam to get it to work. Here is the script and output.
Code
let makeupAirStatus = false;
Shelly.addEventHandler(
function(eventInfo, ud){
if(eventInfo.info.event == "power_update") {
if(eventInfo.info.apower > 1 && !makeupAirStatus) {
print("Makeup Air On");
print('Power: ' + eventInfo.info.apower);
makeupAirStatus = true;
updateMakeupAirStatus("true");
} else if(eventInfo.info.apower < 1 && makeupAirStatus){
makeupAirStatus = false;
print("Makeup Air Off");
updateMakeupAirStatus("false");
}
}
},
null
);
function updateMakeupAirStatus(status) {
let body = "makeup=" + status + "&filtration=false&iaq=false&whf=false&cooling=false&heating=false&heater=true&manual=false";
let parms = {
"url": "http://<INTERNAL_IP>/php/controls.php",
"Content-Type":"application/x-www-form-urlencoded",
"body": body
};
print(JSON.stringify(parms));
Shelly.call(
"HTTP.POST",
parms,
function (response) {
print("processing response");
if (response && response.code && response.code === 200) {
print("response.code : ", response.code);
print(JSON.stringify(response.body));
//Shelly.emitEvent("HTTP-result", response.body);
} else {
print("Error: HTTP request failed.");
print("response.code : ", JSON.stringify(response));
}
}
);
}
Alles anzeigen
********** Output ************
Code
Makeup Air On
Power: 13
{"url":"http://<INTERNAL_IP>/php/controls.php","Content-Type":"application/x-www-form-urlencoded","body":"makeup=true&filtration
=false&iaq=false&whf=false&cooling=false&heating=false&heater=true&manual=false"}
processing response
response.code : 200
"\n\n\nInvalid request."
If anyone can offer any insight/help it would be most appreciated.