rytilahti / python-miio

Python library & console tool for controlling Xiaomi smart appliances
https://python-miio.readthedocs.io
GNU General Public License v3.0
3.74k stars 561 forks source link

Philips Eyecare - physical buttons stops working after few days #617

Open pniewiadowski opened 4 years ago

pniewiadowski commented 4 years ago

Hi There,

don't know really where to put this issue, here or in Home Assistant, but let me try to explain and the you can redirect me to appropriate project.

Once the light is hooked up to Home Assistant via the miio integration, after few days, the physical buttons stops working on the device.

So we have two scenarios:

  1. Philips eyecare synced with Mi Home app, works without problem. Both, physical buttons and app control works without problem,
  2. Philips eyecare integrated into Home Assistant, works for 4, 5 days (physcial buttons, Mi Home app control, and via Home Assistant). After 4, 5 days, buttons doesn't react on touch, app control and HA integration works though.

Once I pull out the plug and plugin back again, the device reconnect to network, and buttons work again for few days.

I have run some debug commands and I am not able to spot anything interesting here, but maybe you are. This is what I can see just after reset: PS C:\WINDOWS\system32> mieye --ip=192.168.0.113 --token=xxxxxxxxxx-d INFO:miio.philips_eyecare_cli:Debug mode active DEBUG:miio.philips_eyecare_cli:Connecting to 192.168.0.113 with token xxxxxxxxxx DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b'' DEBUG:miio.device:Got a response: Container: data = Container: data = b'' (total 0) value = b'' (total 0) offset1 = 32 offset2 = 32 length = 0 header = Container: data = b'!1\x00 \x00\x00\x00\x00\x03.\xa0"\x00\x00\x02\xd2' (total 16) value = Container: length = 32 unknown = 0 device_id = unhexlify('032ea022') ts = 1970-01-01 00:12:02 offset1 = 0 offset2 = 16 length = 16 checksum = b'\x8f\x00\xcb\x89]\xe5j\x00\x0e\x8e\xc3\xca\x85\xec\x03\xe2' (total 16) DEBUG:miio.device:Discovered 032ea022 with ts: 1970-01-01 00:12:02, token: b'xxxxxxxxxx' DEBUG:miio.device:192.168.0.113:54321 >>: {'id': 2, 'method': 'get_prop', 'params': ['power', 'bright', 'notifystatus', 'ambstatus', 'ambvalue', 'eyecare', 'scene_num', 'bls', 'dvalue']} DEBUG:miio.device:192.168.0.113:54321 (ts: 1970-01-01 00:12:02, id: 2) << {'result': ['on', 47, 'off', 'on', 1, 'on', 1, 'on', 0], 'id': 2} Power: on Brightness: 47 Eye Fatigue Reminder: False Ambient Light: True Ambient Light Brightness: 1 Eyecare Mode: True Eyecare Scene: 1 Night Light: True Countdown of the delayed turn off: 0 minutes

This is once the button stooped reacting: PS C:\Users\Przemek> mieye --ip=192.168.0.113 --token=xxxxxxxxx -d INFO:miio.philips_eyecare_cli:Debug mode active DEBUG:miio.philips_eyecare_cli:Connecting to 192.168.0.113 with token xxxxxxxxx DEBUG:miio.protocol:Unable to decrypt, returning raw bytes: b'' DEBUG:miio.device:Got a response: Container: data = Container: data = b'' (total 0) value = b'' (total 0) offset1 = 32 offset2 = 32 length = 0 header = Container: data = b'!1\x00 \x00\x00\x00\x00\x03.\xa0"\x00\x04\x8e\xaa' (total 16) value = Container: length = 32 unknown = 0 device_id = unhexlify('032ea022') ts = 1970-01-04 10:57:46 offset1 = 0 offset2 = 16 length = 16 checksum = b'\x8f\x00\xcb\x89]\xe5j\x00\x0e\x8e\xc3\xca\x85\xec\x03\xe2' (total 16) DEBUG:miio.device:Discovered 032ea022 with ts: 1970-01-04 10:57:46, token: b'xxxxxxxxx' DEBUG:miio.device:192.168.0.113:54321 >>: {'id': 2, 'method': 'get_prop', 'params': ['power', 'bright', 'notifystatus', 'ambstatus', 'ambvalue', 'eyecare', 'scene_num', 'bls', 'dvalue']} DEBUG:miio.device:192.168.0.113:54321 (ts: 1970-01-04 10:57:47, id: 2) << {'result': ['off', 50, 'off', 'off', 1, 'on', 1, 'on', 0], 'id': 2} Power: off Brightness: 50 Eye Fatigue Reminder: False Ambient Light: False Ambient Light Brightness: 1 Eyecare Mode: True Eyecare Scene: 1 Night Light: True Countdown of the delayed turn off: 0 minutes

