Change light brightness/temperature without changing state

For anyone interested this is what I went with:

- id: set_bathroom_lights_night
  alias: Set bathroom lights for night time
  trigger:
  - platform: time
    at: '22:00:00'
  condition:
  - condition: not
    conditions:
    - condition: state
      entity_id: input_select.bathroom_lights_state
      state: night
  action:
  - wait_template: "{{ is_state('light.bathroom_lights', 'off') }}"
  - delay: 00:00:05
  - service: input_select.select_option
    data:
      entity_id: input_select.bathroom_lights_state
      option: night
  - service: light.turn_on
    data:
      entity_id: light.bathroom_lights
      brightness: 40
      color_temp: 250
  - wait_template: "{{ state_attr('light.bathroom_lights', 'brightness') == 40 }}"
  - wait_template: "{{ state_attr('light.bathroom_lights', 'color_temp') == 250 }}"
  - service: light.turn_off
    data:
      entity_id: light.bathroom_lights

I assume the lights you are using remember their last state and use that when turned on?

If that’s the case then it explains why your automation turns on the light to these settings

      brightness: 40
      color_temp: 250

and then almost immediately turns off the light. Now its state is set and will be used the next time the light is turned on (at night).

Do you have another automation that sets the light’s brightness for use during the day?

I’ve been trying to figure out how to do this as well. At least for the dimmer switches I am using the following seems to be working flawlessly:

- service: scene.apply
  data_template:
    entities:
      light.your_light:
        # Keep current state
        state: "{{ states('light.your_light') }}"
        brightness: 1 # or whatever brightness you want the lights to switch to

This will do a couple of things:

  1. Apply the new brightness level to the light regardless of if the light is currently on or off.
  2. Retain the lights current state and not turn it off or on when it is already on or off respectively.

Would love to hear if this works for other people too or if this working is a fluke with my dimmers.

2 Likes

Which lighting integration are you using to control your dimmers?

I intend to try it on my system but I suspect the behavior you’ve reported may be dependent on the integration.


UPDATE
I tried it with lights that are based on the MQTT integration and the scene.apply trick did not work.

Experiment:
Turn light on to full brightness then turn off.
Call scene.apply to set the light to off and set brightness to 100.
Turn on light without setting brightness.
Light turns on to full brightness (255) and not the brightness level specified in scene.apply.

Basically, the light is not using the brightness level set by scene.apply as its default brightness level.

I know this is possible but it depends on the lighting technology and if the integration implements it correctly.

So I switched mine up a bit, it wasn’t working properly. What I’m now doing is:

# scenes.yaml
- id: bathroom_lights_day
  name: Bathroom Day Lights
  entities:
    input_select.bathroom_lights_state:
      state: day
    light.bathroom_lights:
      brightness: 254
      color_temp: 250
      state: 'on'
- id: bathroom_lights_evening
  name: Bathroom Evening lights
  entities:
    input_select.bathroom_lights_state:
      state: evening
    light.bathroom_lights:
      brightness: 200
      color_temp: 250
      state: 'on'
- id: bathroom_lights_night
  name: Bathroom Night Lights
  entities:
    input_select.bathroom_lights_state:
      state: night
    light.bathroom_lights:
      brightness: 10
      color_temp: 400
      state: 'on'
# automations.yaml
- id: set_bathroom_lights_day
  alias: Set bathroom lights for day time
  trigger:
  - entity_id: sun.sun
    from: below_horizon
    platform: state
    to: above_horizon
  - at: 07:00:00
    platform: time
  condition:
  - condition: not
    conditions:
    - condition: state
      entity_id: input_select.bathroom_lights_state
      state: day
  action:
  - wait_template: '{{ is_state(''light.bathroom_lights'', ''off'') }}'
  - delay: 00:00:05
  - scene: scene.bathroom_day_lights
  - data:
      entity_id: light.bathroom_lights
    service: light.turn_off
- id: set_bathroom_lights_evening
  alias: Set bathroom lights for evening time
  trigger:
  - platform: time
    at: '20:00:00'
  condition:
  - condition: not
    conditions:
    - condition: state
      entity_id: input_select.bathroom_lights_state
      state: evening
  action:
  - wait_template: '{{ is_state(''light.bathroom_lights'', ''off'') }}'
  - delay: 00:00:05
  - scene: scene.bathroom_evening_lights
  - service: light.turn_off
