Presence Lighting Logic question

I’ve been very happy with my simple automation to turn my studio lights on and off based on 1x mmwave sensor.
This includes 2x lamps in the ceiling fan and a desk lamp that automatically turn on when you enter and off when you leave.
1x closet light that is manually turned on and turns off with the presence automation.

I just added an overhead worklight and do not want it to turn on every time I walk in, but instead only if I come back into the room within say 15 min of leaving.

I believe the best way to achieve this is with scene.studio_light_states
I can just record the scene with the off automation and recall it with the On, however im not sure how to test if the scene was created within my reentry window.

And at this point I figured it might be nice to see if this is a good direction to be heading or if there is something I should look into!

I also use adaptive lighting for everything in this room so I really just need/want on/off states, I do not need brightness or color attributes which I believe can be adjusted in the scene record settings.

Welcome to the forum. Note that scenes don’t have an on/off state. They are fire & forget, which will lead to complications.

Having said that, what you want seems straightforward enough to do via an automation. Post your current automation (formatted correctly as per pinned post) & post the entity ID of your worklight. We can help you figure out the rest

If your closet has a door, I would suggest buying a contact sensor.
Then your condition to turn the light on is:

  • The door is open (and)
  • There is someone in the office

Hence if you close the door or leave the office the closet light goes out.


For your work-light - I have to read between the lines, I assume that:

  • On a given day the first time you turn it on it will always be manual.
  • If you leave the room you want it to turn off.
  • If you return within 15 minutes you want it to come on automatically.
  • Otherwise the other lights in the room will turn on, but not the work light.

For the work-light, create an automation, that:

  • Trigger: When you return to the room.
  • Condition: That the work-light is off. (and)
  • Condition: The last state change of the light was less than 15 minutes ago.
  • Action: Turn on the light.

Note the check for last change would be a template, something like this:

{{ ((now() - states.light.worklight.last_changed).total_seconds() | int) < 900 }}

Your post implies that you are doing this with a single automation. You can have more than one… :grin:

light.work_light is the new device

alias: Studio Presence Lighting
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.studio_presence_sensor
conditions:
  - condition: state
    entity_id: switch.adaptive_lighting_sleep_mode_office_rhythm
    state:
      - "off"
actions:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.studio_presence_sensor
            state:
              - "on"
        sequence:
          - choose:
              - conditions:
                  - condition: state
                    entity_id: scene.studio_light_states
                    state: []
                sequence: []
            enabled: false
          - action: light.turn_on
            metadata: {}
            target:
              entity_id:
                - light.studio_lights
                - light.desklamp
            data:
              transition: 2
      - conditions:
          - condition: state
            entity_id: binary_sensor.studio_presence_sensor
            state:
              - "off"
          - condition: state
            entity_id: binary_sensor.studio_occupancy
            state:
              - "off"
            enabled: false
        sequence:
          - delay:
              hours: 0
              minutes: 0
              seconds: 15
              milliseconds: 0
          - action: scene.create
            metadata: {}
            data:
              scene_id: studio_light_states
              snapshot_entities:
                - light.studio_lights
                - light.desklamp
                - light.work_light
          - action: light.turn_off
            metadata: {}
            target:
              entity_id:
                - light.studio_lights
                - light.desklamp
                - light.closet_0_10_v_dimmer
                - light.work_light
            data:
              transition: 2
          - if:
              - condition: state
                entity_id: binary_sensor.studio_occupancy
                state:
                  - "off"
            then:
              - action: light.turn_off
                metadata: {}
                target:
                  entity_id: light.closet_0_10_v_dimmer
                data: {}
            enabled: false
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
    enabled: false
mode: restart

I think you are on the right track!

{{ ((now() - states.scene.studio_light_states.last_changed).total_seconds() | int) < 900 }}

This tests in the developer tools as expected, but I get lost in yaml easily and the visual automation builder doesn’t make it clear to me how to do an chooser based on if the scene was updated within the last 15 min or not
This is where I’m at, but I don’t think that “last_changed” is a state…

choose:
  - conditions:
      - condition: state
        entity_id: scene.studio_light_states
        state: []
    sequence:
      - action: scene.turn_on
        metadata: {}
        target:
          entity_id: scene.studio_light_states
        data: {}
  - conditions: []
    sequence:
      - action: light.turn_on
        metadata: {}
        target:
          entity_id:
            - light.studio_lights
            - light.desklamp
        data: {}
enabled: true