Stop motion automation if I manually press the light switch

Hi all, struggling to find a solution & I’m new to automation in HA. My motion lights work great, however, if I then turn the light on manually which is set to 100% (auto is 5%), the lights go off after motion changes from detected to clear.
I have seen reference to a boolean, but unsure how to set this helper up and intergrate?

{{ input_boolean.use_sensor_state == 'on' and binary_sensor.motion_sensor == 'on' }}

My automation yaml is as per the below

alias: Back Porch Light
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.ewelink_snzb_03_ias_zone
    to: "on"
    from: "off"
conditions:
  - condition: or
    conditions:
      - condition: device
        type: is_on
        device_id: d3e5461b988666233ed92619bc98bddb
        entity_id: 2737de9f611879e282b75d4a4771300d
        domain: light
      - condition: device
        type: is_on
        device_id: f5d0cb05bea5d74c8b3c04f0c6a77b9a
        entity_id: 7ad271c865a94538f16bb610d7a6ecd8
        domain: light
actions:
  - alias: Turn on the light
    action: light.turn_on
    target:
      entity_id: light.back_porch
    data:
      brightness_pct: 100
  - alias: Wait until there is no motion from device
    wait_for_trigger:
      - trigger: state
        entity_id:
          - binary_sensor.ewelink_snzb_03_ias_zone
        to: "off"
        from: "on"
    continue_on_timeout: false
    timeout:
      hours: 0
      minutes: 30
      seconds: 0
  - alias: Wait the number of seconds that has been set
    delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - alias: Turn off the light
    action: light.turn_off
    data: {}
    target:
      entity_id: light.back_porch
mode: restart
max_exceeded: silent

can you give some more info?
should the motion sensor only be active when you haven’t manually turned it on?
the switch to manually turn the light on, is this a real switch or a helper?
when the light turns on, should it always be 100% brightness?
when it’s off, should it be 0% or 5%?

1.Motion sensor is always active.
2.The switch is a 4 way wireless zigbee.
3.Light turns on if the back porch motion sensor is activated to 100% & either dining room or living room light is on, I have a second automation that uses dusk to dawn and is limited to 5% for the kids in the night, if all lights are off.

So if the lights are activated by the sensor before sunrise they are 5%, I would then manually use the zigbee switch to turn it off/on to 100%.
After the automation senses no motion, all 3 lights in the yaml go off, regardless if I changed it to 100%,completing the automation.

Ohhh. I hadn’t even considered that! I had already created input_boolean helpers to set motion/presence overrides for my remotes but not yet got around to implementing that in my automations, but as I take it that shouldn’t even be necessary. Instead the motion/presence automation when it come times to turn off the light should check whether it was the one who turned it on.

Hmm. The state machine does not record “new” states which are the same as the “old” state though, so I still need to figure out how to set a “new” state when the remote is pressed but the light is already on… any hints on how to do this or suitable workarounds?

Here was me hoping for a quick fix :slight_smile: , cheers Tom, I will read into this. I’m new to HA & still getting my teeth into it.

what if you use an if then else as below? (to combine both automations)
Also note that I changed the motion trigger from off to on, it was reversed in your automation.

alias: Back Porch Light
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.ewelink_snzb_03_ias_zone
    from: "off"
    to: "on"
conditions: []
actions:
  - if:
      - condition: sun
        before: sunset
        after: sunrise
      - condition: or
        conditions:
          - condition: device
            type: is_on
            device_id: d3e5461b988666233ed92619bc98bddb
            entity_id: 2737de9f611879e282b75d4a4771300d
            domain: light
          - condition: device
            type: is_on
            device_id: f5d0cb05bea5d74c8b3c04f0c6a77b9a
            entity_id: 7ad271c865a94538f16bb610d7a6ecd8
            domain: light
    then:
      - action: light.turn_on
        target:
          entity_id: light.back_porch
        data:
          brightness_pct: 100
      - wait_for_trigger:
          - trigger: state
            entity_id:
              - binary_sensor.ewelink_snzb_03_ias_zone
            from: "on"
            to: "off"
        continue_on_timeout: false
        timeout:
          hours: 0
          minutes: 30
          seconds: 0
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
      - action: light.turn_off
        target:
          entity_id: light.back_porch
        data: {}
    else:
      - action: light.turn_on
        target:
          entity_id: light.back_porch
        data:
          brightness_pct: 5
      - wait_for_trigger:
          - trigger: state
            entity_id:
              - binary_sensor.ewelink_snzb_03_ias_zone
            from: "on"
            to: "off"
        continue_on_timeout: false
        timeout:
          hours: 0
          minutes: 30
          seconds: 0
      - delay:
          hours: 0
          minutes: 1
          seconds: 0
      - action: light.turn_off
        target:
          entity_id: light.back_porch
        data: {}
mode: restart

1 Like

I have connected my risco alarm motion detector so when it detects movement a light turns on.
When I manually press the light switch automation is deactivated in order to keep the light on.
After switching back to off the light, automation reactivates.
Here is how I did it:

alias: Risco Radar Z7 Disabling Light Automations on Manual Button Press
description: ""
mode: single
triggers:
  - entity_id: switch.sonoff_xxxxxxxxxx
    variables:
      id: "{{trigger.to_state.context.id}}"
      parent: "{{ trigger.to_state.context.parent_id }}"
      user: "{{ trigger.to_state.context.user_id }}"
    trigger: state
conditions:
  - condition: template
    value_template: "{{ (id!=None, parent, user) == (true, None, None) }}"
actions:
  - if:
      - condition: state
        entity_id: input_boolean.manual_button_light_saloni
        state: "off"
    then:
      - target:
          entity_id:
            - automation.radar_z7_light_on
            - automation.risco_radar_z7_triggers_light_off
        data:
          stop_actions: true
        action: automation.turn_off
      - data: {}
        target:
          entity_id: input_boolean.manual_button_light_saloni
        action: input_boolean.turn_on
    else:
      - if:
          - condition: state
            entity_id: input_boolean.manual_button_light_saloni
            state: "on"
        then:
          - target:
              entity_id:
                - automation.radar_z7_light_on
                - automation.risco_radar_z7_triggers_light_off
            data: {}
            action: automation.turn_on
          - target:
              entity_id: input_boolean.manual_button_light_saloni
            data: {}
            action: input_boolean.turn_off
2 Likes

Do you have screenshots of how you set this up in the UI, not the yaml?
Also how do I setup a boolean?

This looks like the solution I’m after

DMF1986,

  1. Copy the YAML from Jolas, then create a new, empty automation from scratch.
  2. Click the 3 dots (upper right corner), select EDIT IN YAML.
  3. Now select/delete the YAML you see, then paste Jolas’ YAML in it.
  4. Go back to the 3 dots and select EDIT IN VISUAL editor.

With that, you should see how each aspect of the YAML in the visual User Interface relates.

Definitely maybe, anyways. :slight_smile:

1 Like

Also, don’t forget to change entity_id: switch.sonoff_xxxxxxxxxx with your switch.
Also you need to make a boolean input_boolean.manual_button_light_saloni or whetever you call it (just rename it in automation too)

That is genius.

I’m off to have a play :grin:

What does the below refer to in your yaml please

                - automation.radar_z7_light_on
                - automation.risco_radar_z7_triggers_light_off

These are the automations to deactivate on manual button press

Hi Tom, this seems to refer to scenes, however I have my lights setup against automations. Would it be better if I used scenes and not automations for the result I’m trying to achieve

No it is for automations. Scenes don’t have triggers.