data:
      entity_id: light.bathroom_lights
- id: set_bathroom_lights_night
  alias: Set bathroom lights for night time
  trigger:
  - platform: time
    at: '22:00:00'
  condition:
  - condition: not
    conditions:
    - condition: state
      entity_id: input_select.bathroom_lights_state
      state: night
  action:
  - wait_template: '{{ is_state(''light.bathroom_lights'', ''off'') }}'
  - delay: 00:00:05
  - scene: scene.bathroom_night_lights
  - service: light.turn_off
    data:
      entity_id: light.bathroom_lights
# .storage/input_select
{
    "data": {
        "items": [
            {
                "id": "bathroom_lights_state",
                "name": "bathroom_lights_state",
                "options": [
                    "day",
                    "evening",
                    "night"
                ]
            }
        ]
    },
    "key": "input_select",
    "version": 1
}

I’m using the Samsung SmartThings integration with GE Zwave Motion Dimmers and custom device handlers by Michael Struck on the SmartThings side. I plan on migrating them to use Home Assitant’s Z-Wave integration directly soon. Will report back if I can still get this to work at that point or not.

Are there any plans to change/fix this? It makes adaptive/circadian lighting near impossible to implement smoothly.

There’s nothing to “fix” in Home Assistant. The bulb’s hardware/firmware either supports the feature or it doesn’t.

I should have been more clear: I have LIFX bulbs that support changing the color/brightness while the light is “off” and without changing the state of the light, yet I cannot accomplish this in HomeAssistant.

Are there plans to support this in the future, for devices that have this feature?

My understanding and experience is that currently HomeAssistant does not support this regardless of whether the device’s firmware/api supports it.

It won’t work unless you use the LIFX service call lifx.set_state.

If you are using lifx.set_state and it fails to work correctly, report it as an issue in the Core repository on GitHub.

I have a treatlife DS01C dimmer switch flashed with Tasmota. This also supports changing brightness/dimmer level without changing the state of the switch on. For now, I’ll have to set an automation using the HTTP API to send a brightness setting. This seems like it would be a feature many people want and it could be implemented somehow in HA if enough people show interest.

Use cases are like above. I want to set the bathroom lights to turn on the dimmest possible setting after criteria (basically night time rest of house lights are off) and revert back to full bright during the day and before everyone is asleep. With HA direct, the only way I see is to turn the light on, to the new setting, then turn the light off.
I’m using this shell command for a tasmota dimmer switch, but I really think this would be a useful feature to include in HA
master_bath_light_10percent: curl -s -o /dev/null http://1.2.3.4/cm?cmnd=Dimmer%2010

1 Like

Before I try to understand this I wanted to find out if it’s still working for you and what light(s) you’re controlling. TIA.

Apologies for resurrecting this but exactly the right topic I am after.

I’m just starting out with HA (coming from a different platform) and really like it, except that not having this functionality could be a deal breaker for me.

I have 3 sets of lights:

  • LightwaveRF (via homekit intergration)
  • Lifx
  • Shelly (Dimmer2 and RGBW)

Shelly and Lightwave ones have a physical switch that I use regularly and would therefore like the brightness to be adjusted whilst they are off, so that when someone hits the physical switch, it comes on at the correct brightness for that time.

I can do it with the other platform for all of them but seems like only Lifx has that option with HA.

Hi Daniel,

Can you post the complete code for one light? I am not a programmer and can not get it to work. My entity stays grayed out in the Lovelace card.
Thanks in advance.

This did only work because of the specific details of the implementation of the light device handler in SmartThings.

As other have pointed out, you will need to use your platforms specific implementation for setting brightness or other attributes while the light is off – if that even exists.

@123 Pointed out above how to do this for LIFX bulbs. If you are using GE Z-Wave Smart Motion Dimmers (which I am) you can set the Z-Wave parameter 17 on them to set the brightness default level (i.e. their brightness when they turn on without an explicit brightness value):

service: zwave_js.set_config_parameter
target:
  entity_id: "{{entity_id}}"
data:
  parameter: 17
  value: "{{level}}"

Sadly, I cannot speak to how to do this on any other lights.