Skip to content

Loading a profile derived through complex expression

Jan W edited this page Feb 14, 2021 · 1 revision

In this example a color is received as a property of an object via MQTT (e.g. { "color": "FFD8C3" }, extracted from the object, and transformed to an OpenRGB profile name through an Expression transformation. Expression transformations allow for applying arbitrary logical expressions on the input value.

Note the Color transformation in the Transformations property of the OpenRGB sink. It converts the input string to the type System.Drawing.Color which allows us to use any method or property that is documented here.

The succeeding Expression transformation looks at the different channels of that Color (R, G, and B) to determine if a color is redish, blueish, or greenish. An OpenRGB profile named Red.orp, Blue.orp, or Green.orp is returned based on that determination.

// allmylightsrc.json

{
  "Sources": [
    {
      "Type": "Mqtt",
      "Server": "192.168.168.1",
      "Port": 1883,
      "Topics": {
        "Result": "stat/openrgb/color"
      }
    }
  ],
  "Sinks": [
    {
      "Type": "OpenRGB",
      "Server": "127.0.0.1",
      "Port": 6742,
      "Transformations": [
        {
          "Type": "JsonPath",
          "Expression": "$.color"
        },
        {
          "Type": "Color"
        },
        {
          "Type": "Expression",
          "Expression": "value.B > value.R && value.B > value.G ? \"Blue.orp\" : (value.G > value.B && value.G > value.R ? \"Green.orp\" : \"Red.orp\")"
        }
      ]
    }
  ]
}