philipslight icon indicating copy to clipboard operation
philipslight copied to clipboard

Improve philips.light.moonlight support

Open AsWaM opened this issue 5 years ago • 47 comments

Hello,

I have the following message in home assistant:

Unsupported device found! Please create an issue at https://github.com/syssi/philipslight/issues and provide the following data: philips.light.moonlight

I am a developper myself, and could help if needed.

Alex

AsWaM avatar Dec 16 '18 11:12 AsWaM

Please update the custom component to the development version (branch: develop)! The device is already supported.

syssi avatar Dec 16 '18 11:12 syssi

Hello, thanks for your help. I am noob to python and virtual envs, (i am .NET dev), so I don't know how to install the dev branch.

Went in my virtual env, ran this pip3 install https://github.com/syssi/philipslight/archive/develop.zip the result was Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple Collecting https://github.com/syssi/philipslight/archive/develop.zip Downloading https://github.com/syssi/philipslight/archive/develop.zip \ 102kB 1.0MB/s Complete output from command python setup.py egg_info: Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib/python3.5/tokenize.py", line 454, in open buffer = _builtin_open(filename, 'rb') FileNotFoundError: [Errno 2] No such file or directory: '/tmp/pip-req-build-wuct2s7c/setup.py' Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-req-build-wuct2s7c/

So I tried with (homeassistant) root@DietPi:/srv/homeassistant# python3 -m pip install https://github.com/syssi/philipslight/archive/develop.zip

Same result. What am I doing wrong?

I am sure this is a stupid question but I can't find the answer myself :(

AsWaM avatar Dec 23 '18 19:12 AsWaM

I tried to find something to replace it in the libs, but looks like i miss some preprocessing or whatsoever (the files are splitted by type, unlike in the repository) (homeassistant) root@DietPi:/srv/homeassistant/lib/python3.5/site-packages/miio# dir airconditioningcompanion.py device.py __pycache__ airfresh.py discovery.py tests airhumidifier.py exceptions.py updater.py airpurifier.py extract_tokens.py utils.py airqualitymonitor.py fan.py vacuum_cli.py ceil_cli.py __init__.py vacuumcontainers.py ceil.py philips_bulb.py vacuum_mapparser.py chuangmi_ir.py philips_eyecare_cli.py vacuum.py chuangmi_plug.py philips_eyecare.py version.py click_common.py philips_moonlight.py waterpurifier.py cli.py plug_cli.py wifirepeater.py cooker.py powerstrip.py wifispeaker.py data protocol.py yeelight.py

AsWaM avatar Dec 23 '18 19:12 AsWaM

Please download & extract this file: https://github.com/syssi/philipslight/archive/develop.zip

Place the "custom_components" folder (incl. content) into your config directory. On hassbian the directory structure looks like this:

/home/homeassistant/.homeassistant/custom_components/light/xiaomi_miio.py

On hass.io it should be something like this:

/config/custom_components/light/xiaomi_miio.py

Restart Home Assistant and try to control the moonlight.

syssi avatar Dec 23 '18 23:12 syssi

Hello, and merry christmas! Works perfectly, thank you very much :)

Il will try to use the sleep assistant and sleep off time features when I go back from holidays.

Thanks Again

AsWaM avatar Dec 27 '18 08:12 AsWaM

I would be happy if you provide some details (example values, mihome settings -> moonlight behavior) about the sleep assistant & sleep off time features. Thanks in advance!

syssi avatar Dec 27 '18 09:12 syssi

Of course, will do this either next weekend or the first week of january

AsWaM avatar Dec 27 '18 09:12 AsWaM

I hope the naming of the properties (brand_sleep, brand f.e.) can also be improved some day if the meaning is known.

syssi avatar Dec 27 '18 09:12 syssi

Hello, sorry for the delay, The component works perfectly!!! I try to figure out the meaning of the properties (brand_sleep, brand), it looks like it is an indicator of supported features (you can do anything, it never changes)

Alex

AsWaM avatar Feb 05 '19 06:02 AsWaM

@AsWaM Do you own a Miband?

syssi avatar Feb 05 '19 06:02 syssi

Yes, a miband 3

AsWaM avatar Feb 05 '19 06:02 AsWaM

The property should be miband related. If you enable the "miband dependend turn off" the brand_sleep property should be true. If you don't use the feature it's false.

syssi avatar Feb 05 '19 07:02 syssi

I will try this, and keep you informed

AsWaM avatar Feb 05 '19 07:02 AsWaM

@syssi you were right, this is MiBand Related brand_sleep --> Auto power off with MiBand when asleep brand --> Auto power on/off when miband is close sleep_off_time --> remaining time before countdown ends (minutes) --> set to 0 if sleep mode deactivated total_assistant_sleep_time --> original countdown time (minutes)

AsWaM avatar Feb 06 '19 10:02 AsWaM

Hello, I've found some issues related to the scenes. HA allows 1,2,3 and 4 only. But when I chose midnight theme from MI home, it shows as "6" in HA When I chose music mode, in HA i have the error below:

