al-one / hass-xiaomi-miot

Automatic integrate all Xiaomi devices to HomeAssistant via miot-spec, support Wi-Fi, BLE, ZigBee devices. 小米米家智能家居设备接入Hass集成
https://miot-spec.com
Apache License 2.0
4.14k stars 578 forks source link

No motion detected since the v0.7.14 update #1441

Open p0macs opened 6 months ago

p0macs commented 6 months ago

Device model / 设备型号

lumi.sensor_motion.v2

Component version / 插件版本

0.7.14

HA core version / HA版本

2023.12.3

Integrated mode / 集成方式

Automatic (自动模式)

The problem / 问题详情

The motion sensors were detected motion before the 0.7.14 update, but they are not detecting anymore.

Entity attributes / 实体属性

Model lumi.sensor_motion.v2 Lan IP MAC address lumi.158d0003e80af4 Entity class LumiBinarySensorEntity Home room OurHome Nappali Miot type urn:miot-spec-v2:device:motion-sensor:0000A014:lumi-v2:2 Motion sensor.motion state false State updater cloud State property motion_sensor.motion_state

Home Assistant Logs / 系统日志

2023-12-19 19:06:22.011 DEBUG (MainThread) [custom_components.xiaomi_miot.binary_sensor] Bejárat(lumi.sensor_motion.v2): Got new state: {'motion_sensor.motion_state': True, 'state_updater': 'cloud'}

p0macs commented 6 months ago

When I enable debug log, I can see messages like: Got new state: {'motion_sensor.motion_state': True, 'state_updater': 'cloud'}

but the sensor state is not updated in HA

p0macs commented 6 months ago

Rolled back to 0.7.13 - and the motion detection works again.

javifly commented 6 months ago

The exact same thing happens to me. In version 0.7.13 working motion sensors. When updating to 0.7.14 they have stopped working. It must be a generalized failure. I went back to 0.7.13 and they are working again. image

javifly commented 6 months ago

Checked 2 times. Version 0.7.13 works perfectly with my motion sensors, version 0.7.14 does not. My sensors are these lumi.sensor_motion.v2 por lumi see the photo:

image
p0macs commented 6 months ago

Looking at the debug logs, I can see this. In version 0.7.14 - about every 15 seconds the following command is executed: 2023-12-19 19:05:07.051 DEBUG (SyncWorker_17) [custom_components.xiaomi_miot.core.xiaomi_cloud] Request miot api: miotspec/prop/get {'params': [{'did': 'lumi.158d0003e809da', 'siid': 2, 'piid': 1}]} result: bytearray(b'{"code":0,"message":"ok","result":[{"did":"lumi.158d0003e809da","iid":"0.2.1","siid":2,"piid":1,"value":true,"code":0,"updateTime":1703009058,"exe_time":0}]}')

In version 0.7.13, about every 15 second the similar command is executed as above, later on followed by a second command: 2023-12-19 22:05:17.269 DEBUG (SyncWorker_25) [custom_components.xiaomi_miot.core.xiaomi_cloud] Request miot api: miotspec/prop/get {'params': [{'did': 'lumi.158d0003e809da', 'siid': 2, 'piid': 1}]} result: bytearray(b'{"code":0,"message":"ok","result":[{"did":"lumi.158d0003e809da","iid":"0.2.1","siid":2,"piid":1,"value":true,"code":0,"updateTime":1703019838,"exe_time":0}]}') 2023-12-19 22:05:17.601 DEBUG (SyncWorker_8) [custom_components.xiaomi_miot.core.xiaomi_cloud] Request miot api: user/get_user_device_data {'did': 'lumi.158d0003e809da', 'key': 'device_log', 'ty pe': 'prop', 'time_start': 1702760717, 'time_end': 1703019977, 'limit': 1} result: bytearray(b'{"code":0,"message":"ok","result":[{"uid":"1857406299","did":"lumi.158d0003e809da","type":"prop","v alue":"[\\"[1703019718,[\\\\\\"event.motion\\\\\\",[]]]\\"]","time":1703019718,"key":"device_log"}]}')

So, in 0.7.13 - two command are executed:

In 0.7.14 the user/get_user_device_data is never executed for this sensor.

p0macs commented 6 months ago

