/* Configure your list of controls and their URIs */
let controls = [{
label: 'Bedroom 1',
uri: 'bedroom1',
},
{
label: 'Bedroom 2',
uri: 'bedroom2'
},
{
label: 'Bathroom',
uri: 'bathroom'
},
{
label: 'Kitchen',
uri: 'kitchen'
}
];
const controlsContainer = document.getElementById('controls');
/* Loop through each control and create a button element */
controls.forEach(function(control, index) {
let button = document.createElement('li');
button.appendChild(document.createTextNode(control.label));
button.className = 'grid-cell';
button.setAttribute('role', 'button');
button.addEventListener('click', function() {
callWebHook(control.uri);
})
controlsContainer.appendChild(button);
});
/* Calls a webhook with a provided URI */
function callWebHook(uri) {
fetch(`http://server_ip/token/blah/${uri}=1`);
}