In my last post I described how I set my lights to change colour automatically according to the time of day. It’s not quite perfect, and I’ve had to make some tweaks.
The problem is that I have four ways to turn a light on:
- Through the Home Assistant user interface.
- Home Assistant automations such as motion detection.
- Alexa voice control.
- Hue dimmer switches mounted on the wall.
My method for setting the light to the right value when it’s switched on relies on listening for the state change. When the light’s state goes from “off” to “on” I set the appropriate values for colour and brightness based on the time of day. I also have an event listener that sets the current value. It runs on a timer, adjusting all lights that are switched on to my preferred values unless I’ve manually changed them to something outside of the schedule.
The problem is that when the light is switched on, it will default to the values it had when it was last on. There will be a slight delay and then my automation will kick in and set the new values. That can be a problem if the last setting was quite bright. I have a light in the bathroom that I want to come on at very low brightness overnight so that there’s just enough light to see but not so much that it fully wakes me up. It would defeat the object if it came on at a higher brightness which was then lowered by the automation.
It’s not a problem when I use an automation to turn the light on, as I can just replace the service call to use my “LIGHT_ON” event and that will turn the light on and set the correct values in a single step. That covers my bathroom use case, as I have a motion sensor controlling the light. Instead of an automation that turns the light on directly:
I can fire my custom event:
The answer for two out of the other three cases is to use Home Assistant’s light_profile.csv file. This set the default values for a light when it’s switched on. I created a default profile for the lights in my automation with very low brightness. When the light is switched on, it starts dim and then, when the automation kicks in, changes to the required setting gradually using the transition value in my automation. I quite like the effect. so it doesn’t matter to me that it’s not immediate.
That resolves the problem when I use the Home Assistant user interface. It also works with the voice controls because I have Alexa set up to talk to Home Assistant via Home Assistant cloud. That means that Alexa is controlling the lights exposed by Home Assistant instead of directly sending commands to my Hue hub.
That just leaves the dimmer switches. It is possible to let Home Assistant manage the dimmers, but that would mean replacing all of the functionality. I did experiment with it, but it has a downside.
The problem with taking control of the dimmer switch through Home Assistant is that you have to replicate every button push and it doesn’t support press and hold for the dimmer brightness control. The native functionality allows you to hold the brightness buttons down. The light will brighten – or dim – until you release the button. The best that you can achieve with Home Assistant is to react to the buttons having been pressed and then increase – or decrease – brightness by a fixed amount.
A simpler solution was to set the Hue lights to come on at low brightness by default and then the automation works in the same way as the light_profiles.csv does when using the UI. I used the night light default as the first button press for the switches linked to the lights that I manage through my automation:
With those tweaks in place the lights now work the way that I want them to, regardless of how I switch them on.in Home Automation