mirror of
https://github.com/nikdoof/hapz2m.git
synced 2026-01-30 06:58:14 +00:00
Add support for motion sensors
There doesn't seem to be any distinction in Z2M between occupancy and motion sensors, but HomeKit has separate types. Most of the sensors are PIR, so they are technically motion sensors instead of occupancy sensors. There are of course _real_ occupancy sensors like mmWave, but we'll deal with those when we get there.
This commit is contained in:
@@ -13,6 +13,7 @@ Currently only supports the types of Zigbee devices I have:
|
|||||||
|
|
||||||
- Climate sensors (temp, humidity)
|
- Climate sensors (temp, humidity)
|
||||||
- Contact sensors
|
- Contact sensors
|
||||||
|
- Motion sensors
|
||||||
- Wall switch
|
- Wall switch
|
||||||
|
|
||||||
If you do use this software, note that it's in development and may contains bugs,
|
If you do use this software, note that it's in development and may contains bugs,
|
||||||
|
|||||||
36
s_motion_sensor.go
Normal file
36
s_motion_sensor.go
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
package hapz2m
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/brutella/hap/accessory"
|
||||||
|
"github.com/brutella/hap/service"
|
||||||
|
)
|
||||||
|
|
||||||
|
// there isn't a distinction between motion and occupancy sensors in z2m,
|
||||||
|
// but most sensors are PIR, so they are technically motion sensors
|
||||||
|
|
||||||
|
func createMotionServices(dev *Device) (byte, []*service.S, []*ExposeMapping, error) {
|
||||||
|
var svcs []*service.S
|
||||||
|
var exposes []*ExposeMapping
|
||||||
|
|
||||||
|
for _, exp := range dev.Definition.Exposes {
|
||||||
|
if exp.Ignored() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case exp.Type == "binary" && exp.Name == "occupancy":
|
||||||
|
exp := exp // create a copy
|
||||||
|
|
||||||
|
s := service.NewMotionSensor()
|
||||||
|
|
||||||
|
svcs = append(svcs, s.S)
|
||||||
|
exposes = append(exposes, &ExposeMapping{&exp, s.MotionDetected.C, nil})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return accessory.TypeSensor, svcs, exposes, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RegisterCreateServiceHandler(createMotionServices)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user