Motionsensor - nightlight automation help needed

Tags: #<Tag:0x00007f7386621e38> #<Tag:0x00007f7386621a50>

Hello all,
I am stuck with my automation for my nighlight I used to realize with Node-Red. Since my SD-card broke down, I want to switch to HomeAssistant entirely.
Im my bedroom are 2 Aqara motion sensors on each side of the bed. I want them to turn on the nightlights (Aqara Gateway, WLED-Strip) after dark, once it senses motion.
I have tried the following automation without success, but I don’t know why.

- id: '1593986475252'
  alias: Nachtbeleuchtung
  description: ''
  trigger:
  - entity_id: binary_sensor.mtn_mnu_schlafzi_li
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: binary_sensor.mtn_mnu_schlafzi_re
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: sunset
    after_offset: 0:30
    before: sunrise
    before_offset: 0:30
    condition: sun
  action:
  - data:
      brightness_pct: 10
      entity_id: light.mnu_gateway
      rgb_color: 0,0,255
    service: light.turn_on
  - data:
      brightness_pct: 10
      color_name: blue
      entity_id: light.mnu_bettlicht
    service: light.turn_on
  - delay: 00:05:00
  - data: {}
    entity_id: light.mnu_bett
    service: light.turn_off
  - data: {}
    entity_id: light.mnu_gateway
    service: light.turn_off

The automation is created through the web configuration.
What am I missing or doing wrong?

Regards
manu

I don’t know exactly what was wrong with it, this is kinda the problem with the UI editor is that the code comes out in an unreadable mess.

I’ve converted it into something readable and in doing so have corrected everything that would have been wrong I think. Try this…

- id: '1593986475252'
  alias: Nachtbeleuchtung
  trigger:
    platform: state
    entity_id:
      - binary_sensor.mtn_mnu_schlafzi_li
      - binary_sensor.mtn_mnu_schlafzi_re
    to: 'on'
  condition:
    condition: or
    conditions:
      - condition: sun
        after: sunset
        after_offset: '00:30:00'
      - condition: sun
        before: sunrise
        before_offset: '00:30:00' 
  action:
    - service: light.turn_on
      data:
        entity_id: light.mnu_gateway
        brightness_pct: 10
        rgb_color: [0 , 0 , 255] 
    - service: light.turn_on
      data:
        entity_id: light.mnu_bettlicht
        brightness_pct: 10
        color_name: blue
    - delay:
        minutes: 5
    - service: light.turn_off 
      entity_id:
        - light.mnu_bett
        - light.mnu_gateway
2 Likes

You are my hero.
It worked flawlessly!

Edit:
Just for the sake of completeness:
in the light.turn_on the entity_id needs to be light.mnu_bett

1 Like