Help need to automate Hue lights with Shelly Motion at night

Hello,

I am new to Home Assistant running my HA instance on Raspi4 with SSD and get into automation now after adding lots of my devices mainly focusing on lights, relays, motion and door locks.

I wanted to create my first automation today with the following devices to trigger and action, when environmental lighting is low (night so around <50lux) and from times (22:00 - 06:00a.m.).

The triggering action would be a Shelly Motion 2 movement which then should turn on 2 Hue lights (Iris and Go) in my floor during dark and night.

I created the automation which probably should work but I am struggling with the following challenges:

  • How to turn of the light when Shelly Motion doesn’t report any motion anymore after 1-2minutes?
  • How to make sure that the automation is triggered during certain times, ideally on certain days, so in my case between 22:00 - 06:00a.m. next day. This should be reoccuring so multiple on/off actions on lights should be executed?

I am a bit confused with the on (should work) and off (no idea how to do this) automations and also with the delay of turn off so lights don’t go immediately off when Shelly Motion 2 doesn’t report motion anymore.

Same applies to the timing question to make sure only nighttimes are taken into consideration!?

Attached is my current ON action but now the rest of the workflow has to come… Any help warmly appreciated…

Sorry it’s German but very simple automation as of now…

There’s a stock blueprint that does this, but you can do something like this, using the concept of holding a state:

trigger:
  - platform: state
    entity_id: binary_sensor.whale_motion
    to: 'on'
action:
  - service: light.turn_on
    entity_id: light.petunia

  - wait_for_trigger: 
    - platform: state
      entity_id: binary_sensor.whale_motion
      to: 'off'
      for: '00:02:00'
  - service: light.turn_off
    entity_id: light.petunia

With a time condition

trigger:
  - platform: state
    entity_id: binary_sensor.whale_motion
    to: 'on'
condition:
  - condition: time
    after: '22:00:00'
    before: '06:00:00'
action:
  - service: light.turn_on
    entity_id: light.petunia

  - wait_for_trigger: 
    - platform: state
      entity_id: binary_sensor.whale_motion
      to: 'off'
      for: '00:02:00'
  - service: light.turn_off
    entity_id: light.petunia
1 Like
alias: Bewegung Wohnzimmer Nachts
description: >-
  Bei Bewegung im Wohnzimmer vom Shelly Motion 2 erkannt bei Dunkelheit (<50lux)
  schalte Hue Iris und Hue Go auf 75% ein.
trigger:
  - type: motion
    platform: device
    device_id: 35af0507d777e3e54c8c660d6a7cc99d
    entity_id: binary_sensor.shelly_motion_wohnzimmer_motion
    domain: binary_sensor
condition:
  - condition: numeric_state
    entity_id: sensor.shelly_wohnzimmerture_luminosity
    below: 50
  - condition: time
    after: "21:00:00"
    before: "07:00:00"
action:
  - type: turn_on
    device_id: f16d16dc9103395b6981c49b555ce48d
    entity_id: light.hue_iris_1
    domain: light
    brightness_pct: 75
  - type: turn_on
    device_id: 78da407a271c0ecaafa2ff563df42a36
    entity_id: light.hue_go
    domain: light
    brightness_pct: 75
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - if:
      - type: is_no_motion
        condition: device
        device_id: 35af0507d777e3e54c8c660d6a7cc99d
        entity_id: binary_sensor.shelly_motion_wohnzimmer_motion
        domain: binary_sensor
    then:
      - type: turn_off
        device_id: f16d16dc9103395b6981c49b555ce48d
        entity_id: light.hue_iris_1
        domain: light
      - type: turn_off
        device_id: 78da407a271c0ecaafa2ff563df42a36
        entity_id: light.hue_go
        domain: light
    else:
      - delay:
          hours: 0
          minutes: 0
          seconds: 30
          milliseconds: 0
mode: single

This is what I did, should normally be similiar to @Tinkerer’s YAML setup but a bit more complex I guess.

Yours:

  1. Turns on two lights
  2. Waits two minutes
  3. If there’s currently no motion, turns off the lights
  4. Otherwise waits 30 seconds (and does nothing)

It is likely to leave the light on instead of turning it off.

1 Like

Hi gessi, this is somewhat off topic, but you seemed to have managed to get a Shelly Motion 2 recognized by HA. There’s a few topics in this forum about this, but no easy solution. How did you implement it?