Standard motion light with delay but with return to previous dim level

I am giving HA a test run to replace another GUI-driven solution that was abandoned by the providing company without warning. I’m trying to test key functionality quickly while I also have to learn a new, and more technically demanding, platform.

I have a number of Insteon switches that control various outside lights (flood lights, porch lights, etc). Here are the main functions Currently:

A) At 15 minutes before sunset, these lights come on to various preset levels (eg, back flood 20%, side floods 35%, front porch lights 35%).

B) At a preset time (eg, 11:00PM), these lights dim to lower various preset levels (eg, back floods 12%, side floods 20%, front porch lights 18%).

C) At 15 minutes before sunrise, they turn off.

Any time between A and C, if motion is detected on a handful of outdoor motion detectors, all outdoor lights go to 100% for as long as any motion is detected, and for 5 minutes after last motion. They then return to their previous dim level.

Any change in levels (eg, from dim 35% to 100% and back) is done in a nice ramp over a couple seconds. This was an Insteon switch controller value settable via the old program.

This control was easily accomplished in the old control program.

I checked out the “Sensor Light” blueprint by blackshome, which looks like it can do some, but not all, of this.

Is this possible in HA and, if so, can someone help me actually do it? I will learn over time but I am in a bind to make a new software decision quickly due to the sudden dropping of the current by the maker and this capability is a key safety and security one.

With any automation in HA there are many ways it can be accomplished, and the “best” way is dependent upon the preferences and knowledge level of the person implementing it.

To your question of whether it is possible, of course it is possible. You could do this with scenes, or input helpers, or template sensors, or just within a single automation without any extra pieces. I would do it all inside one automation so I will describe that method.

Before doing that, let’s work through dimming. Performing a dimming transition of a few seconds is easy if it is supported by both your hardware and the integration you’re using. To test this out, go to developer tools → actions, pick light.turn_on from the dropdown, then “pick choose entity” and select your outdoor light entity from the list. If your integration supports it, options for both “transition” and “brightness” will appear. Test those out and see if you can get your lights to behave like you want them to. A tip here is that you get the action that you want, you can switch to YAML mode and copy the code and paste it into your automation.

Next task, to make your automation more simple, is to create a group for your outdoor motion sensors. This way they essentially behave as one detector. In the UI go to devices & services → helpers → create a helper → group → binary sensor group. Pick all your outdoor motion sensors and give this a name like “outdoor motion sensors”.

Ok, assuming you figured out the dimming transition and the group, this is what I would recommend for an automation. What I will describe is an automation that can be triggered by many different things, and then we’ll use a choose block to pick the appropriate actions depending on which conditions are currently met. The choose block is essentially an if-elseif with as many elseif’s as you want. They will be evaluated in order and only the first matching one will be ran.

Triggers:

  • Sun trigger, using sunset with an offset specified of either -900 or -00:15:00
  • Time trigger of 11:00pm
  • State trigger of your outdoor motion sensor group going from off to on
  • State trigger of your outdoor motion sensor group going from on to off and staying off for 5 minutes
  • Sun trigger, using sunrise with an offset specified of either -900 or -00:15:00

Conditions:

  • Sun condition, using after sunset with an offset specified of either -900 or -00:15:00, and also using before sunrise with an offset specified of either -960 or -00:16:00

Actions:
The first and only top-level action is a choose block. Here are the items in that block:

  • option 1
    • conditions:
      • sunset: after sunrise with an offset specified of either -900 or -00:15:00
    • actions:
      • light.turn_off for all outdoor lights
  • option 2
    • conditions:
      • state: outdoor motion sensor group is on
    • actions:
      • light.turn_on for all outdoor lights, set to max brightness with a 3 sec transition
  • option 3
    • conditions:
      • time: after 11pm
    • actions:
      • a separate light.turn_on action for each set of lights that needs a unique brightness level, and use a 3 sec transition for each action. These are the 11pm light levels.
  • default option
    • actions:
      • a separate light.turn_on action for each set of lights that needs a unique brightness level, and use a 3 sec transition for each action. This would be the light level they turn on around sunset.

Hopefully this makes sense.

Most of what you want to do can be done using scenes.
To access scenes go to Settings > Automations & Scenes > Scenes tab > Click add scene
From here all you need to do is put your devices in their desired state, add them to the scene list, give your scene a name, and click save.
Now anytime you activate the scene it will return your devices to the state they were in when you created the scene.

1 Like

Thanks, mekaneck! I don’t think I would have realized logic trees like this could be built in the GUI portion without a lot of trial and error time I don’t have.

