Skip to content
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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

eric14142004
Copy link

  1. Added motion detector module.
  2. 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.
  3. Currently there are delays for motion detection (same as in HA), not sure how to solve it yet.

@@ -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())) {
Copy link
Owner

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?

Copy link
Author

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.

Copy link
Owner

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...

Copy link
Author

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?

Copy link
Owner

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.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thanks for the advice!

@merdok
Copy link
Owner

merdok commented Aug 5, 2023

Is this something that is ready for merge or not as you closed and reopened the PR multiply times 😅

@eric14142004
Copy link
Author

not ready yet, I found a bug and I thought I fixed it and then back and forth, haha 😅

@merdok
Copy link
Owner

merdok commented Aug 5, 2023

ok 👍

@eric14142004 eric14142004 reopened this Aug 7, 2023
@merdok
Copy link
Owner

merdok commented Aug 7, 2023

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?
I guess that would be the perfect way to make it work...

@eric14142004
Copy link
Author

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? I guess that would be the perfect way to make it 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 😆

@merdok
Copy link
Owner

merdok commented Aug 8, 2023

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

@merdok
Copy link
Owner

merdok commented Dec 4, 2023

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😅
I will try to keep investigate in the direction of events so that we can properly handle that. I tried with the push server above but it seems that only works for the old miio device and not for devices using the miot protocol.
I saw in some documentations that there is a miot sdk from xiaomi, i guess if we could get our hands on that then maybe that would be helpful.

@eric14142004
Copy link
Author

Fair enough! I have been busy recently, I will revisit this PR whenever I have free time!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants