Skip to content

Instantly share code, notes, and snippets.

@SliX185
Created December 25, 2024 20:31
Show Gist options
  • Save SliX185/ec97073dffdec944539f4962bf47b013 to your computer and use it in GitHub Desktop.
Save SliX185/ec97073dffdec944539f4962bf47b013 to your computer and use it in GitHub Desktop.
send request Hue APIv2
// Erstellung hue-application-key:
// https://developers.meethue.com/develop/hue-entertainment/hue-entertainment-api/#getting-started-with-streaming-api
const axios = require('axios');
// Konfiguration
const HUE_IP = 'XXX.XXX.XXX.XXX';
const HUE_APP_KEY = 'XXX';
const HUE_BEHAVIOR_INSTANCE_ID = 'z.B: 60c1xxxx-8xx6-4xx3-be62-eexxx5ddb41e' // Unter https://HUE_IP/clip/v2/resource/behavior_instance herauszufinden (z.B mit Programm Postman)
const URLAUB_DP = 'Datenpunkt um Trigger auszulösen';
// Logging
const logging = true;
// URL und Header-Parameter für Requests
const baseUrl = `https://${HUE_IP}/clip/v2/resource/behavior_instance/${HUE_BEHAVIOR_INSTANCE_ID}`;
const headers = {
'hue-application-key': HUE_APP_KEY,
};
// Subscribe Datenpunkt Urlaub/Feiertag | Wenn URLAUB_DP = true => Hue Automation = false
on({ id: URLAUB_DP, change: 'ne' }, function (obj) {
setEnabledState(!obj.state.val);
});
// Funktion, um den Status zu setzen
async function setEnabledState(value) {
const body = { enabled: value };
try {
const response = await axios.put(baseUrl, body, { headers: headers, httpsAgent: new (require('https').Agent)({ rejectUnauthorized: false }) });
if (logging) console.log(`Status "${value}" erfolgreich gesetzt:`);
} catch (error) {
console.warn(`Fehler beim Senden der Anfrage: ${error.message}`);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment