rytilahti / python-miio

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

Improve the Bedside Lamp / Moonlight support #417

Open syssi opened 5 years ago

syssi commented 5 years ago
# delayed turn off / enabled delayed turn off, minutes?
set_sleep_time [i]
en_wakeup

# visual "alarm clock": hour, minute
set_wakeup_time [i, i]  
en_sleep

# enable night light
enable_bl
go_night
ms <-> enable_mibs (setSleepCloseEnable)
mb <-> enable_mb (setXmBraceletEnable)
syssi commented 5 years ago

@slakin Do you like to provide some details (request & response payloads) about the mentioned methods above? You can use the "miiocli --ip IP --token raw_command METHOD PARAMS" to execute the commands.

slakin commented 5 years ago

I will be glad to help. I will try to do it on next weekend.

mouth4war commented 5 years ago

Is this for the yeelight bslamp2?

syssi commented 5 years ago

@mouth4war Is your lamp working?

slakin commented 5 years ago
raw_command set_sleep_time '[1]'
Running command raw_command
['ok']

First param - minutes (1-60) Changed 'spt' to 1

raw_command en_wakeup '[0]'
Running command raw_command
['ok']

Disable wakeup mode Changed 'wke' to 0

raw_command en_wakeup '[1]'
Running command raw_command
['ok']

Enable wakeup mode Changed 'wke' to 1

raw_command set_wakeup_time '[1,2,3]'
Running command raw_command
['ok']

Changed wkp to [3, 1, 2] First param - hour (0-23) Second param - minutes (0-59) Third param - days of the week. For example '1' - Mon, '2' - Tue, '3' - Mon and Tue. '4' - Wed, '7' - Mon Tue Wed, '8' - Thu

raw_command en_sleep '[1]'
Running command raw_command
['ok']

Enable sleep mode Changed 'spr' to value from 'spt' field and started countdown for 'spr' field

raw_command en_sleep '[0]'
Running command raw_command
['ok']

Disable sleep mode Changed 'spr' 0

raw_command go_night
Running command raw_command
['ok']

Turn on Midnight scene

raw_command enable_mibs '[0]'
Running command raw_command
['ok']

Disable "Auto turn off the lamp when Mi Band detected you are asleep" Changed 'ms' to 0

raw_command enable_mibs '[1]'
Running command raw_command
['ok']

Enable "Auto turn off the lamp when Mi Band detected you are asleep" Changed 'ms' to 1

raw_command enable_mb '[0]'
Running command raw_command
['ok']

Disable "Turn on the lamp when Mi Band is nearby. Turn off the lamp when it is far away" Changed 'mb' to 0

raw_command enable_mb '[1]'
Running command raw_command
['ok']

Enable "Turn on the lamp when Mi Band is nearby. Turn off the lamp when it is far away" Changed 'mb' to 1

raw_command enable_bl '[1]'
Running command raw_command
['ok']

Enable "When the ambient light is dark during 23:00-6:00, the soft Night Light turns on automatically for the comfort of your eyes" Changed 'bl' to 1

raw_command enable_bl '[0]'
Running command raw_command
['ok']

Disable Changed 'bl' to 0

syssi commented 5 years ago

Good job! I will ask some more questions if I implement this feature. All "days of the week" values would be nice f.e. and what do you mean be "midnight scene"? How does it look like?

slakin commented 5 years ago

"midnight scene" - it's very dim warm light. inkedscreenshot_2019-01-14-10-36-37-993_com xiaomi smarthome_li

slakin commented 5 years ago

"days of the week" - they looks like enum with values which can be combined. I'm not familiar with Python, but I found something similar in docs - https://docs.python.org/3/library/enum.html#intflag.

from enum import IntFlag
class DayOfTheWeek(IntFlag):
     Mon = 1
     Tue = 2
     Wed = 4
     Thu = 8
     Fri = 16
     Sat = 32
     Sun = 64

>>> DayOfTheWeek.Mon + DayOfTheWeek.Tue 
3

How it look like on UI screenshot_2019-01-14-10-57-12-132_com xiaomi smarthome

jiafengwang commented 4 years ago

I have the bslamp2 and ceiling3. Through the Yeelight and MiHome APP I can select the moonlight mode to control both bslamp2 and ceiling3, successfully change them to moonlight mode. But only ceiling3 can be conctrol with HomeAssistant through define the "nightlight_switch_type" to the configuration.yaml file. Bslamp2 still can't. Wish you can improve it. If need any further testing, I am glad to do. Thanks a lot!

syssi commented 4 years ago

@jiafengwang Both devices are supported by the yeelight component / library. Do you use xiaomi_miio to control your lights? I don't think so. In this case this is the wrong project / issue. :-)

jiafengwang commented 4 years ago

Sorry for that. Actually I mean the Yeelight Ceiling3 and Yeelight Bslamp2, not Philips. I use yeelight comptent to control them.