#Code check please.

1 messages · Page 1 of 1 (latest)

ashen crow
#

Goal 1 - 30 minutes after sunset i would like the light to come on at 25% brightness. The light should stay on until 23:00.

Goal 2 - additionally i would like to trigger the light to reach 100% brightness when a Hue PIR detects motion. The light should remain on for 15 seconds then return to the previous state as per the conditions in goal 1.

automation:

  • id: outdoor_light_sunset
    alias: "Outdoor Light - Sunset to 23:00"
    trigger:

    • platform: sun
      event: sunset
      offset: "+00:30:00"
      condition: []
      action:
    • service: light.turn_on
      target:
      entity_id: light.extended_color_light_1
      data:
      brightness_pct: 25
      mode: single
  • id: outdoor_light_off_2300
    alias: "Outdoor Light - Turn Off at 23:00"
    trigger:

    • platform: time
      at: "23:00:00"
      condition: []
      action:
    • service: light.turn_off
      target:
      entity_id: light.extended_color_light_1
      mode: single
  • id: outdoor_light_motion_trigger
    alias: "Outdoor Light - Motion Trigger"
    trigger:

    • platform: state
      entity_id: binary_sensor.hue_outdoor_motion_sensor_1_motion
      to: "on"
      condition: []
      action:
    • choose:
      • conditions:
        • condition: time
          before: "23:00:00"
          after: "sunset"
          sequence:
        • service: light.turn_on
          target:
          entity_id: light.extended_color_light_1
          data:
          brightness_pct: 100
        • delay: "00:00:15"
        • service: light.turn_on
          target:
          entity_id: light.extended_color_light_1
          data:
          brightness_pct: 25
          default:
      • service: light.turn_off
        target:
        entity_id: light.extended_color_light_1
        mode: single
hallow forge
#

i like to add the time spans as a condition, not only in the trigger for my on/off automations. that way i can add more triggers to check that the light indeed is in the right state. like a trigger for ha starting up. even if ha was down while you crossed the trigger time the automation can then recover

mighty copperBOT
#

@ashen crow To format your text as code, enter three backticks on the first line, press Enter for a new line, paste your code, press Enter again for another new line, and lastly three more backticks.
```yaml
example: here
```
Don't forget you can edit your post rather than repeatedly posting the same thing.

sleek crag
hallow forge
#

i have stopped relying on motions detectors "off" state.
instead i have a timer as a helper. when motion is detected, light is turned on and the timer is started. every new detection will simply keep the light on and reset the timer. my light off automation triggers on the timer reaching 0, not on the sensor.

vivid mural
#

Turning on at motion sensor -> on and then turning off when the motion sensor going -> off for 15 seconds will be a more reliable solution overall imo (note: I am talking about separate triggers rather than the "wait for trigger" solution used in the example automation)

  1. automatically behaves sensibly when HA restarts or the network going down (no need for additional triggers) - the state going from unavailable -> on/off will trigger the lights to behave properly
  2. works for different behaviours of motion sensors. most have internal timers so will report a state of "on" for X (generally >=10) seconds after actually detecting something, and which refresh - so a sensor could be on for hours continuously. triggering off that state directly would keep the light on, whereas the timer solution would turn it off after 15s without additional redundant logic. Only a handful of off the shelf sensors don't have this kind of internal timer by default
  3. just easier to do imo
#

As for @ashen crow's question, tbh I think the easiest thing to do is to make a time of day helper (in yaml config you can set sunrise/sunset + offsets as times) as that makes it easy to check what "return" state the automation needs to go to after motion is detected - as written your 3rd automation will not do what you want.

  1. it ignores your 30 min offset on the sunset time, which means it will turn on from motion and reset to its 25% brightness state for half an hour before it would have turned on normally - not a dealbreaker but a bit weird
  2. it doesn't turn the light on at all on the default branch - so if if the motion is after 11pm or before sunset you don't get any lights