I can try to help with debuging this, but please tell me what else I can do here. I own two of these lights, and both react the same way. I found a guy on the internet, which has same problem as mine.

syssi commented 4 years ago

Do you mean the button of the device itself? What happens after 4-5 days if you remove the integration from HA?

pniewiadowski commented 4 years ago

Yes, I mean the button of the device itself. Any of the buton doesn't react. Well, I didn't think of removing this integration, but le me check and come once the issue occur again. It can take few days :)

pniewiadowski commented 4 years ago

This time issue appeared a bit faster. After few hours. I have removed the integration from HA, but this did not resolve the problem. The other light which is not integrated with HA works as it should.

syssi commented 4 years ago

You should contact the manufacturer of your device because it looks like an firmware issue which cannot be solved here.

pniewiadowski commented 4 years ago

Hmm, so why is that the manufacturer integration (Mi Home app) works, while once I start using python-miio it stops?

syssi commented 4 years ago

What did you mean by:

I have removed the integration from HA, but this did not resolve the problem.

If the issue appears without interaction with 3rd party apps/libraries it should be a hardware/firmware issue of the device itself. Correct me if I'm wrong. :-)

pniewiadowski commented 4 years ago

I thought you want me to remove the integration from HA, once the issue occur again. So I did, and the issue persists.

The other Philips light is sync with Hi Home app, but not with HA and the issue doesn't appear so I think there is something with python-miio.

Hope I am clear now :)

pniewiadowski commented 4 years ago

Hey, I found out this is the same here: https://github.com/syssi/philipslight/issues/25

I can try and help, but need some guidance, what I can check.

maximalexanian commented 4 years ago

The same issue here with two different versions of the lamp. Please let me know if I can help debugging it

Emilv2 commented 4 years ago

Same issue here, when integrated with Home Assistant the physical buttons stop working after a while until the power is turned off (after which it happens again). When it's not connected with Home Assistant this problem does not occur.

I would say that the most logical explanation is that python-miio somehow triggers a bug (or a hidden child lock function?) in the firmware, but maybe we can find a workaround for it?

pniewiadowski commented 4 years ago

Hey, any news about this? I really would like to help, but not sure how.

rytilahti commented 4 years ago

Well, the only real way (in my opinion) to find out is to use the command-line tool (or create a script to do those calls) and find out at which point and at which call it will get stuck.

My intuition agrees with the analysis of @Emilv2 on that regard, but we need to find out what triggers it and then create a workaround for it.

As it does not hit until a few days later, maybe this has something to do with the sequence numbers? So perhaps:

