Automation not working first one

I am taking a WYZE PIR and trying to turn on a light switch automatically when it has motion during night hours.

Then after 10 min of no motion it turns off. Its not working.

Please help its my first one and all the examples on line dont match my version of HA.

- id: '1577684005931'
  alias: Motion detection living room
  description: test
  trigger:
  - entity_id: binary_sensor.wyzesense_779b9111
    from: 'off'
    platform: state
    to: 'on'
  condition:
  - after: sunset
    after_offset: '-45'
    before: sunrise
    before_offset: '45'
    condition: sun
  action:
  - alias: ''
    data: {}
    entity_id: switch.055551102cf432194111
    service: switch.turn_on
- id: '1577684225468'
  alias: no motion living room light off
  description: no motion living room lights off
  trigger:
  - entity_id: binary_sensor.wyzesense_779b9111
    from: 'on'
    platform: state
    to: 'off'
  condition: []
  action:
  - entity_id: switch.055551102cf432194111
    service: switch.turn_off
  - delay: '10'
  1. You cant have a condition of “after sunset and before sunrise” on the same day. It needs to be “after sunset or before sunrise” on the same day:
condition:
  condition: or 
  conditions:
    - condition: sun
      after: sunset
      after_offset: "-00:45:00"
    - condition: sun
      before: sunrise
      before_offset: "00:45:00"
  1. Your 10 second delay is after the action in the second automation. Also it is not needed. Do it like this:
- id: '1577684225468'
  alias: no motion living room light off
  description: no motion living room lights off
  trigger:
  - platform: state
    entity_id: binary_sensor.wyzesense_779b9111
    to: 'off'
    for:
      seconds: 10
  action:
  - service: switch.turn_off
    entity_id: switch.055551102cf432194111

See the example here:

I made the changes. I will see if it works tonight. I made this with the HA wizard

under configuration-auctions i used the drop downs and it made the code. I am guessing that its not working very well using that way of visual coding and that i am going to have to slowly learn how to just code it myself.

Thanks so much i report back.

Rob

So now i get an error that HA could not start automation when i reboot.

The following components and platforms could not be set up:

  • automation

Please check your config.

- id: '1577684005931'
  alias: Motion detection living room
  description: test
  trigger:
  - entity_id: binary_sensor.wyzesense_779b9111
    platform: state
    to: 'on'
    condition:
        condition: or 
        conditions:
          - condition: sun
            after: sunset
            after_offset: "-00:45:00"
          - condition: sun
            before: sunrise
            before_offset: "00:45:00"
  action:
  - alias: ''
    data: {}
    entity_id: switch.055551102cf432194d111
    service: switch.turn_on
- id: '1577684225468'
  alias: no motion living room light off
  description: no motion living room lights off
  trigger:
  - entity_id: binary_sensor.wyzesense_779b9111
    platform: state
    to: 'off'
    for: 
        minuts: 10
  condition: []
  action:
  - entity_id: switch.055551102cf432194d9f111
    service: switch.turn_off
  1. Restart, not reboot.

  2. Always validate your configuration before restarting.

833da05cfef9b35f9be3903895dc8edd9893d60b_2_386x500

  1. Your condition block indentation is way off. Should be:
- id: '1577684005931'
  alias: Motion detection living room
  description: test
  trigger:
  - entity_id: binary_sensor.wyzesense_779b9111
    platform: state
    to: 'on'
  condition:
    condition: or 
    conditions:
      - condition: sun
        after: sunset
        after_offset: "-00:45:00"
      - condition: sun
        before: sunrise
        before_offset: "00:45:00"

Where is the config checker? i have looked all over and cant find it.

Sorry for all the newbie questions but thanks for the help.

Rob

You may have to go into your profile (the round icon at the bottom of the sidebar) and enable advanced mode. Then Configuration side menu / Server control

I found it! Just like you said i had to turn on advanced mode.

So the on trigger is now working but the off timer is not. Any ideas?

- id: '1577684225468'
  alias:  motion non living room light off
  description:  motion non living room lights off
  trigger:
  - entity_id: binary_sensor.wyzesense_779b9111
    platform: state
    to: 'off'
    for: 
        minuts: 10
  condition: []
  action:
  - entity_id: switch.055551102cf432194111
    service: switch.turn_off

Indentation is very important in YAML, so is spelling :slight_smile:

    for: 
      minutes: 10

I feel really dumb. Thanks so much i will test it. I program in VB/C++ but i have never had to worry about indention’s that i will have to watch.

Thanks again

Rob

1 Like

I highly recommend Visual Studio Code as an editor with the following extensions:

  • Home Assistant Config Helper
  • indent-rainbow
  • Rainbow Brackets
  • Spell Right
  • vscode-icons
  • Material Design Icons Intellisense
1 Like

It all works thanks! I will install those thanks.

Rob

So this time i am using the visual basic studio. Again i tried to set this up using the add automation wizard and i already had to make so many changes that it did wrong but i am missing something. Any ideas?
This is a wyze magnetic sensor, when tripped turns on a light. when the door closes its waits 5 min then turns off the light. Sorry to bother you again i cant find the issue.

- id: '1577845861147'
  alias: Entry light on
  description: turn on entry light for 5 min when door opens
  trigger:
  - entity_id: binary_sensor.wyzesense_779ba111
    platform: state
    to: 'open'
  condition:
    condition: or
    conditions:
    - condition: sun
      after: sunset
      after_offset: -00:45:00
    - condition: sun
      before: sunrise
      before_offset: 00:45:00
  action:
  - alias: ''
    data: {}
    entity_id: switch.055551102cf432192111
    service: switch.turn_on

- id: '1577846098902'
  alias: entry light off
  description: turn off after 5min
  trigger:
  - entity_id: binary_sensor.wyzesense_779ba111
    platform: state
    to: 'close'
    for:
      minutes: 5
  condition: []
  action:
  - entity_id: switch.055551102cf432192111
    service: switch.turn_off

i tried to do it as open and on FYI

The states of binary sensors are ‘on’ and ‘off’ no matter how they display in the frontend. This

  trigger:
  - entity_id: binary_sensor.wyzesense_779ba111
    platform: state
    to: 'open'

Should be:

  trigger:
  - entity_id: binary_sensor.wyzesense_779ba111
    platform: state
    to: 'on'

Likewise your closed trigger state should be ‘off’

tried that still did not work.

- id: '1577845861147'
  alias: Entry light on
  description: turn on entry light for 5 min when door opens
  trigger:
  - entity_id: binary_sensor.wyzesense_779ba111
    platform: state
    to: 'on'
  condition:
    condition: or
    conditions:
    - condition: sun
      after: sunset
      after_offset: -00:45:00
    - condition: sun
      before: sunrise
      before_offset: 00:45:00
  action:
  - alias: ''
    data: {}
    entity_id: switch.055551102cf432192111
    service: switch.turn_on

- id: '1577846098902'
  alias: entry light off
  description: turn off after 5min
  trigger:
  - entity_id: binary_sensor.wyzesense_779ba111
    platform: state
    to: 'off'
    for:
      minutes: 5
  condition: []
  action:
  - entity_id: switch.055551102cf432192111
    service: switch.turn_off
1 Like

Do i need a sensor yaml? the automation wizard was placing this in the auction yaml?

Got it i just needed to restart it again. wow i was like man i got it this time and dead but just needed a restart. Thanks again