Scripts set as a sensor don't work with homekit extension. #600
-
Thanks for the help with the object detection earlier. I've written a script that turns on and off when a person is detected. However if I set the type to sensor, it won't let me use the extension. I am not sure if this is by design or not. |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments
-
If this is a bug, I'd like to attempt to fix it myself if you can point me in the right direction. |
Beta Was this translation helpful? Give feedback.
-
You need to implement binary sensor, not OnOff |
Beta Was this translation helpful? Give feedback.
-
Share the script too please |
Beta Was this translation helpful? Give feedback.
-
EDITED (I am starting to figure some of this stuff out) Here's the script as I currently have it. It still needs some cleaning up. class LivingRoomPeopleSensor implements BinarySensor {
public binaryState = false;
constructor() {
this.listen();
}
async listen() {
const livingRoom = sdk.systemManager.getDeviceByName<ObjectDetector>("Living Room Camera");
if (!livingRoom) {
throw new Error("Device not found!");
}
livingRoom.listen(ScryptedInterface.ObjectDetector, (_, __, data) => {
const results = data as ObjectsDetected;
if (!this.binaryState && results.detections.length > 0) {
for (const result of results.detections) {
if (result.className === 'person') {
this.binaryState = true;
break;
}
}
} else {
if (this.binaryState) {
this.binaryState = false;
}
}
});
}
}
export default LivingRoomPeopleSensor; I still can't get HomeKit to appear in the extensions list though. For example does the script decide that HomeKit is compatible, or does HomeKit decide that the script is compatible. |
Beta Was this translation helpful? Give feedback.
-
I also noticed that if I change the script, the old behavior continues anyways. |
Beta Was this translation helpful? Give feedback.
-
Need to add this at the end
|
Beta Was this translation helpful? Give feedback.
-
Yep that fixed it. There definitely appears to be a potential memory leak with the listener when I modify and rerun the script. Where are listeners for "ScryptedDevice" stored? I found my way to plugin api proxy, but got lost after that, |
Beta Was this translation helpful? Give feedback.
-
Yeah, there's a known leak in scripts. This might fix it but I'll verify later. |
Beta Was this translation helpful? Give feedback.
-
I guess you have to set device.binaryState. I wasn't able to get it to work until I did that. I'll try this for a few days and see how well it works. |
Beta Was this translation helpful? Give feedback.
Need to add this at the end