Because of breaking changes in HA 2024.1 - I had to update the integration to 0.7.15 - and my sensors are not detecting motion again. Please, check it. (I cannot use 0.7.13 version anymore, because all the temperature sensors are not working in HA 2024.1)

javifly commented 6 months ago

Indeed, I have upgraded to HA 2024.1 with 0.7.13 and the humidity and temperature sensors have stopped working. I have exactly the same problem as you.

HA 2024.1 + Xiaomi Miot 0.7.13 -> Humidity and temperature sensors not working HA 2024.1 + Xiaomi Miot 0.7.14 -> Motion sensors not working HA 2024.1 + Xiaomi Miot 0.7.15 -> Motion sensors not working

HA 2023.12 + Xiaomi Miot 0.7.13 -> Everything OK

p0macs commented 6 months ago

OK, found a workaround. The only change related to the motion sensor in 0.7.14 (and 0.7.15) was that the lumi.sensor_motion.v2 was added to the MIOT_LOCAL_MODELS collection in the miot_local_devices.py file. Looks like the motion sensor cannot detect motion when handled as a local device, only when it is a cloud device. I made following:

After that, the motion sensor is detecting motions again. No restart is required. I did this for my other motion sensors as well.

If you can edit the configuration.yaml file, it is probably easier to customize the model:

# Customize via device model
xiaomi_miot:
  # https://github.com/al-one/hass-xiaomi-miot/blob/master/custom_components/xiaomi_miot/core/device_customizes.py
  device_customizes:
    lumi.sensor_motion.v2:
      miot_cloud: true

I don't know what was the intention to move this device to the local devices. Of course, it would be better to detect motion without the cloud, but looks like it is not working on this model.

javifly commented 6 months ago

Reading your post I have seen then there is a simple solution and explanation.

I have updated HA to the latest version 2024.1.1 as well as the Xiaomi Miot Auto to version 0.7.15.

HA 2024.1.1 + Xiaomi Miot 0.7.15 -> Motion sensors not working. Humidity and temperature sensors working OK

The motion sensors are not working, but by performing this configuration they have all started working again:

  1. on the Xaiomi Miot Auto integration clicked the ADD ENTRY
  2. selected the "Customizing device (自定义设备)"
  3. selected the motion sensor from the dropdown-list -> lumi.sensor_motion.v2
  4. from the Customize options checked the miot_cloud
  5. clicked the Submit button

image

image

image

javifly commented 6 months ago

I think this is the perfect solution, as it allows you to upgrade HA and Xiaomi Miot Auto to new versions and have your motion sensors always working.

It is also a solution that is applied in 10 seconds for all your sensors and you don't need to know programming since it is applied at the click of a mouse.

javifly commented 6 months ago

Once configured, if you click on configure again, you can no longer change the parameters, you can only view them.

image

If we want to make any changes we must delete and create it from 0.

javifly commented 5 months ago

This same configuration can be used to force a device to always work under the cloud and not to use it on the local network. For example, if you have a sensor hanging from another network that is not the same as the one in which home asisstant is located and you want to integrate it, you can choose that a certain entity is always used with the cloud.

image
alex-dokienko commented 5 months ago

I also experience same issue when no motion detected, once I switch to cloud configuration, then motion sensor is working but other 2 seonsors which worked on local (no duration and illimination) now not working local

image

cloud

image

Does anyone else experience same behavior? I don't know what version of miiot I'm using but I installed HA 2024.1.6 last week, so I'd imagine it's latest versions.

javifly commented 5 months ago

have you configured only the motion sensor in cloud leaving the rest in local? or did you switch all of them to cloud?

alex-dokienko commented 5 months ago

I just reconfigured this one device to use cloud config, are you saying I need to reconfigure only one motion sensor to be cloud and other two sensors should stay local? sorry I'm new in HA and yes some discussion in this thread with configurations examples wasn't very clear for me.

javifly commented 5 months ago

Exactly, first you configure the normal application in automatic to be able to work in cloud and local. and then look at my post and just add to the motion sensor the feature that only that sensor works in cloud leaving the rest to work automatically.

alex-dokienko commented 5 months ago

Thank you @javifly, used customize option and now it's working, but lost no duration sensor for one of my devices, but that's story for another time, thank you for help and quick assistance

javifly commented 4 months ago

I use a customization for a few devices to work from the cloud, but it doesn't affect the rest.

image