Hi, I am trying to trigger a light turning on from my locally hosted webpage (same ip address that home assistant is hosted on - also listed as a trusted website in the configuration.yaml file), but every POST request fails and returns
XMLHttpRequest cannot load http://ip-address:8123/api/service/light/turn_on. Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://ip-address’ is therefore not allowed access. The response had HTTP status code 404.
I am doing the following to do an ajax POST request:
var data={ "entity_id": "light.hue_white_lamp_1"};
$.ajax({
url: 'http://'+document.URL.split("/")[2]+':8123/api/service/light/turn_on',
dataType:"json",
data:JSON.stringify(data),
contentType:'application/json; charset=utf-8',
type: 'POST',
success: function(res) {
console.log(res);
}
});
I have used ajax GET requests to get the current state of entities, but I have been unable to get the POST requests to work properly. Any help would be appreciated