Got exception while fetching the state: {'code': -5001, 'message': 'music mode'}

frkos avatar Feb 11 '19 11:02 frkos

@frkos How did you choose the "music mode"?

syssi avatar Feb 11 '19 19:02 syssi

@frkos If you change this line in HA

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/xiaomi_miio/light.py#L91

Is scene 5 and 6 available/usable via the set_scene service?

syssi avatar Feb 11 '19 19:02 syssi

@frkos How did you choose the "music mode"?

Music mode is the colored button at the bottom of mi home. smartselect_20190211-234200_mi home

@frkos If you change this line in HA

https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/xiaomi_miio/light.py#L91

Is scene 5 and 6 available/usable via the set_scene service?

I have hass.io installation with doker. So I've set up ssh, connected to hassio.local, but couldn't find components folder to amend the file ((( If you let me know how to do this, I will be glad to help you with testing

frkos avatar Feb 11 '19 20:02 frkos

Provide some testing on docker setups is hard. Could you install python-miio (pip3 install python-miio) on your desktop and provide some output of the miiocli command line interface?

syssi avatar Feb 12 '19 06:02 syssi

Provide some testing on docker setups is hard. Could you install python-miio (pip3 install python-miio) on your desktop and provide some output of the miiocli command line interface?

Here it is... Sorry for the screenshot, I'm doing it from my cell phone 😬 Is it what you need? screenshot_20190212-121545_photo editor

frkos avatar Feb 12 '19 09:02 frkos

Perfect! Please try:

miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "['4']"
miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "['5']"
miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "['6']"

Does it work?

syssi avatar Feb 12 '19 20:02 syssi

Unfotunately, for apply_ I have param err, so i tried other options, but with timeout error(( Is it possible to increase it? BTW info, on,off... works, but not the raw_command screenshot_20190212-233414_termux

frkos avatar Feb 12 '19 20:02 frkos

It looks like you missed a space between property (set_fixed_scene) and the new value ("['1']"). You could enable the deboug output of miiocli by -d to get more insights / details.

syssi avatar Feb 13 '19 06:02 syssi

Done... But with rhe same UART timeout error( screenshot_20190213-093943_termux

But set_scene without raw_command works. Of course, just for 1-4 options smartselect_20190213-094550_termux

frkos avatar Feb 13 '19 06:02 frkos

Next try:

miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "[4]"
miiocli device --ip 192.168.1.101 --token f.... raw_command get_prop "['scene']"

miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "[5]"
miiocli device --ip 192.168.1.101 --token f.... raw_command get_prop "['scene']"

miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "[6]"
miiocli device --ip 192.168.1.101 --token f.... raw_command get_prop "['scene']"

Note the removed single quotes for the numbers. The value must be an integer and no string.

syssi avatar Feb 13 '19 06:02 syssi

Now it works for all scenes except 6. Also get_prop 'scene' doesn't work. But it works for get_prop 'status'... I think 'scene' is not available property name ( smartselect_20190213-102354_termux

Also i confirm, that scene 5 is 'scrreen reading' from mi home app. And when I chose 'midnight' in mi home, I see 6 in HA. But can't set it via miiocli... Weird smartselect_20190213-102916_mi home

smartselect_20190213-102951_firefox

frkos avatar Feb 13 '19 07:02 frkos

Okay. Could you try to enable the night light by:

# make sure "scene 6" isn't active
miiocli device --ip 192.168.1.101 --token f.... raw_command apply_fixed_scene "[1]"
# get the scene property called "snm"
miiocli device --ip 192.168.1.101 --token f.... raw_command get_prop "['snm']"

# enable the night light mode?
miiocli device --ip 192.168.1.101 --token f.... raw_command enable_bl "[True]"
# the value of snm should be 6 now
miiocli device --ip 192.168.1.101 --token f.... raw_command get_prop "['snm']"
# turn off the night light mode?
miiocli device --ip 192.168.1.101 --token f.... raw_command enable_bl "[False]"
# check the scene again
miiocli device --ip 192.168.1.101 --token f.... raw_command get_prop "['snm']"

syssi avatar Feb 15 '19 08:02 syssi

Looks like it's not for scene 6... Also i tried "['on']" and "[1]" but with the same result smartselect_20190215-114154_termux

frkos avatar Feb 15 '19 08:02 frkos

Could you try

miiocli device --ip 192.168.1.101 --token f.... raw_command go_night "[]"

too?

syssi avatar Feb 15 '19 09:02 syssi

And now it works! As I'm doing it remotely, I can check the lamp itself in the evening only. But HA shows scene 6 and Mi Home shows midnight scene. So it definitely works.

I tried go_music randomly and it works too - MI home opens music mode screen. So as I understand, the only promblem is that HA expects scene as int, and crashes when receive str 'music mode'. Maybe in the code it's pissible to map music mode to scene 7, for example... And we are done )

smartselect_20190215-121830_termux

frkos avatar Feb 15 '19 09:02 frkos