-
-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xiaomi Human Body Movement Sensor #511
base: main
Are you sure you want to change the base?
Conversation
eric14142004
commented
Aug 4, 2023
- Added motion detector module.
- Added a handler for the lumi motion sensor. This device always return value:true and won't update to reflect whether motion was detected. This issue was discussed in Issue #70.
- Currently there are delays for motion detection (same as in HA), not sure how to solve it yet.
lib/protocol/MiotDevice.js
Outdated
@@ -1327,13 +1328,28 @@ class MiotDevice extends EventEmitter { | |||
// updates the property value with the value retrieved from the device | |||
_updatePropertyValueFromDevice(result, propName, response) { | |||
if (this._isResponseValid(response)) { | |||
if (LUMI_MOTION_MODELS.includes(this.getModel())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why special handling for the device needs to be done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is needed because this device will always return "value":true regardless of the motion detect status
if motion detection: false
curl: miot cloud get-props '[{"did":"lumi.XXXX","siid":2,"piid":1}]'
return: [{"did":"lumi.XXXX","iid":"0.2.1","siid":2,"piid":1,"value":true,"code":0,"updateTime":1691225681,"exe_time":0}]
if motion detection: true
curl: miot cloud get-props '[{"did":"lumi.XXXX","siid":2,"piid":1}]'
return: [{"did":"lumi.XXXX","iid":"0.2.1","siid":2,"piid":1,"value":true,"code":0,"updateTime":1691226209,"exe_time":0}]
the only value that changes is the "updateTime", but it also has some special rules about when exactly the value updateTime will be updated, so I am still working on it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should in that case register for specific property changes and handle that in the device class itself. It is a little bit odd to do it in a central generic place...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, I might need to change the MiotProperty then to catch the "updateTime" tho, as I don't see it pass down to specific device handling. Or do you have a suggestion of any other ways to achieve it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, i know what you mean now. "updateTime" is only there is the response, after processing that information is lost. I am thinking if maybe to offer an event would be a better solution,. Interested devices could then register for that event and do extra data processing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 thanks for the advice!
Is this something that is ready for merge or not as you closed and reopened the PR multiply times 😅 |
not ready yet, I found a bug and I thought I fixed it and then back and forth, haha 😅 |
ok 👍 |
Thanks for the update! That already looks much more cleaner. BTW, the device also has the motion-detected event, and I guess that would be the most correct way to go. Unfortunately I did not manage to get that to work, do you maybe have any info about the events and how to get them to work? |
Sorry, I also have no clue how events work. But I am guessing they managed to make it work in HA, so I will try to explore that a bit more when I have time this weekend 😆 |
I guess this is how events work in HA. A push server would be needed to get them to work: https://github.com/rytilahti/python-miio/tree/master/miio/push_server |
Hi, i have added the motion sensor module in the recent update, but i skipped the device implementation as that kind of does not satisfy me😅 |
Fair enough! I have been busy recently, I will revisit this PR whenever I have free time! |