One way to try that out would be to initialize the device with a large sequence number and see what happens when it hits the limit (see https://github.com/rytilahti/python-miio/blob/master/miio/miioprotocol.py#L231).

seafoodrice commented 4 years ago

To refresh the discussion of the defect, I am joining the party and become another additional victim of the issue.

xekil commented 4 years ago

I have exactly the same problem with 3 lamps, it is annoying because my children can no longer use the lamp, you can find a solution? Thanks you

bazuchan commented 4 years ago

A have the same problem with xiaomi zhimi heater and it started after firmware upgrade.

Stupco commented 4 years ago

Same issue with 2x Philips Eyecare lamps, only happened since integrating with HA which is a shame as they are now useless for "dumb" operations (using buttons) which my wife prefers.

Would really like a fix!

Light Xiaomi firmware version: 1.2.8.0026

TigranAsaturjan commented 4 years ago

Same issue, for already a year... all the time i need to get a new token and as soon as it is connected to Home Assistant, buttons on the device are disabled. Please, need a solution for this.

janowakps commented 3 years ago

same issue philips eyecare 2 I used openhab before and everything worked there, after switching to homeassistant the buttons stopped working

syssi commented 3 years ago

@janowakps Are you sure? Can we try to compare both implementations?

Emilv2 commented 3 years ago

This seems to be the https://github.com/openhab/openhab-addons/tree/main/bundles/org.openhab.binding.miio miio OpenHAB implementation.

Edit: Think this is the official one

syssi commented 3 years ago

This issue applies to the sread1, right?

syssi commented 3 years ago

https://github.com/openhab/openhab-addons/blob/main/bundles/org.openhab.binding.miio/src/main/resources/database/philips.light.sread1.json

syssi commented 3 years ago

Implemented properties and commands:

$ cat philips.light.sread1.json | grep property
                                "property": "power",
                                "property": "bright",
                                "property": "ambstatus",
                                "property": "ambvalue",
                                "property": "dvalue",
                                "property": "eyecare",
                                "property": "bl",
$ 
$ cat philips.light.sread1.json | grep command
                                                "command": "set_power",
                                                "command": "set_bright",
                                                "command": "set_power",
                                                "command": "enable_amb",
                                                "command": "set_amb_bright",
                                                "command": "set_eyecare",
                                                "command": "enable_bl",

We are using this properties: https://github.com/rytilahti/python-miio/blob/master/miio/philips_eyecare.py#L122-L132

syssi commented 3 years ago
# python-miio, https://github.com/rytilahti/python-miio/blob/master/miio/philips_eyecare.py#L122-L131
            "power",
            "bright",
            "ambstatus",
            "ambvalue",
            "dvalue",
            "eyecare",
            "bls", // typo?
            "notifystatus", // not requested at openhab
            "scene_num", // not requested at openhab
syssi commented 3 years ago

The mi home plugin (react app) uses this set of properties:

 _miot.Device.getDeviceWifi().callMethod('get_prop', ["power", "bright", "notifystatus", "ambstatus", "ambvalue", "eyecare", "scene_num", "bls", "dvalue"]).then(function (response) {
syssi commented 3 years ago

Anybody here available for an experiment?

  1. Remove this device from HA (comment out the philipslight platform).
  2. Reboot the lamp and test the phyiscal buttons. They should work now.
  3. Install this custom component: https://github.com/syssi/xiaomi_raw/
  4. Configure the lamp as switch (because this component doesn't support a light entity):
switch:
  - platform: xiaomi_miio_raw
    name: Philips Eyecare Lamp
    host: <host>
    token: <token>
    turn_on_command: 'set_power'
    turn_on_parameters: 'on'
    turn_off_command: 'set_power'
    turn_off_parameters: 'off'
    state_property: 'power'
    state_property_getter: 'get_prop'
    state_on_value: 'on'
    state_off_value: 'off'
  1. Restart Home Assistant
  2. You should be able to control the lamp via the switch entity (switch.philips_eyecare_lamp) now. You cannot change the brightness remotely etc. because we are requesting a single property (periodically) now (power) and we use the set_power method only. If the phyiscal buttons are working now and doesn't get stuck we are on the right track. If the phyiscal buttons doesn't work after some time, we can stop this experiment and we don't need to care about the number of requested properties.
janowakps commented 3 years ago

This issue applies to the sread1, right?

yes, everything except this lamp works fine I'm starting an experiment, I'll let you know in a few days

Emilv2 commented 3 years ago

I'll give it a try too

pniewiadowski commented 3 years ago

Trying this one as well. Will see.

pniewiadowski commented 3 years ago

I have two of these lights. I have integrated them and reset the same time 4 days ago. One currently running on the "xiaomi_raw" custom component. another one on Home Assistant integration. The one running "xiaomi_raw" - no issue with buttons but the second one, I have found out today buttons stops working so the "xiaomi_raw" custom component looks promising :)

Continue testing.

janowakps commented 3 years ago

same here, xiaomi_raw 4 days without issue

Emilv2 commented 3 years ago

Yes, seems like you're on the right track @syssi

janowakps commented 3 years ago

@syssi a week has passed and I can confirm with almost 100% certainty that in this configuration with xiaomi_raw it does not block the physical buttons

janowakps commented 3 years ago

@syssi everything still works fine, can we move on? I will be happy to take part in further experiments

syssi commented 3 years ago

The next step is to request a properties periodically as the custom component is doing it. Just add this block to your configuration:

# first try

sensor:
  - platform: xiaomi_miio_raw
    name: Philips Eyecare Lamp Properties
    host: <host>
    token: <token>
    sensor_property: 'bright'
    sensor_unit: '%'
    default_properties_getter: 'get_prop'
    default_properties:
      - power
      - bright
      - notifystatus
      - ambstatus
      - eyecare
      - scene_num
      - bls
      - dvalue

A new sensor (sensor.philips_eyecare_lamp_properties) will be registered. It will show the brightness property as value. The values of the other properties are available as attributes. As soon the device crashs we will reduce the number of properties.

# second try. The set of properties used at openhab. Using "bl" instead of "bls".

sensor:
  - platform: xiaomi_miio_raw
    name: Philips Eyecare Lamp Properties
    host: <host>
    token: <token>
    sensor_property: 'bright'
    sensor_unit: '%'
    default_properties_getter: 'get_prop'
    default_properties:
      - power
      - bright
      - ambstatus
      - ambvalue
      - dvalue
      - eyecare
      - bl
pniewiadowski commented 3 years ago

I was trying to add this today but there seems to be a problem with sensor_unit

Invalid config for [sensor.xiaomi_miio_raw]: [sensor_unit] is an invalid option for [sensor.xiaomi_miio_raw]. Check: sensor.xiaomi_miio_raw->sensor_unit. (See ?, line ?).

syssi commented 3 years ago

I've released a fixed xiaomi_miio_raw version (1.4.0) right now. Please give it a try.

Emilv2 commented 3 years ago

Weird, I didn't have that issue. The buttons just stopped working with the first test values. I will try the second test now.

janowakps commented 3 years ago

@syssi hi so here is my results: first test with bls physical buttons stops responding after just one day second test with bl instead bls 9 days and still everytning works

so i think we have a solution

Emilv2 commented 3 years ago

@syssi hi so here is my results: first test with bls physical buttons stops responding after just one day second test with bl instead bls 9 days and still everytning works

so i think we have a solution

Not yet I think, there are more differences between the two: there's also scene_num and notifystatus. Changing bl into bls does still work after 5 days here.

janowakps commented 3 years ago

there are more differences between the two: there's also scene_num and notifystatus

in fact, I didn't even notice these code differences but still it's been 10 days and I get this data from the integration

model: philips.light.sread1
firmware_version: 1.2.8
hardware_version: ESP8266
properties: eyecare, bright, power, notifystatus, scene_num, dvalue, bl, ambstatus
sensor_property: bright
eyecare: off
bright: 100
power: off
notifystatus: off
scene_num: 1
dvalue: 0
bl: on
unit_of_measurement: %
friendly_name: Philips Eyecare Lamp Properties
icon: mdi:flask-outline

so everything is fine except for the "ambstatus" property which should be turned on now (because I turned it on with the button) but it doesn't show at all

Emilv2 commented 3 years ago

For me it's been six days now with these values in the configuration:

      - power
      - bright
      - ambstatus
      - ambvalue
      - dvalue
      - eyecare
      - bls

ambvalue and ambstatus work for me:

model: philips.light.sread1
firmware_version: 1.2.8
hardware_version: ESP8266
properties: dvalue, ambstatus, power, bls, eyecare, ambvalue, bright
sensor_property: bright
dvalue: 0
ambstatus: off
power: on
bls: on
eyecare: off
ambvalue: 41
bright: 5
unit_of_measurement: %
friendly_name: Philips Eyecare Lamp Properties
icon: mdi:flask-outline

I'll wait a few more days to be 100% sure, but I don't think bls is the issue. Maybe it's a combination that does it?

I'm also not really sure what ambvalue, abmstatus and bls/bl are supposed to represent, they do not seem to change values at all.

syssi commented 3 years ago

I would be happy if everybody could provide a list of good vs. bad properties.

ambvalue: Brightness of the ambient light.
ambstatus: Ambient light on/off
bls/bl: True if the smart night light mode is on.
Emilv2 commented 3 years ago

I was too quick in replying, those properties do indeed what you say and seem to work correctly for me.

Emilv2 commented 3 years ago

I have added notifystatus and the buttons stopped working after 5 days.

janowakps commented 3 years ago

24 days and still everythings works my properties:

      - power
      - bright
      - notifystatus
      - ambstatus
      - eyecare
      - scene_num
      - bl
      - dvalue

as you can see, notifystatus is not causing the problem

syssi commented 3 years ago

I will remove notifystatus from python-miio.

Emilv2 commented 3 years ago

@syssi I think you misread, @janowakps has no issue with notifystatus.

I've been running this configuration for 17 days now and everything still works:

      - power
      - bright
      - ambstatus
      - scene_num
      - ambvalue
      - dvalue
      - eyecare
      - bls

So I'd say bls isn't the problem either. Maybe it's a combination that triggers the issue?

syssi commented 3 years ago

Ups. You are right. In this case the exact solution is still undefined. :-(

ratcashdev commented 3 years ago

Isn't it possible to hook up Arduino studio to this lamp and check the logs/output?