Coder Social home page Coder Social logo

10xjschad / bulbscript-for-wiz-lights Goto Github PK

View Code? Open in Web Editor NEW
22.0 2.0 5.0 58 KB

BulbScript is a simple scripting language for controlling Philips Wiz Lightbulbs using the pywizlight library.

License: GNU General Public License v3.0

Python 100.00%
wiz wiz-light wiz-light-bulb scripting-language philips smarthome interpreter scripting

bulbscript-for-wiz-lights's Introduction

BulbScript for Wiz Lights

BulbScript is a simple scripting language used to control Philips Wiz Lightbulbs using the pywizlight library.
BulbScript can be used to very quickly create intricate lightbulb sequences with the help of functions, variables, and conditional statements, all without having to write any Python code. However, BulbScript also supports executing and getting returned values from custom Python functions, for those who are looking to create more advanced light sequences and routines.

This script and several other example scripts can be found in /BulbScript_scripts

Dependencies

💡Using BulbScript

1. Configure your broadcast space in config.py. (Default: "192.168.1.255")
2. Run interpreter.py, this will execute the default BulbCode.bulb script. If your lights start slowly turning off and on, your broadcast space is set correctly.
3. Create your own BulbScript script! Simply navigate to the /bulbScript_scripts directory and create a new .bulb file. Then open it in your favorite text editor and start coding! Make sure to read the documentation below and check out the other example script in the /bulbScript_scripts directory if you're struggling.
4. Set the "loadedScript" variable in config.py to your new bulb script, and run interpreter.py. If everything is configured correctly, your script will be successfully executed. The script will infinitely loop until it hits a "stop" command.

Note: BulbScript now supports indentation in scripts!


⚠️BulbScript Limitations

As BulbScript is a small and simple interpreted scripting language with the sole purpose of controlling lightbulbs, it does not come packed with 'quality of life' features. The interpreter expects you to write your code formatted exactly as in the example scripts and in many cases will ignore an incorrectly formatted line of code instead of throwing an exception.

BulbScript does NOT support

  • Arrays, Lists, Vectors, etc
  • Booleans. I did not see a point in implementing this, as integers will get the same job done.
  • For Loops. However, a simple workaround can be found in "Loop Example.bulb".
  • BulbScript function arguments and return values, however, you can still pass BulbScript values to a custom Python function and get the returned value
  • Nested functions (but it does support nested conditionals!)

📖BulbScript Commands

setrgb 'all/index of light' (R, G, B)

setrgb all (255, 255, 255) //Sets the rgb value of all lights to (255, 255, 255) 

setbrightness 'all/index of light' 'int 1-255'

setbrightness 1 50 //Sets the brightness value of the light at the index of 1 to 50 

setscene 'all/index of light' 'int 1-255'

setscene all 4 //Sets the scene on all lights to 4

Supported scenes can be found here

setwhite 'all/index of light' warm/cold 'int 1-255'

setwhite all warm 50 //Sets all lights to a warm white with a brightness value of 50 
setwhite all cold 255 //Sets all lights to a cold white with a brightness value of 255 

setoff 'all/index of light'

setoff all //Turns all the lights off

slp float

slp 0.5 //Waits for half a second before continuing 

var varName

var exampleIntVariable = 50
var exampleFloatVariable = 5.5
var exampleStringVariable = Hello World!

set variable 'variable/value'

set exampleIntVariable 50 //Sets the value of exampleIntVariable to 50 
set exampleIntVariable exampleFloatVariable //Sets the value of exampleIntVariable to the value of exampleFloatVariable 

add variable 'variable/value'

add exampleIntVariable 50 //Adds 50 to the value of exampleIntVariable
add exampleIntVariable anotherIntVariable //Adds the value of anotherIntVariable to the value of exampleIntVariable

sub variable 'variable/value' //Same as add but for subtraction

exec functionName() //Executes a Python function from /user_functions/customFunctions.py
//Note: The default BulbScript variable 'returned' will be set to whatever the custom function returns

print //Prints out whatever comes after it

print Hello World! //Prints out "Hello World!"
print The value of X is *X* //Prints out "The value of X is " followed by the value of the variable 'X'

rnd variable int int

rnd exampleIntVariable 0 500 //Sets the value of exampleIntVariable to a random number between 0 and 500

if and end if //Starts and ends an If Statement
Supported operators: ==, >=, <=, >, <, !=

if x == 255 //Checks if x is equal to 255
 set y x //Sets the value of y to the value of x (255)
 set x 0 //Sets x to 0
end if //Ends the if statement

func, end func, and call //Starts, ends, and calls a function

func lightsOff
 setoff all
end func

call lightsOff //calls lightsOff once, 'call lightsOff 2' would call it twice.

stop //Stops the script so it will not loop indefinitely

bulbscript-for-wiz-lights's People

Contributors

10xjschad avatar

Stargazers

 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

bulbscript-for-wiz-lights's Issues

Documentation

A lot of this code needs to be documented, hopefully I will be doing that relatively soon.

Allow for indentation in BulbScript scripts.

Currently any form of indentation in BulbScript scripts will cause the line to be parsed incorrectly, this should be an easy fix which would allow BulbScript scripts to be written in a more readable way.

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.