Set light to dim then turn off if after a certain time


I have some lights that come on at the last brightness they were set at and a RF switch that can send an event to Home Assistant.

What I want to do is when the OFF button is pressed is the following (in pseudo code)

if( now() is after 7pm){
   ceiling light set brightness 30%
ceiling light turn OFF
side light turn OFF
wall light turn OFF

So this will mean that if it is early in the day we just turn all the lights off but if it is after 7pm then we will dim the ceiling light first then turn all the lights off. This means when we go in during the night the light and turn on the ceiling light it is nice and low and doesn’t wake her up.

How would I do this in an automation or a script? I could code it fairly easy in appdaemon but I’d rather have a scene or script that can be edited in the UI so others can update it.

    - service: light.turn_on
        entity_id: "{{ 'light.ceiling' if now().hour >= 7 else 'light.none' }}"
        brightness_pct: 30
    - service: light.turn_off
        - light.ceiling
        - light.side
        - light.wall

This works because the entity_id’s provided to the light.turn_on service don’t have to actually exist. So, if it’s 7 pm or later, have it turn on the ceiling light at 30%. If it’s not, then have it turn on a bogus light instead.

That is genius! Thanks I’ll try that out.

No problem. I can’t claim credit – I saw someone else do it. :slight_smile: