Using Shelly Motion to automate turning on lights?

Hi,

Does anybody know the best way to set up a Shelly Motion to use for motion detection for lights?

Basically, say you want the lights on at 10% normally, but when the motion detection is triggered, you want it to ramp up to say 100%, then back down to 10% after 5 minutes.

Is there some way to do this natively in Home Assistant?

If the Shelley Motion signal is available to HA then it’s just a regular automation with it as the trigger.

Here is a simple automation via shelly motion.

  alias: Study Lights On via Motion
  description: Control Study Lights with Shelly Motion Detection
  trigger:
  - platform: state
    entity_id: binary_sensor.shellymotionsensor
    to: 'on'
  condition:
  - condition: device
    type: is_off
    device_id: xxxxxxxxxxxx
    entity_id: light.study_cans
    domain: light
  action:
  - service: light.turn_on
    target:
      entity_id: light.study_cans
    data:
      brightness: 159
  mode: single

Oh neat - thank you! The example really helps.

I just noticed there’s also an included Blueprint in Home Assistant as well, which I believe does something similar:

One note is that the blind time set on the actual Motion Shelly still applies as well.

In our case, say we wanted the lights at 10% by default, then ramp up to 100% on motion, then go back to 10% after 5 minutes.

  1. Your condition has is_off - condition is optional right? So could we simply remove this part, if we didn’t care if the lights are already off?
  2. How do we time-out the lights back down to 10% after 5 minutes? Is there something we’d add here, or do we need to figure out some other second automation for that?
  1. Correct - condition[] would replace it

  2. See below for adding it into a single automation. You can do two and it may simplify you maintenance. It is up to you. You can add off to the trigger and add a second option on the action choose

alias: Lights On via Motion
description: Control Lights with Shelly Motion Detection
trigger:
  - platform: state
    entity_id: binary_sensor.shellymotionsensor
    id: off_to_on
    to: 'on'
  - platform: state
    entity_id: binary_sensor.shellymotionsensor
    id: on_five
    to: 'on'   <--- change to 'off' if you want no motion for 5 minutes to go to 10%
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: off_to_on
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.your_light
            data:
              brightness_pct: 100
    default:
      - service: light.turn_on
        target:
          entity_id: light.your_light
        data:
          brightness_pct: 10
mode: single
1 Like

@AllHailJ - Thanks for your help!

I can confirm I have this working, here is my current code for anybody else:

alias: New Automation
description: ''
trigger:
  - platform: state
    entity_id: binary_sensor.shellymotionsensor_60a423beb6c4_motion
    id: off_to_on
    to: 'on'
  - platform: state
    entity_id: binary_sensor.shellymotionsensor_60a423beb6c4_motion
    to: 'off'
    id: no_motion_for_five_minutes
    for:
      hours: 0
      minutes: 1
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: off_to_on
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.living_room_lights
            data:
              brightness_pct: 100
    default:
      - service: light.turn_on
        data:
          brightness: 35
        target:
          entity_id: light.living_room_lights
mode: single

Two things I noticed:

  • For the Shelly Motion, during the blind time (minimum 1 minute on the device), the binary sensor in HA is still set to “On” (even if there is no motion). So this means if you want 5 minutes for no motion - then you should configure the automation for 4 minutes (plus the 1 minute of blind time).
  • If you edit the YAML manually in HA an automation (three dots in top right, Edit in YAML), any changes you make won’t take effect until you manually reload the Automations configuration (Configuration, Server, YAML Configuration reloading). Even doing this, for some reason, it didn’t always reload - although opening up the automation in GUI mode, and moving a slider/value there seemed to get it to reload all the time.

One idea I had was to base this on time of day - so e.g. from 09:00 to 17:00 hrs, motion would cause it to turn on to say 100%, but rom 17:00 to 0:00 and 0:00 to 09:00, it would only turn on to 80%.

@AllHailJ Am I right in thinking that condition: is the right place to set this - but that I will need to split this up into two separate automations?

Or is there some way you can see to do this in one automation? (I think it would reduce copy/pasting code to do it in one automation, so that’s reduces maintenance in one sense - but not sure if it reduces code readability…)

I believe you can accomplish in one by adding the extra condition. You could also do a trigger sensor and have the sensor be whatever percentage you wanted at the time you wanted and then use a template for the brightness.

     - conditions:
          - condition: trigger
            id: off_to_on
          - condition: time
            after: '09:00:00'
            before: '17:00:00'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.living_room_lights
            data:
              brightness_pct: 100
     - conditions:
          - condition: trigger
            id: off_to_on
          - condition: time
            after: '17:00:00'
            before: '09:00:00'
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.living_room_lights
            data:
              brightness_pct: 80