Move Lights in & out of Motion Automation On-Demand

Hoping to pick someone’s brain for different solutions for a simple workflow before I commit to building one.
• I have a bunch of motion sensors and have auto-lights working in main living areas of house.
• I’d like the ability to move lights in & out of the “auto/motion automation” on-demand.

The obvious solution is to create input_boolean switches (one for each light), have a separate entity card tucked away in a LoveLace tab so I can manually move each light in & out of the automation. The downside to this solution (in my opinion) is:
• I need to create a large QTY of switches and implement them all into my Node Red workflow.
• From a user perspective the switches are tucked away on another tab so could be frustrating to control?

Ultimately I think it’d make more sense if I could place the switch on the light-card itself (LIKE THIS) so I could just long press the picture-entity card for each light on my home screen to access the switch, but I’m told this isn’t possible.

Any suggestions? How are you guys moving lights in & out of motion sensing on-demand?

I use physical buttons to set the light mode: ON, OFF or AUTO. There are times when you don’t want to have to muck around with a GUI for a simple, quick task. This is one of those times

1 Like

Thanks, that’s a great idea! I have Xiaomi buttons so I can dedicate one of the three functions to this and use Google Home (or the light) to indicate auto-status when triggered. Thanks!

why do you want to do this?
You may want to have a look at the custom component entity controller. You can set overrides in this component.

1 Like

The Short Version: Sometimes we have guests or other scenarios where I’d like all the lights in the house to be automatic, except a select room.

The Long Version: In the kitchen we’re moving constantly and we don’t spend much time sitting in the living room. Downstairs, we have a chromecast & cinema, and our a table where we play board games with friends.
• Sometimes, we sit still in the Downstairs room - and the lights turn off. So I end up turning the auto-lights off (front page of my hass dashboard), then remember to turn them back on before my wife or I leave the room to rest of house.
• Sometimes we have guests and I’d like all the lights to be automated except in a specific room.
• I’d like my backyard lights to be automated but I won’t have motion sensors throughout the yard, so when we leave via the back door I can trigger the lights & LED strips on for X minutes. But other times we have guests and I want the lights to stay on.

etc

I use Xiaomi buttons as well. I’ll post my code

Then I would recommend you have a look at the entity controller (mentioned previous post). Easy to set up, you can use time constrains and override buttons/input_booleans, multiple trigger sensors and multiple lights to activate. And if you have turned on a light on manually the component ignores the light and doesn’t turn it off.

You do have to set up each room or area separately.

1 Like

this is a package, kitchen_light.yaml

#  All code relating to the functioning of the kitchen light

input_number:
  kitchen_light_auto_off_time:
    name: Kitchen light timer
    min: 1
    max: 9
    step: 1
    icon: mdi:camera-timer
    unit_of_measurement: min


automation:
  - alias: 'Kitchen Remote Button 1'
    initial_state: 'on'
    trigger:
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d0002241b37
          click_type: single
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d0002241b37
          click_type: double
      - platform: event
        event_type: xiaomi_aqara.click
        event_data:
          entity_id: binary_sensor.switch_158d0002241b37
          click_type: long_click_press

    action:
      - service_template: >
          {% if trigger.event.data.click_type == 'single' %}
            script.kitchen_button_single_click
          {% elif trigger.event.data.click_type == 'double' %}
            script.kitchen_button_double_click
          {% elif trigger.event.data.click_type == 'long_click_press' %}
            script.kitchen_button_long_press
          {% endif %}
          


  - alias: 'Kitchen light auto ON motion'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_multi_sensor_sensor
        to: 'on'
    condition:      # look at changing this to use room light level only
      condition: or
      conditions:
      - condition: sun
        after: sunset
        after_offset: '-00:10:00'
      - condition: sun
        before: sunrise
        before_offset: '-01:00:00'
      - condition: template
        value_template: '{{ states.sensor.kitchen_multi_sensor_luminance.state | int < 10 }}'
    action:
      - service: script.turn_off
        entity_id: script.kitchen_light_auto_off_timer
      - service: light.turn_on
        data:
          entity_id: light.kitchen_light_level



  - alias: 'Kitchen light auto off'
    initial_state: 'on'
    trigger:
      - platform: state
        entity_id: binary_sensor.kitchen_multi_sensor_sensor
    condition:
      condition: or
      conditions:
      - condition: sun
        after: sunset
        after_offset: '-00:10:00'
      - condition: sun
        before: sunrise
        before_offset: '-01:00:00'
    action:
      - service: script.turn_on
        entity_id: script.kitchen_light_auto_off_timer


script:
  kitchen_button_single_click:
    alias: Kitchen button single click
    sequence:
    - service: switch.turn_off
      data:
        entity_id: switch.circadian_lighting_kitchen_living_circadian_lighting
    - service: light.turn_on
      data:
        entity_id: light.kitchen_light_level
        brightness: 255
    - service: automation.turn_off
      data:
        entity_id: 
          - automation.kitchen_light_auto_on_motion
          - automation.kitchen_light_auto_off
  
  kitchen_button_double_click:
    alias: Kitchen button double click
    sequence:
    - service: light.turn_off
      data: 
        entity_id: light.kitchen_light_level
    - service: automation.turn_off
      data:
        entity_id: 
          - automation.kitchen_light_auto_on_motion
          - automation.kitchen_light_auto_off
  
  kitchen_button_long_press:
    alias: Kitchen button long press
    sequence:
    - service: switch.turn_on
      data:
        entity_id: switch.circadian_lighting_kitchen_living_circadian_lighting
    - service: automation.turn_on
      data:
        entity_id: 
          - automation.kitchen_light_auto_on_motion
          - automation.kitchen_light_auto_off
  
  kitchen_light_auto_off_timer:
    alias: Kitchen light off after preset time
    sequence:
    - delay: '00:0{{ states.input_number.kitchen_light_auto_off_time.state | int }}:00'
    - service: homeassistant.turn_off
      data:
        entity_id: light.kitchen_light_level
2 Likes

Config I use with entity controller (2 rooms as example);

entity_controller:
  upstairs:
    sensor: binary_sensor.motion_sensor_2
    entity_on: light.overlooplamp_2
    delay: 180
    backoff: true
    backoff_factor: 1.2
    backoff_max: 600
    service_data:
      brightness: 255
    night_mode:
      delay: 60
      service_data:
        brightness: 20
      start_time: '23:30:00'
      end_time: '07:00:00' 
    overrides:
      - binary_sensor.light_outside
      - input_boolean.motion_off
  hallway:
    sensor: 
      - binary_sensor.motion_sensor_3
      - binary_sensor.window_door_sensor
    entity_on: 
      - light.halllamp_1
      - light.halllamp_2
    delay: 180
    service_data:
      brightness: 255
    overrides:
      - binary_sensor.light_outside
      - input_boolean.motion_off

I’m keen to check this out in more detail. I saw it a couple of weeks ago but the documentation didn’t seem straight forward. I guess though that you still need more code to set the input_boolean.motion_off from a physical switch / button? or do you not have a non-gui way to turn off the motion control? That was the point of mine, I didn’t want to have to find a phone or tablet just to force the light to stay on

I agree the documentation looks very difficult, but you can just ignore everything about the “state machine” as it discribes the inner workings. You don’t need to understand that for the component to work.

yes, this is just a switch I can use to turn off all motion related events in my house.

input_boolean: 
  motion_off:
    name: Disable motion sensors
    initial: off

You don’t need to with this component! If you turn on a light yourself (by pressing a button, using a automation or in any other way), entity controller will NOT turn it off.

but this is only a gui switch.

I understand that, but there still must be code somewhere to integrate said physical switch into HA. For this, I would still need code to tell HA I had pressed the Xiaomi button. What physical light switches are you using?

What do you mean? Yes it’s just a gui switch, but if you look at the config I posted it’s listed as an override. So no more logic is needed. You can use a physical switch as override too, or a sensor.

True. For HA to use a physical switch you’ll have to integrate it ofcourse. I use a mixture of z-wave (fibaro), zigbee(hue and xiaomi) and wifi (shelly)

Just that this ‘switch’ is only available if you use your phone / computer / tablet etc.

Don’t get me wrong, I like the setup and definitely plan to look into it further. I have a heap of wifi bulbs, so they have no physical switch (other than completely turning the power off to them) hence I use the Xiaomi buttons, but I also have some z-wave dimmers. I need to see if I can utilise those a bit better once I move house. (i have been limited due to being in a rental, so can’t hard-wire)

But you can use this too.

  • Integrate the button in HA (don’t attach it to anything)
  • use it as an override in entity controller
  • done :slight_smile:

Yeah, I will for the wifi lights. Hopefully use entity controller with zwave dimmers elsewhere as well