Hue Motion Detector Automation and Hue Wall Switch

Hello everyone,

Fairly new to Home Assistant and especially to the automation part, I’m encountering a problem that I can solve theoretically but can’t apply.

To be as informative as possible, here are the devices concerned:

  • 1 Hue motion detector
  • 1 Hue Wall Switch

1. Hue motion detector

It performs an automation when it detects movement: turning on the light for 1 minute on a particular scene.

2. The Hue Wall Switch

Turns the light on or off in another specific scene. Simple ON/OFF switch

3. The Goal

When it’s dark, the motion detector turns the lights on at low brightness for one minute (repeatable in the event of movement). However, if I need more light, I use the Wall Switch to switch the lights on as normal.

4. The problem

If the motion detector turns on the lights, if I turn them off with the Wall Switch and then turn them on to get full brightness, the lights cut out at the end of the motion detector automation. Which is logical…

How can I stop the automation when this change of state occurs? I’ve read a lot about scene persistence and the problems associated with it. I’ve also read about the possibility of using a helper to set the current status, but I don’t have a concrete example.

Any help ?

alias: "Bathroom"
description: >-
Formatted
trigger:
  - platform: state
    entity_id:
      - binary_sensor.hue_motion_sensor_1_move
    to: "on"
    enabled: true
    id: Move
condition:
  - condition: state
    entity_id: light.bathroom
    state: "off"
    for:
      hours: 0
      minutes: 0
      seconds: 1
action:
  - if:
      - condition: trigger
        id: Move
    then:
      - if:
          - condition: or
            conditions:
              - condition: sun
                before: sunrise
                before_offset: "01:00:00"
              - condition: sun
                after: sunset
                after_offset: "-01:00:00"
        then:
          - alias: Scene Switch
            service: scene.turn_on
            target:
              entity_id: scene.bathroom_chill
  - alias: Trigger part
    wait_for_trigger:
      platform: state
      entity_id: binary_sensor.hue_motion_sensor_1_move
      from: "on"
      to: "off"
    continue_on_timeout: true
  - alias: Waiting Zone
    delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - alias: Turn Off
    service: light.turn_off
    target:
      entity_id: light.bathroom
mode: restart
max_exceeded: silent

My easiest theory would be to take a snapshot before and after to compare them but i’m aware the created scenes doens’t persist so it a no go.

Second is : If there is a change of state while the automation, don’t apply the Turn Off function…

I’m kinda lost :stuck_out_tongue:

Add a condition that the Hue Wall switch has been “off” for x minutes?
Or is the light and the wall switch the same entity?

Hey. Thanks for your quick answer.

The Hue Wall Switch don’t return an On/Off position. When pressed, the hue bridge switch from state On to Off (and vice versa) so i can’t rely on this on since he don’t have a status as his own.

Right Now i’m trying to create an automation to get the status of the wall switch based on the lights status.

You mean it’s an event?
You can position a binary_sensor with the last state through an automation or

Yup, that’s an event.

BATHROOM éteint 11:01:10
HUEWALLSWITCH a détecté un événement 11:01:10
STATUS déclenché par l'état de Hue wall switch SdB Button 1 11:01:09
HUEWALLSWITCH a détecté un événement 11:01:09
STATUS déclenché par l'état de Hue wall switch SdB Button 1 11:00:57
BATHROOM allumé 11:00:57
HUEWALLSWITCH a détecté un événement 11:00:57
HUEWALLSWITCH a détecté un événement 11:00:56

HUEWALLSWITCH is the Hue Wall
BATHROOM is the Hue Lights Group
STATUS is an automation where i try to get the current status of the switch.

I looked at the custom sensor github but i would try to keep it as simple as possible whitout installing and interfering in my global HA installation if possible. Still, seems a great tools. Maybe when i’ll be more experienced :smiley:

Edit : and i really don’t know why state is send 2 times…

You have the “down” and “up” events each time

1 Like

I think i’ll try helpers.

I created a simple helper with two options for now. “Offline” and “Online”.

Then i created 2 automations to check light status and apply the Offline or Online state to the helper

alias: Bathroom is On
description: ""
trigger:
  - platform: state
    entity_id:
      - event.hue_wall_switch_module_1_button_1_11
    attribute: event_type
    from: short_release
condition:
  - condition: state
    entity_id: light.bathroom
    state: "off"
action:
  - service: input_select.select_option
    target:
      entity_id:
        - input_select.bathroom_scenes
    data:
      option: Online
mode: single

since the switch is pressed, i check the light as off since they will go ON.

Did the same with light on → switch → status Offline as below

alias: Bathroom is Off
description: ""
trigger:
  - platform: state
    entity_id:
      - event.hue_wall_switch_module_1_button_1_11
    attribute: event_type
    from: short_release
condition:
  - condition: state
    entity_id: light.bathroom
    state: "on"
action:
  - service: input_select.select_option
    target:
      entity_id:
        - input_select.bathroom_scenes
    data:
      option: Offline
mode: single

Not really happy having 2 automations basically doing the same things. Any method to regroup ?

Ok, as for now, i think i can call this case closed.

For whoever find this topic, here’s the trick :

1. Create a Helper with multiple choice :

In my case :

  1. Offline
  2. Online
  3. Motion

2. Apply automation to the Hue Wall Switch (code on last post) to determine if lights are on or off

This will define the Helper to either ‘Offline’ or ‘Online’

3. On the motion sensor automation

Apply the ‘motion’ status to the helper at the start.

Check if the helper status changed before turning the light Off.

Setting the option at start :

          - service: input_select.select_option
            target:
              entity_id:
                - input_select.bathroom_scenes
            data:
              option: Motion

Verifying before turning the light off :

  - if:
      - condition: state
        entity_id: input_select.bathroom_scenes
        state: Motion
    then:
      - alias: Turn the lights off
        service: light.turn_off
        target:
          entity_id: light.bathroom
        data: {}
      - service: input_select.select_option
        target:
          entity_id:
            - input_select.bathroom_scenes
        data:
          option: Offline

Thanks @koying for your input !