|
| 1 | +# Custom presets |
| 2 | + |
| 3 | +Starting with v1.1.0, this integration also allows you to have your own custom presets. |
| 4 | + |
| 5 | +Be advised though that this feature will not hold your hand. It is intended to be used by developers. |
| 6 | + |
| 7 | +## How |
| 8 | + |
| 9 | +On startup, the custom_component will create folder named `userdata/custom` inside `custom_components/scene_presets` |
| 10 | +of your home assistant instance. By default, this folder will be empty apart from another folder named `assets`. |
| 11 | + |
| 12 | +To add custom presets, you create a `presets.json` in that folder and add your custom images to that `assets` folder. |
| 13 | +This essentially mirrors the structure of the included scenes. The JSON Schema is the same. |
| 14 | +Everything in the custom presets will simply be added at the end of the lists of categories and presets. |
| 15 | + |
| 16 | +Please note that there is no validation in place that would prevent you from creating ID conflicts nor is there any |
| 17 | +validation ensuring that the schema of the custom data is correct. Just don't provide any incorrect data. |
| 18 | + |
| 19 | +If I understood the HACS documentation correctly, this folder should survive component updates.<br/> |
| 20 | +For now though, I'd recommend making backups just to be sure. |
| 21 | + |
| 22 | +## Example |
| 23 | + |
| 24 | +The best way to explain this feature is to give an example. |
| 25 | + |
| 26 | +First the directory structure: |
| 27 | + |
| 28 | +``` |
| 29 | +user@foo:/homeassistant/custom_components/scene_presets# tree userdata/ |
| 30 | +userdata/ |
| 31 | +└── custom |
| 32 | + ├── assets |
| 33 | + │ └── 1d2ef59e-8f29-4d58-a437-c0b03d90ce8a.jpeg |
| 34 | + └── presets.json |
| 35 | +
|
| 36 | +3 directories, 2 files |
| 37 | +``` |
| 38 | + |
| 39 | +And here's the content of the `presets.json`: |
| 40 | + |
| 41 | +``` |
| 42 | +{ |
| 43 | + "categories": [ |
| 44 | + { |
| 45 | + "name": "Color Temperatures", |
| 46 | + "id": "e0c17262-f84b-4943-bdd5-fcd24c574f24" |
| 47 | + } |
| 48 | + ], |
| 49 | + "presets": [ |
| 50 | + { |
| 51 | + "id": "1d2ef59e-8f29-4d58-a437-c0b03d90ce8a", |
| 52 | + "categoryId": "e0c17262-f84b-4943-bdd5-fcd24c574f24", |
| 53 | + "name": "1800 Kelvin", |
| 54 | + "bri": 76, |
| 55 | + "lights": [ |
| 56 | + { |
| 57 | + "x": 0.6264, |
| 58 | + "y": 0.3632 |
| 59 | + } |
| 60 | + ] |
| 61 | + } |
| 62 | + ] |
| 63 | +} |
| 64 | +``` |
| 65 | + |
| 66 | +In there you can see a few things: |
| 67 | + |
| 68 | +- We've added a new category named "Color Temperatures" |
| 69 | +- We've added a single preset with the "Color Temperatures" categoryId |
| 70 | + |
| 71 | + => every preset needs to be part of a category <br/> |
| 72 | + => custom presets can be part of stock categories <br/> |
| 73 | +- The new "1800 Kelvin" preset has a single light |
| 74 | + |
| 75 | + => There is no limit to how many lights a preset can have <br/> |
| 76 | + => If you apply a preset to a group with more lights, some options will be repeated <br/> |
| 77 | + => Colors have to be specified as X/Y |
| 78 | + |
| 79 | +After adding that example JSON and restarting Home Assistant, it looks like this: |
| 80 | + |
| 81 | + |
| 82 | + |
| 83 | +And as you can see, we forgot to install Counter-Strike: Source. |
| 84 | + |
| 85 | +To fix that, we need to change the preset to include an `img` key like this: |
| 86 | + |
| 87 | +``` |
| 88 | + { |
| 89 | + "id": "1d2ef59e-8f29-4d58-a437-c0b03d90ce8a", |
| 90 | + "categoryId": "e0c17262-f84b-4943-bdd5-fcd24c574f24", |
| 91 | + "name": "1800 Kelvin", |
| 92 | + "img": "1d2ef59e-8f29-4d58-a437-c0b03d90ce8a.jpeg" |
| 93 | + "bri": 76, |
| 94 | + "lights": [ |
| 95 | + { |
| 96 | + "x": 0.6264, |
| 97 | + "y": 0.3632 |
| 98 | + } |
| 99 | + ] |
| 100 | + } |
| 101 | +``` |
| 102 | + |
| 103 | +This will now point to `userdata/custom/assets/1d2ef59e-8f29-4d58-a437-c0b03d90ce8a.jpeg`.<br/> |
| 104 | +Make sure to place the desired image there. |
| 105 | + |
| 106 | +And that's it. When in doubt, take a look at the `presets.json` and `assets` included with the component.<br/> |
| 107 | +As said, they are the same format and structure. |
| 108 | + |
| 109 | +## Misc |
| 110 | + |
| 111 | +To convert RGB colors to X/Y, you can use this js snippet using the `cie-rgb-color-converter` npm library: |
| 112 | +``` |
| 113 | +const colorConverter = require("cie-rgb-color-converter"); |
| 114 | +
|
| 115 | +const xyValue = colorConverter.rgbToXy(255, 126, 0); |
| 116 | +xyValue.x = parseFloat(xyValue.x.toFixed(4)); |
| 117 | +xyValue.y = parseFloat(xyValue.y.toFixed(4)); |
| 118 | +
|
| 119 | +console.log(JSON.stringify(xyValue, null, 2)) |
| 120 | +``` |
0 commit comments