@michihorn schon mal dran gedacht, die devices als Listen zu definieren und dann über die einzelnen elemente der Liste zu loopen?
// nicht so
const id_Michi = "tr-064.0.devices.S20-FE-von-Michael"
const id_Heike = "tr-064.0.devices.S20-FE-von-Heike"
const id_Noel = "tr-064.0.devices.IPhone-Noel"
on({ id: id_Michi, change: 'any', val: false }, function (dp) {
setState(id_AWMichi, false)
if (dp.state.val == true) {
setState(id_AWMichi, true)
}
});
on({ id: id_Heike, change: 'any', val: false }, function (dp) {
setState(id_AWStute, false)
if (dp.state.val == true) {
setState(id_AWStute, true)
}
});
on({ id: id_Noel, change: 'any', val: false }, function (dp) {
setState(id_AWNoel, false)
if (dp.state.val == true) {
setState(id_AWNoel, true)
}
});
// sondern so
var deviceList = [
{ device: "tr-064.0.devices.Michael-Handy", user: "Michael", type: "tr-064" },
{ device: "tr-064.0.devices.Heike-Handy", user: "Heike", type: "tr-064" },
{ device: "tr-064.0.devices.IPhone-Noel", user: "Noel", type: "tr-064" }
];
for (var i = 0; i < deviceList.length; i++) {
if deviceList[i].type == "tr-064" {
on({ id: deviceList[i].device, change: "any", val: false }, function (dp) {
setState(id_AWNoel, false)
if (dp.state.val == true) {
setState(id_AWNoel, true)
}
});
}
};
Hat den Vorteil, dass du den Code nicht ändern musst, falls mal ein Handy dazukommt.