by kingo55 · 3y ago · 0 comments
Chat GPT is now our personal lighting DJ, giving us dynamic and interesting light combinations that respect our circadian rhythm.
Here's my prompt - the output of which feeds Home Assistant:
Set the hue for my home's lights using the HSL/HSB scale from 0-360 by providing a primary and complementary colour which considers the current situation. The HSL color spectrum ranges from 0 (red), 120 (green), to 240 (blue) and back to 360 (red). Lower values (0-60) represent warmer colors, while higher values (180-240) represent cooler colors. Middle values (60-180) are neutral.
Consider these factors in setting the primary hue (in order of importance):
1. Preferences throughout the day: - When about to wake: Reds, oranges or hot pinks - Approaching bedtime: Hot pinks or reds - During worktime: Blues, greens or yellows - Other times: Greens, yellows or oranges
2. Current activity: Bedtime
3. Sleep schedule: Bedtime 23:00, Wake-up time 07:00
4. Date & time: Sunday May 21, 05:40
5. Current primary hue: 10
6. Current complementary hue: 190
7. Weather: 13°C, wind speed 9 km/h, autumn
Respond in this format and provide a reason in <250 characters:
{"primary_hue": PRIMARY_HUE, "complementary_hue: COMPLEMENTARY_HUE, "reason": REASON }
The output looks like this:
{primary_hue: 10 complementary_hue: 190 reason: "Approaching bedtime and early hours of morning, so a warm and calming hue is needed. Complementary hue adjusted slightly to 195 to maintain balance."}
> {"primary_hue": 345, "complementary_hue": 55, "reason": "For bedtime, warm orange tones at 345 create relaxation while paired with cool green at 55 helps prepare your body for sleep."}
You can absolutely replace this with something self hosted, this was using the `oasst-sft-6-llama-30b` model on https://open-assistant.io
Like so:
Write three thoughts on how the primary and complementary hue should change and what value they should change to, along with your reasoning.
Pick one, summarize the reason for it in less than 50 words.
Then write FINAL CHOICE: followed by output that looks like this {"primary_hue": PRIMARY_HUE, "complementary_hue": COMPLEMENTARY_HUE, "reason": REASON"}
For what it's worth, I've been using something similar with my prompts and felt the completions did a poor job of honoring this, but do a better job when asked to use words instead of characters.
Yes, restricting by characters is hard for GPT-style LLMs because they work in tokens, not characters.
If you actually have a hard cap, you’ll have to give feedback. If it’s just you don’t want an essay, it works great to say something like “a few sentences”. And as always, examples help a ton.
I wonder if the limited amount of variables mean one could just ask ChatGPT to generate a one-time lookup table of colors and store them locally. But it's interesting to see that an LLM can be a "color designer".
Here's a snapshot of how it works in my office - bedroom and living room have similar setups and draw from the same colours:
https://ibb.co/ysxY3Lf https://ibb.co/9VgYVTb
And details on the setup in Node Red/Home Assistant: https://news.ycombinator.com/item?id=36018291
Prompt:
I might struggle matching colours to the music playing a little, but there are so many other factors that it probably doesn't matter.
I also keep complaining that music recommendations fail because they don't take into account enough factors like this - would be great to control music choices this way too
https://news.ycombinator.com/item?id=36018291
The flow is pretty simple in Node Red - render the prompt from Home Assistant and pass it to Chat GPT. The response from Chat GPT is parsed and sent back to Home Assistant in some "Helper" variables known as "input_number" and "input_text".
Once the values are in Home Assistant, it's pretty easy to change the colours of lights in an automation.
Costs about $3/year in API quota.
1. Every hour a Node Red flow runs 2. It generates a prompt using a Home Assistant Jinja template 3. The prompt is sent to Open AI 4. The response gets parsed from JSON and sent to Home Assistant's "input_number" entities 5. Lights in Home assistant pick up the state change and set the new colours
If you're keen, I can share the Node Red flow diagram (or JSON).
Happy to answer any questions if you hit a snag.