Coder Social home page Coder Social logo

yeelight-shell-scripts's Introduction

Yeelight Shell Scripts

Control Xiaomi Mi Yeelight (RGB) with shell scripts. Should work under any recent Linux with a bash or zsh - sorry, don't know if that works under Windows/CygWin or Macos - you might need to rewrite the last line in the yeelight.sh script (e.g. by pipeing the output to netcat).

License

Copyright [2016] [Heinz Peter Hippenstiel]

Licensed under the Apache License, Version 2.0 (the "License"); you may not use the files in this repository except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Setup

You need to connect the light using the Yeelight app (or using any other appropriate way) to your network. Then enable Developer Mode (or LAN Control Mode in the current version of the app) for the light. This setting may need to be reset after a firmware update. You should also make sure that your DHCP server always assigns the same IP address to the light.

Now edit the yeelight-ips file and enter the IP address of each light you have, separated by a space.

Running

Each of the yeelight-*.sh scripts has a specific function that is hopefully quite easy to guess from it's name. All the scripts call the yeelight.sh script that really does the job. Each script requires several parameters - calling them without any will give you a usage prompt. All scripts require the ID of a light - this is the position of the light you entered in the setup part. The first light has the ID 0.

Examples

Switch on (to last used values)

./yeelight-scene.sh 0 On

Switch on using 4300 Kelvin

./yeelight-scene.sh 0 4300

Switch on Rainbow

./yeelight-scene.sh 0 Rainbow

Switch on Disco

./yeelight-scene.sh 0 Disco

Switch on Disco with 120ms

DISCOSPEED=120 ./yeelight-scene.sh 0 Disco

Set brightness to 50%

./yeelight-brightness.sh 0 50

Set RGB color to BLUE (using absolut number, decimal and hex triples)

./yeelight-rgb.sh 0 255
./yeelight-rgb.sh 0 0,0,255
./yeelight-rgb.sh 0 x0,0,ff

Set hue (hsv) to 32 (yellow) with 80% brightness (of that color - 0 means full white)

./yeelight-hue.sh 0 32 80

Set color temperature to 6500 Kelvin

./yeelight-colortemp.sh 0 6500

Integration with redshift

yeelight-redshift.sh is a script that allows your lamp to change color temperature simultaneously with your monitor if you use redshift. Just like redshift, this script eases strain on your eyes if you use your computer at night. To use this script you need to copy ./samples/yeelight-redshift.timer and ./samples/yeelight-redshift.service to /etc/systemd/system/, change scrip location in yeelight-redshift.service. Then run sudo systemctl daemon-reload, sudo systemctlt enable yeelight-redshift.timer, sudo systemctl start yeelight-redshift.timer.

You can also change some values in yeelight-redshift.sh if you need warmer color.

For the script to work you need to have redshift installed.

Contributed by Maxim Mishukov

HA-Bridge and Amazon Alexa

I am personally using this scripts on a Synology NAS with a running HA-Bridge. Since the scripts don't require any additional tool or access rights you can just execute them directly from the HA-Bridge. Make sure the scripts are executable (chmod +x *.sh) and either you are using the full path or put them somewhere inside $PATH, for example /usr/local/bin/.

I have setup different scenes as devices for the same light. There is a bedroom device which can be switched on/off and use the dim feature - this is just a normal setup. And there is also a sleep and a rainbow device that addresses the same light to apply this scenes.

