Allmylights
Sync your RGB devices through MQTT with OpenRGB, your Desktop Wallpaper, Chroma devices, and more to come
Install / Use
/learn @sparten11740/AllmylightsREADME
allmylights
What am I?
I am a command line app that synchronizes your ambient lighting and RGB peripherals. I serve as a broker that consumes input values through MQTT and other sources, and applies those to a number of configurable sinks. Those can be an OpenRGB instance, Chroma enabled devices, or your Desktop wallpaper.
Dependencies
OpenRGB
OpenRGB is one of the supported options to control the RGB peripherals of your host system.
Open source RGB lighting control that doesn't depend on manufacturer software. Supports Windows and Linux.
You can download the OpenRGB binaries in the release section of the project's gitlab
Follow these instructions to run a minimized OpenRGB server when logging in to your machine.
For questions around the detection of your devices, please refer to the OpenRGB community.
MQTT Server
Inputs such as profile names, or color strings are received through subscription of an MQTT topic.
MQTT is an OASIS standard messaging protocol for the Internet of Things (IoT). It is designed as an extremely lightweight publish/subscribe messaging transport that is ideal for connecting remote devices with a small code footprint and minimal network bandwidth
Given that you are looking at this page, you probably have a smart home framework in place already and want to integrate with it. Chances are that you are using MQTT as part of that setup. In that case you can go ahead and skip the rest of this section. If you're using a smart home framework without MQTT, please refer to the following resources for getting your MQTT server started and integrated.
OpenHAB Integration
An OpenRGB Binding for OpenHAB does not exist. However, it is something that would be easy to implement.
OpenHAB has a binding that connects with an MQTT broker. Install the broker Mosquitto on your device running OpenHAB and afterwards proceed installing the MQTT Binding.
You could then create a rule along the lines (using the rules DSL):
"Set RGB value"
when
Item My_Color_Item received command
then
val actions = getActions("mqtt","mqtt:broker:mosquitto")
val HSBType hsb = receivedCommand as HSBType
val Color color = Color::getHSBColor(hsb.hue.floatValue / 360, hsb.saturation.floatValue / 100, hsb.brightness.floatValue / 100)
val String rgb = String::format("%1$02x%2$02x%3$02xFF" , color.red, color.green, color.blue)
actions.publishMQTT("stat/open-rgb/RESULT", rgb)
end
Installation
Using the binaries
Download the binaries for your target platform in the releases section (stable) or from the uploaded artifacts of the most recent workflow runs. Place them in your desired target location. You can also clone this repository and build the project yourself.
Building the project yourself
In order to build the binaries for Windows, you have to use a Windows machine. This is because of a framework dependency on
Microsoft.WindowsDesktop.Appthat is only available on Windows. However, MacOS and Linux binaries can be built and published from any host system.
First you need to install the Visual Studio Community Edition 2019 on your machine.
Make sure dotnet is available in your path and run the following command from
the project root to build a standalone .exe (Windows):
dotnet publish --runtime win-x64 --configuration Release -p:PublishSingleFile=true --self-contained false
Run the following if you want the application to work on a target without the .NET runtime installed:
dotnet publish --runtime win-x64 --configuration Release -p:PublishSingleFile=true -p:PublishTrimmed=true --self-contained true
Configuration
The required parameters such as connection details are provided in a
configuration file called allmylightsrc.json (default). Hereinafter, I will
adivse on what this file should look like to satisfy your requirements.
A number of usage examples can also be found in the wiki.
The configuration distinguishes between
- sources, that provide values to the app
- transformations, that alter those values
- sinks, that consume and apply those values
- (optional routes that define from which sources to what sinks those values travel)
Any value emitted by a source is routed to all sinks unless routes are specified.
The structure of the allmylightsrc.json is the following:
// allmylightsrc.json
{
"Sources": [
// ... see available options below
],
"Sinks": [
// ... see available options below
],
"Routes": [
// ... see route section
]
}
Available source, sink, and transformation types are:
| Type | Options |
| ---------------| ---------------------------------------------|
| Source | Mqtt, OpenRGB |
| Sink | OpenRGB, Wallpaper, Chroma, Mqtt |
| Transformation | JsonPath, Color, Mapping, Expression |
Sources
Sources produce values that are eventually consumed by sinks. All sources have a
Transformations property in common. Therein you can define transformations
that alter the value emitted by the source to suit your requirements.
MQTT
The MQTT source subscribes to a topic and emits all values that are published to that topic.
{
// optional id that can be used to define routes
"Id": "my-mqtt-source",
"Type" : "Mqtt",
"Server": "192.168.1.20",
"Port": 1883,
"Topics": {
// optional command topic that is used to request the current color on startup
"Command": "cmnd/sonoff-1144-dimmer-5/color",
"Result": "stat/sonoff-1144-dimmer-5/RESULT"
},
// transformations are applied in order on any received message
"Transformations": [
// ... see section transformations for options
]
}
OpenRGB
The OpenRGB source continueously polls your configured OpenRGB server and emits an object that contains the colors per device whenever a device state changes.
{
// optional id that can be used to define routes
"Id": "my-openrgb-source",
"Type" : "OpenRGB",
"Server": "127.0.0.1",
"Port": 6742,
// controls how often OpenRGB is asked for changes, default is 1000ms
"PollingInterval": 1000,
// transformations are applied in order on any received message
"Transformations": [
// ... see section transformations for options
]
}
The produced value is of type Dictionary<string, DeviceState> where the
key is the name of your OpenRGB device and DeviceState is a struct that
has the following properties:
public struct DeviceState
{
public IEnumerable<Color> Colors;
}
To extract values from it, use the Expression transformation such as
{
"Type": "Expression",
"Expression": "value[\"Corsair H150i PRO RGB\"].Colors.Cast().First().ToCommaSeparatedRgbString()"
}
Sinks
Sinks conclude the transformation process and consume values. A sink can define transformations which are applied on the value before it is consumed by the sink.
OpenRGB
The OpenRGB sink can receive values of type System.Drawing.Color or string.
Colors are applied to all devices connected to your OpenRGB instance
unless specified otherwise in the sink's Overrides property. A color type can
be converted from a string (such as #FF0022 or Red) by adding a Color
transformation to the sink.
String values received by the sink have to be valid OpenRGB profile names such
as MyProfile.orp. They end in .orp and have to exist on your OpenRGB host.
Note that a working version of the profile management API was only added in
commit f63aec11 to OpenRGB. Please make sure that you have an up-to-date
version on your machine.
{
// optional id that can be used to define routes
"Id": "my-openrgb-sink",
"Type": "OpenRGB",
"Server": "127.0.0.1",
"Port": 6742,
// if you want to override certain OpenRGB controlled devices you can do so here
"Overrides": {
// ignore an entire device
"Razer Copperhead": {
"Ignore": true,
},
"MSI Mystic Light MS_7C84": {
"Zones": {
// configure what color is passed to what channel of a zone
"JRGB2": {
"ChannelLayout": "GRB"
},
// ignore a single zone of a device
"JRAINBOW1": {
"Ignore": true
}
}
}
},
// transformations can also be applied before a sink consumes a value
"Transformations" : []
}
MQTT
The MQTT sink publishes any value it consumes to all configured topics.
{
// optional id that can be used to define routes
"Id": "my-mqtt-sink",
"Type" : "Mqtt",
"Server": "192.168.1.20",
"Port": 1883,
// Optiona
