N00b struggeling with a simple light automation

So, I’ve recently got myself a couple of Fibaro Motion Sensors, and figured it should be easy peasy making an automation to turn on lights and dim them down again after a given time. I’ve tried a few combos, and this is the one that feels most right to me, even though it actually breaks HA. I want my light to stay at a low brightness, and increase when motion is detected. When motion is no longer detected +5min, i want the light to dim down to barely on again.

My automations.yaml:

- alias: "Belysning Bad dim opp"
  trigger:
    - platform: state
      entity_id: sensor.sensor_bad_beveglse
      from: '0'
      to: '8'
  action:
    - service: light.turn_on
      data:
        entity_id: light.downlights_bad_niva
        brightness: 150
      delay:
        minutes: 5

- alias: "Belysning Bad dim ned"
  trigger:
    - platform: state
      entity_id: sensor.sensor_bad_beveglse
      from: '8'
      to: '0'
  action:
    - service: light.turn_on
      data:
        entity_id: light.downlights_bad_niva
        brightness: 50

I’ve come across a few posts with similar setups, but not enough to wrap my head around it. Like why is it state and not state_binary? Many use a service called homeassitant_on or something which doesn’t make any sense to me at all. Are they turning a sleeping system on? Is it more practical to use scenes, scripts and magic on top? I haven’t started to look into those yet. All the possible options aren’t as obvious when i’m trying to write this myself.

BTW, I’m running HA 0.48 on a Pi2 in a virtual env, didn’t use AIO or HASS image. The dimmer is currently a Qubino Flush Dimmer and the controller is a Aeotec USB Z-Wave 5th Gen EU if that’s relevant.

When you put the delay on the turn_on action, doesent the light turn_on 5 minutes after the motion is detected?
So the delay should be 5 minutes after the motion is “gone”… ?

I do not know how your sensor.sensor_bad_beveglse works, but if it restets from 8 to 0 while the first automation is running you may encounter some problem.

Personally I would simply remove the delay action (which is in wrong syntax anyway. It should be a sibling of - service, not a child), and add a ‘for: minutes: 5’ in the trigger of the second automation.

This would give

- alias: "Belysning Bad dim opp"
  trigger:
    - platform: state
      entity_id: sensor.sensor_bad_beveglse
      from: '0'
      to: '8'
  action:
    - service: light.turn_on
      data:
        entity_id: light.downlights_bad_niva
        brightness: 150


- alias: "Belysning Bad dim ned"
  trigger:
    - platform: state
      entity_id: sensor.sensor_bad_beveglse
      from: '8'
      to: '0'
      for:
        minutes: 5
  action:
    - service: light.turn_on
      data:
        entity_id: light.downlights_bad_niva
        brightness: 50

So basically, the first automation just turns on the lights. And the second is triggered if the state is returned to 0 for 5 minutes. Which is exactly what you want I believe.

1 Like

Thanks so much for your quick response, it works great. And fun to see that i actually was pretty close :slight_smile: Now, if i want to have this function enabled only at given times during the day, would i include that into the automation, or should i enable/disable that automation from elsewhere? I haven’t fully planned how to do this myself yet, but i know i don’t want it on during the night, and probably not in the morning or early afternoon either. At least i now have a working starting point :smiley: Thanks again!

basically you could add a condition to the first automation to allow it triggering only after sunset for instance (or after a given hour). And for the second one, just keep it that way or also add a condition that will execute the automation only if the lights are on.

check