yeelight-disco.sh is a wrapper that only accepts one value - I use ${intensity.percent} from HA-Bridge. There is some math done with that value to fit into the 2-99% range (Strange: I can't tell Alexa to use 1 or 100%) and still have some 'disco-speed'. Adjust to your needs.

yeelight-shell-scripts's People

Contributors

coinzz avatar darth-hp avatar engel-b avatar juboba avatar markselias avatar mmskv avatar thekix avatar wardg32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yeelight-shell-scripts's Issues

Not imputing IPs correctly

Hi there,

Im trying to set up your script, but clearly not putting the ips in correctly.

Can you advise, it just says: "Now edit the yeelight.sh script and enter the IP address of each light you have separated by a space."

user@machine:/path/yeelight-shell-scripts$ ./yeelight-scene.sh 0 On
./yeelight.sh: line 2: Put: command not found
cat: ./192.168.190.105: No such file or directory
cat: 192.168.190.106: No such file or directory
cat: 192.168.190.112: No such file or directory
liminal@tautulli:/opt/Tautulli/script/yeelight-shell-scripts$

This is how I entered the IP;

eclare -a ID=($(cat $(dirname $0)/192.168.190.105 192.168.190.106 192.168.190.112))

Thanks

Help - ESP8266

Hello, I want to implement this control on ESP8266 it's possible?

Music mode

Hello . I got my yeelight today. I was wondering If it is possible to use music mode from ubuntu (spotify, youtube etc)

All Yeelights?

Hi,

Is there any way to apply a script to all yeelights at once?

Thanks

Syntax error: "(" unexpected

./yeelight-scene.sh 0 On
./yeelight.sh: 3: ./yeelight.sh: Syntax error: "(" unexpected

#!/bin/sh
declare -a ID=(192.168.1.29 192.168.1.80)

Sunrise and Sunset not working

Hi,
First of all a big thank you for your scripts, they have been really helpfull for me.
The only upset is that Sunset and Sunrise do not work.

As a workaround I found:
/home/me/.local/bin/yeelight_set_scene.sh 3 1 '50,1,16731392,1,360000,2,1700,10,540000,2,2700,100' 192.168.1.3"

cat /home/me/.local/bin/yeelight_set_scene.sh
#!/bin/bash
echo -ne "{"id": 1, "method": "set_scene", "params": ["cf",${1},${2},"${3}"]}\r\n" | /bin/nc -w1 ${4} 55443

from here: https://community.home-assistant.io/t/sunrise-sunset-script/13135/2
and this works.
Can you please advise, I would preffer to use only your script if possible :)
Thanks again!
Vlad

LE:

  1. I cannot comment on the issue: " An owner of this repository has limited the ability to comment to users that are collaborators on this repository. "
  2. yeelight-ips should be declared with absolute path (so it does not depend from where you run the script (if it is in the $PATH))
  3. Add Sunrise2 to SCENES=....
  4. Sunrise2 works perfect
  5. Old Sunrise and Sunset also work now, but are very white.

Thank you very much!

Yeelight Smart LED Bulb W3 doesnot work

While Yeelight s1 works OK, the new W3 does not.

The reason is it needs to send an answer to the host saying something like {"method":"props","params":{"power":"on"}} while printf "something" > /dev/tcp/xxx/yyy does not imply answers.

The solution is to change from
printf "{\"id\":1,$2}\r\n" >/dev/tcp/$ip/55443
to
printf "{\"id\":1,$2}\r\n" | nc -w 1 $ip 55443 &

It means netcat gets an answer and closes the connection after 1 second working in background. Works OK after that.

Wont execute script if full path?

Hi again,

I seem to have an issue when running the script from the full path?

Executing on ID 1 [192.168.190.105] ...   1 Off
Executing on ID 2 [192.168.190.106] ...   2 Off
Executing on ID 3 [192.168.190.112] ...   3 Off

Returns this and does nothing

Where as running the script from the directory gives me;

Executing on ID 1 [192.168.190.105] ...   1 "method":"set_power","params":["off"]
Executing on ID 2 [192.168.190.106] ...   2 "method":"set_power","params":["off"]
Executing on ID 3 [192.168.190.112] ...   3 "method":"set_power","params":["off"]

And it works

Connection refused upon executing any script

Running any script will throw the same error : ./yeelight.sh: line 18: /dev/tcp/192.168.__.___/_____: Connection refused

To reproduce :
Run any script, for example ./yeelight-scene.sh 0 On
See the attempt to connect using the given IP address, but failing because the connection was refused (by what/who ?).

Detailed console output :

[Nephty@fedora yeelight-shell-scripts]$ ./yeelight-scene.sh 0 Off
Executing on ID 1 [192.168.88.124] ...   1 "method":"set_power","params":["off"]
./yeelight.sh: connect: Connection refused
./yeelight.sh: line 18: /dev/tcp/192.168.88.124/55443: Connection refused

Expected result : successful connection

I'm running Fedora 34 and double checked that I was on the same network as my light. I tried using different scripts but since they all refer to yeelight.sh, the same error is thrown. The IP is correct because changing it to an unused one gives the message 192.168.__.___ not available.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.