A. YLIGHT utility to control Yeelight® bulbs
B. YSUNLIGHT set color temperature to time of the day
Depends on: bash, coreutils, curl, jq, openbsd-netcat, socat
Clone this repository:
git clone https://github.com/teegre/ylight-suite.git
then:
./install.sh
YLIGHT - utility to control Yeelight® bulbs
LAN Control has to be enabled via Yeelight® mobile application:
https://www.yeelight.com/faqs/lan_control
When done, bulbs on your local network have to be discovered. Enter:
$ ylight --discover
ylight: OK
If you get an error message, wait a few seconds and invoke the command again.
Show bulb status:
$ ylight --status
name: bulb
host: xxx.xxx.x.xxx
port: xxxxx
power: off
brightness: 100%
color temp: 6500K
effect: smooth
transition: 500 ms
In case you own more than one bulb:
$ ylight --list
bulb1:xxx.xxx.x.xxx:xxxxx
bulb2:xxx.xxx.x.xxx:xxxxx
The first of the list will be used as default. So, if you want to turn bulb2 on:
$ ylight --name bulb2 --on
To set bulb2 as default:
$ ylight --set-default bulb2
default bulb set to: 'bulb2'
OPTIONS:
Option | Description |
---|---|
--discover | retrieve and save bulbs IP and port on local network |
--set-name NAME | set device name |
--set-default DEVICE_NAME | set DEVICE_NAME as default device |
-a, --name DEVICE_NAME | send command to DEVICE_NAME |
-l, --list | print saved bulbs |
-s, --status | display bulb status |
-n, --on | turn light on |
-f, --off | turn light off |
-t, --toggle | toggle power |
-b, --brightness [+/-]VALUE | set brightness (1..100) |
-c, --color-temp [+/-]VALUE | set color temperature (1700..6500) |
-T, --timer [DURATION] | enable timer for a given duration |
(from 1 to 120 minutes). 0 to turn off current timer; | |
if no argument is present, each call to the function | |
set the timer with a preset duration | |
(30, 60, 90, 120 minutes or off, respectively) | |
-S, --smooth [DURATION_MS] | smooth transition time when changing settings (100..10000) |
-u, --sudden | changes are applied immediately (ignore -S) |
-N, --notify | display a notification |
-h, --help | print this help and exit |
-V, --version | print program version and exit |
Turn light on, set brightness to 50% and color temperature to 4500K:
ylight -n -b 50 -c 4500
Decrease brightness by 10% and turn light off:
ylight -b -10 -f
YSUNLIGHT - set color temperature according to time of the day.
Once per day, ysunlight connects to this website https://sunrise-sunset.org
to retrieve sunrise and sunset times in your city, then it sets the right color temperature.
If the light is currently turned off, color temperature will be set once you turn the light on.
Period | Color temperature |
---|---|
Sunset | 1700K→6500K |
Sunrise | 6500K→4500K |
Night (user defined) | 4500K→1700K |
To be able to work, ysunlight needs to know:
- Timezone
- Latitude
- Longitude
Type this command:
$ timedatectl
Local time: ven. 2020-07-03 11:34:50 CEST
Universal time: ven. 2020-07-03 09:34:50 UTC
RTC time: ven. 2020-07-03 09:34:50
Time zone: Europe/Paris (CEST, +0200)
System clock synchronized: yes
NTP service: active
RTC in local TZ: no
What you need is Europe/Paris
Follow the link: https://latitude.to
and enter your city name, for instance, Paris
Edit the file: $HOME/.config/ylight/ysunlight.conf
and enter the previous info, ie.:
timezone=Europe/Paris
latitude=48.85
longitude=2.35
Other settings can also be found:
night_time=11:00 PM
sunrise_duration=600
sunset_duration=600
sunrise_step_duration=60
sunset_step_duration=60
All durations are in seconds.
$ systemctl --user enable ysunlight
$ systemctl --user start ysunlight
If everything went fine, you should see a notification
indicating time of the day.
If something went wrong, check the log file at: $HOME/.config/ylight/ysunlight.log
and also: systemctl --user status ysunlight
[] YLIGHT: ability to send commands to more than one bulb at a time.
[] YSUNLIGHT: Make color temperature configurable.
[] YSUNLIGHT: Check if night_time value is valid.