Newbie in Home Assistant

Hi Guys…
I am new here and I am trying to setup an Automation in HA.
When I open the Front Door (Wyze Door Sensor) the idea is to get the Hue Light Bulb to turn.
I have a Nortek dual USB connected to a RaspBerry Pi 4 and everything looks good and I can see all my devices and entities.
I have tried multiple ways but no luck

- id: '1605########'
** alias: Porch Lights ON**
** description: (Front Door Sensor)**
** trigger:**
** - platform: state**
** entity_id: binary_sensor.wyzesense_77a90a7a**
** to: ‘ON’**
** condition: []**
** action:**
** - service: light.turn_on**
** data:**
** entity_id: light.philips_lte001_1c91d308_level_light_color_on_off**
** mode: single**

Any help is very much appreciated…(I work on the Automation via the GUI)

Because the example you posted has lost all its formatting (and gained a lot of extraneous asterisks) it’s nearly impossible for anyone to check it for proper indentation (which is essential for YAML). Nevertheless I do see something that is incorrect and that is the state of the binary_sensor. Your example uses uppercase 'ON' but it should be lowercase 'on' because a binary_sensor’s state is either on or off.

Beyond that, I suggest you try to copy-paste the automation’s code again and this time try to preserve its original formatting. After pasting the code into the forum’s message, put three consecutive back-quotes ``` on a separate line before the code and three more on a separate line after the code. The forum’s editor understands that anything between the two sets of back-quotes is to be formatted as code.

OMG …thank you so much for your guidance !!!
You were spot on … it worked …
UPPERCASE was the issue

If I wanted to add a timer to turn OFF after 10 mins; would it be a different AUTOMATION ?

‘’’
alias: Porch Lights ON
description: (Front Door Sensor)
trigger:

  • platform: state
    entity_id: binary_sensor.wyzesense_77a90a7a
    to: ‘on’
    condition:
  • condition: sun
    before: sunrise
    after: sunset
    action:
  • service: light.turn_on
    entity_id: light.philips_lte001_1c91d308_level_light_color_on_off
    data: {}
    mode: single
    ‘’’

Thank You again.

Just for further clarification, the three back quotes are not single quotes. It’s the backward quote that’s usually above the TAB and under the ESC way over on the left of the keyboard. The back quotes look like this ` where the single quote looks like this '. If you put three back quotes above and below your code, it looks like this when you’re reading it:

alias: Porch Lights ON
description: (Front Door Sensor)
trigger:
  platform: state
    entity_id: binary_sensor.wyzesense_77a90a7a
    to: ‘on’
    condition:
  condition: sun
    before: sunrise
    after: sunset
    action:
  service: light.turn_on
    entity_id: light.philips_lte001_1c91d308_level_light_color_on_off
    data: {}
    mode: single

Thank You Russell.

alias: Porch Lights ON
  description: (Front Door Sensor)
  trigger:
  - platform: state
    entity_id: binary_sensor.wyzesense_77a90a7a
    to: 'on'
  condition:
  - condition: sun
    before: sunrise
    after: sunset
  action:
  - service: light.turn_on
    entity_id: light.philips_lte001_1c91d308_level_light_color_on_off
    data: {}
  mode: single

You’re going to have an issue with the above condition. It can’t be both before sunrise AND after sunset, so you’ll want to do this:

  condition:
  - condition: or
    conditions:
    - condition: sun
      before: sunrise
    - condition: sun
      after: sunset

or simply this:

  condition:
  - condition: state
    entity_id: sun.sun
    state: 'below_horizon'
1 Like

If I wanted to add a timer to turn OFF after 10 mins; would it be a different AUTOMATION?

I use this to turn on my hallway lights when the motion sensor is in the on state. When the motion sensor is in the Off state for 30sec, the lights turn off.
I have modified it to your condition. Further adjustment maybe needed for the 00:10:00

- alias: 'Porch Lights ON'
  trigger:
  - entity_id: binary_sensor.wyzesense_77a90a7a
    from: 'off'
    platform: state
    to: 'on'
  condition:
    - condition: state
      entity_id: sun.sun
      state: 'below_horizon'
  action:
  - service: light.turn_on
    data:
    entity_id: light.philips_lte001_1c91d308_level_light_color_on_off

- alias: 'Porch Lights OFF'
  trigger:
  - entity_id: binary_sensor.wyzesense_77a90a7a
    for: 00:10:00
    from: 'on'
    platform: state
    to: 'off'
  action:  
  - service: light.turn_off
    data:
      entity_id: light.philips_lte001_1c91d308_level_light_color_on_off

Blockquote
If I wanted to add a timer to turn OFF after 10 mins; would it be a different AUTOMATION ?

# using timer
- alias: Porch Lights ON_OFF
  description: (Front Door Sensor)
  mode: single
  trigger:
  - platform: state
    entity_id: binary_sensor.wyzesense_77a90a7a
    to: 'on'
  condition: "{{ is_state('sun.sun', 'below_horizon') }}"
  action:
  # start timer
  - service: timer.start
    data:
      entity_id: timer.light_off_timer
  # turn on light
  - service: light.turn_on
    entity_id: light.philips_lte001_1c91d308_level_light_color_on_off
  # wait for timer to finish
  - wait_for_trigger:
    - platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.light_off_timer
  # turn off light
  - service: light.turn_off
    data:
      entity_id: light.philips_lte001_1c91d308_level_light_color_on_off

OR

# using delay
- alias: Porch Lights ON_OFF
  description: (Front Door Sensor)
  mode: single
  trigger:
  - platform: state
    entity_id: binary_sensor.wyzesense_77a90a7a
    to: 'on'
  condition: "{{ is_state('sun.sun', 'below_horizon') }}"
  action:
  # turn on light
  - service: light.turn_on
    entity_id: light.philips_lte001_1c91d308_level_light_color_on_off
  - delay:
      minutes: 10
      # or adjustable using input_number
      minutes: "{{ states('input_number.your_custom_time) | int }}"
  - service: light.turn_off
    data:
      entity_id: light.philips_lte001_1c91d308_level_light_color_on_off  

Edit: you may need to change the mode: single to mode: restart to use the above

@123

Interesting!

Explain the below, please?

I can explain that part but, as you can see, I have deleted the example I had posted because I assumed it was a motion sensor but it’s actually a contact sensor (making the example non-applicable).

The automation had two triggers. One was a Template Trigger and the other a State Trigger. Depending on which one triggered, the action would be different. To know which one triggered, you can use trigger.platform.

In this particular example, if the Template Trigger had triggered then the action would be to turn on the light. Otherwise, it was the State Trigger that triggered and the action would be to turn off the light.

I also assumed it was a motion sensor… Oops.

Thanks! I understand now. Going to put that in my automation right now.