Brighten front porch lights, then return to recorded dim level

I thinked first that it was due to phue.py library, but I had the same behavior with yeelight bulbs.
The light.turn_on function was probably updated. Too bad, this trick was useful.

Here was my approach to brighten stairway light then return to previous state :

##############################

- alias: Light Stairway Bright
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d000130d5ed
    from: 'off'
    to: 'on'

  action:
    - service: light.turn_on
      entity_id: light.stairway
      data_template:
        brightness: '{{ ((states.light.stairway.attributes.brightness or 0) + 150) | min(255) }}'

##############################

- alias: Light Stairway Back
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d000130d5ed
    from: 'on'
    to: 'off'

  action:
    - service: light.turn_on
      entity_id: light.stairway
      data_template:
        brightness: '{{ ((states.light.stairway.attributes.brightness or 0) - 150) | max(0) }}'

It appears the behavior of light.turn_on with brightness = 0 has changed. I’m on 0.47.1 and it doesn’t turn off lights connected via Wink or Hue.

That’s unfortunate. I just ran a test and brightness-0 still performs an “off” for zwave lights. But (lazy), I’m still at .45. I’ll make an image of my card and upgrade and check things out at .47…

Under .47, it looks like Zwave is still behaving the same. Brightness=0 turns it off.

@ih8gates How would I adapt this to not change the brightness of a dimmer if it happens to already be on? My use case is the dining room chandelier where I want it to turn on dimply (30%) when someone triggers a motion/door sensor for 5-10 min and then turn off when no motion is detected. However, I don’t want it to adjust the level to 30% in the event that I’m having dinner in the room and the light is already on. Make sense?

Just add a condition to the automation. Where the “only at night” part is, add something that’s essentially “only if the light is off”.

1 Like

@ih8gates I’m a little confused as to what the does. I have a log error that states it can’t find this. Should I remove it?

Yup. Sorry - I had been experimenting with a check to see if the light had been changed by this motion sensing, or if it had just been turned on because of time-of-day, etc. So it’s not necessary here.

1 Like

@ih8gates did you ever build this part out? Where would I add this piece as I have a similar use case. Thanks again for all your help!

I never did. You could just create a boolean and then turn it on/off with the same actions that adjust the lights. Then address it with conditions.

But I didn’t really have a use-case for that. Since I’m returning it to its previous state, I didn’t really need to know how it’d been turned on.

@ih8gates did you upgrade to the newest version 0.51.2? I’m seeing that your script appears to no longer save the last light level anymore. Can you confirm?

I’m on vacation. And still running .49.1 - I’ll try to remember to report back when I update.

I’m just trying to do this now and a few mods.
“input_slider” is now “input_number”
and
“select_value” is now “set_number”

I’m just at work, so can’t test, but i think this is all that is needed to get this running on my 0.73.1

Hmm no dice. Tho I’m using mqtt home base lights, so storing just the brightness is prob not enough.
I’ll see if I can figure out away to achieve this as I use flashing my light red as a warning, but still wanna have them return to normal rather than off after the alert.

I’m still using the code above with no issues. On 0.73.1

No comment about the code discussed in this topic, since I really haven’t taken the time to digest it. But, if you’re looking for a way to save the state of lights and/or switches so that you can return them to the same state at a later time, you might be interested in this:

With MQTT Bruh sensor lights and Bruh Digital leds ?
I’m sure i could use it for the LiFx bulb.

Oooooo, i know what i’m doing today at lunch !

1 Like

No, but don’t they still have a brightness value? Shouldn’t the same idea still apply?

You could probably use service_template calls to handle the “turn_on with zero brightness = turn_off” question.

I don’t think i can just send brightness to them as they are RGB, so need the colour to turn on to.

I’ll give the python script a go, but thanks for replying to such an old thread.