(( apologies for the formatting of the post. I’ll try to fix it if it is too messy at first ))
Hi,
I was wondering if people here have an idea to simplify a number of flows I currently have.
End-goal:
My end-goal is the following:
I want my Philips Hue white ambiance (For those who are not familiar with it: They are white bulbs, varying light from very cold (blueish) to very warm (amberish) and everything in between) to slowly go ‘warmer’ based on the position of the sun.
So,
Suppose the lights are on at mid-day (sun very high/bright), the light is ‘very white’
and if you turn on the lights at midnight (sun very low/not there), the light is ‘very warm’
When the lights are on, and the sun is setting, the light should gradually go warmer but in such a way that I don’t see them suddenly change colour.
Currently used apps:
I currently do this using the following apps:
- Sun Events by Marcel Timmermans to get the position of the sun
- Philips Hue Zigbee by Sebastian Johansson to control my Hue bulbs
- Better Logic by Patrick Sannes to set various variables and slowly change them based on the ‘mathjs’ function
Here are my current flows:
Trigger based on sun event
When
- Sun Event is “Begin of sunset”
Then:
- set better logic numeric variable “target_light_temperature” to 0.65
- set better logic numeric variable “target_light_brightness” to 0.8
When
- Sun Event is “Nautical dusk”
Then:
- set better logic numeric variable “target_light_temperature” to 0.7
- set better logic numeric variable “target_light_brightness” to 0.75
(etc, for a number of Sun Events)
Detect changed target variables
I then 'detect the changed 'target-variables:
When
- better logic numeric variable “target_light_temperature” changes
Then:
- Start Flow “Slowly lower light temperature”
- Start Flow “Slowly raise light temperature”
When
- better logic numeric variable “target_light_brightness” changes
Then:
- Start Flow “Slowly lower light brightness”
- Start Flow “Slowly raise light brightness”
Slowing start changing ‘current’ variables towards ‘target’ variables:
These flows look like (one example):
When
- flow is started (Slowly raise light temperature)
And
- better logic numeric variable “target_light_temperature” is greater than variable “current_light_temperature”
Then:
- Better logic: set variable “current_light_temperature” to mathjs: “round( current_light_temperature + 0.01 ) * 100 / 100”
- Start flow “Slowly raise light temperature” after 5 seconds
This effectively loops the flow “Slowly raise light temperature” until variable “current_light_temperature” is equal to “target_light_temperature”, gradually raising it by 0.01 point every 5 seconds
(( the mathjs is required, because sometimes the variables get skewed causing 0.5 + 0.01 to become: 0.50000001 or something, which the hue bulb doesn’t understand ))
‘Current’ variables are changed
Then another flow reacts on the changed variables:
When:
- variable “current_light_temperature” changes (or)
- variable “current_light_colour” changes
Then:
- Start flow: “Apply new light settings”
Apply the light settings
Then the flow Apply new light settings:
When
- the flow starts
Then:
- Set hue bulb colour to “current_light_temperature”
- Set hue bulb brightness to “current_light_brightness”
The above is the simplified version of the actual flows:
Additional complexity built in are the following, but probably not relevant to my question:
When the lights are off, and the better logic target_light_* variables are changed by a Sun Event, then they the ‘slow’ part is bypassed and the ‘current_light*’ variables are immediately changed (so not going slowly). The purpose of this is the following:
Suppose the Sun Event starts at 19:00, then it can take a few minutes before the end-goal is reached.
If I turn on the light at 19:01, then the lights go on, directly to their targeted values.
I did this, so that Homey doesn’t have to go through the loops when they are not actually changing the bulb settings
This is it
If anyone needs any clarification, I’ll try to update this post.