I have set up a test environment with one motion and a couple light modules to verify the basic functionality works. I will see if it works as expected this evening.

I tried several different Insteon modules that I know for sure can natively do the dimming transition via any normal Insteon HW/SS. In the developer tools as you directed, it only shows brightness – no transition. So, I’m scratching my head a bit on that one. It does looks like HA is detecting the Insteon module model numbers correctly. Dimming transition isn’t a major problem in this particular automation, but there are others where it’s really nice to have (eg, a “goodnight” slow dim to 0% over 60 seconds in bedrooms).

I don’t use Insteon, but I found a relevant post from Tom Harris, the maintainer of the Insteon integration. It appears that the transition is a feature that is not yet supported.

1 Like

The automation doesn’t seem to be working. I’ve been trying to troubleshoot and it appears that having time based triggers/chooses don’t work, and somehow might be causing others (eg, motion) to not work.

Here’s the YAML (I have not edited anything here, only in visual editor). Note, the extra trigger is just something I’ve tested with – the automation also doesn’t ever turn on the lights with or without that trigger. I can’t figure out what I’m missing? Running through this as a sort of flowchart, it seems like all of them should be working but in fact, none are.

alias: Test Outdoor Light Night Automation
description: “”
triggers:

  • trigger: sun
    event: sunset
    offset: “-00:15:00”
  • trigger: time
    at: “23:00:00”
  • trigger: state
    entity_id:
    • binary_sensor.outdoor_motion_sensor_group
      from: “off”
      to: “on”
  • trigger: state
    entity_id:
    • binary_sensor.outdoor_motion_sensor_group
      from: “on”
      to: “off”
      for:
      hours: 0
      minutes: 5
      seconds: 0
  • trigger: sun
    event: sunrise
    offset: “-00:15:00”
  • trigger: time
    at: “20:08:00”
    conditions:
  • condition: sun
    before: sunrise
    before_offset: “-00:16:00”
    after: sunset
    after_offset: “-00:15:00”
    actions:
  • choose:
    • conditions:
      • condition: sun
        after: sunrise
        after_offset: “-00:15:00”
        sequence:
      • action: light.turn_off
        metadata: {}
        data: {}
        target:
        entity_id: light.outdoor_lights
    • conditions:
      • condition: state
        entity_id: binary_sensor.outdoor_motion_sensor_group
        state: “on”
        sequence:
      • action: light.turn_on
        metadata: {}
        data:
        brightness_pct: 100
        target:
        entity_id: light.outdoor_lights
    • conditions:
      • condition: time
        after: “23:00:00”
        weekday:
        • sun
        • mon
        • tue
        • wed
        • thu
        • fri
        • sat
          sequence:
      • action: light.turn_on
        metadata: {}
        data:
        brightness_pct: 30
        target:
        entity_id: light.outdoor_lights
        default:
    • action: light.turn_on
      metadata: {}
      data:
      brightness_pct: 50
      target:
      entity_id: light.outdoor_lights
      mode: single

You’ll need to format your code properly otherwise I can’t really help.

Also check out the documentation for troubleshooting automations. If the automation is triggering but not running the actions that you think it should run, you can look at the trace to see where things are going wrong. If you can’t figure it out, download the trace file and paste the text (formatted as code) in this thread.

Ok, I’ve gotten more up to speed on automations and through trial and error have gotten everything working except for the sunset/sunrise.

How do I use a sunset/sunrise based trigger in conjunction with a choose tree condition? If I set a trigger of when sun sets offset by -00:15:00 and a Choose with Option Confirm sun before sunset offset by -00:15:00, the trigger portion fires but the Choose Option does not. What am I missing?

If your trigger is when something happens, the condition needs to be when it is after that thing happening.

Also be aware you can add an id to each trigger, and you can create a condition for when the automation was triggered by that id

I’ve gotten it all working except I’m having a brain fart and can’t figure out getting it to turn off around sunrise. Can you confirm or explain exactly how the offset part of sunrise/sunset works? For simplicity, say the sun rises at 8:00 AM. If the TRIGGER is when sun rises offset by -00:01:00, is that 7:59 AM or 8:01 AM? Does that also apply to And If and Choose statements which both have slightly different wording?

So if I want off fifteen minutes before the sun rises, should it be:
TRIGGER when sun rises offset by -00:15:00
AND IF Confirm before sunrise
THEN DO
CHOOSE Confirm before sunrise by -00:16:00

That doesn’t seem to work – the light or group remains on.