Automations not working

I have these two automations to open lights after sunset till before sunrise with a motion sensor and close them after 7 minutes without movements, but they are not triggered… no opne lights and no close them after 7 minutes… Why?

- alias: Accendi Luce Studio
  initial_state: true
  trigger:
    - platform: sun     
      event: sunset
      offset: '+00:30:00'
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d0001ddac9e
      to: 'on'
  condition:
  - condition: sun
    before: 'sunrise' 
  action:
    - service: homeassistant.turn_on
      entity_id: light.philips_studio
      data:
        scene: 1
        transition: 12
    - service: homeassistant.turn_on       
      entity_id: light.yeelight_rgb_7811dcdc133c   
      data:
        brightness: 150
        rgb_color:
        - 255
        - 255
        - 194
        transition: 600

- alias: Spegni Luce Studio
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d0001ddac9e
    to: 'off'
    for:
      minutes: 7
  condition:
  - condition: sun
    before: 'sunrise' 
  action:
    service: homeassistant.turn_off
    entity_id:
      - light.philips_studio
      - light.yeelight_rgb_7811dcdc133c

so to clarify…

you want to turn on lights (action) after motion is detected (trigger) but only if it’s after sunset and before sunrise (condition)?

then you want the lights to turn off (action) after 7 minutes with no motion (trigger) but only after sunset and before sunrise (condition)?

is that correct?

If so, see if you can work it out given the clues above. If you can’t just ask and we can go from there.

I think you need to change at least homeassistant.turn_on to light.turn_on, same for turn_off.

You may also want to look into the trigger/condition, looks to me the first automation triggers only when motion sensor on before sunrise, the trigger sunset and condition sunrise is crossing over midnight would confuse HA.

homeassistant.turn_on or…off should work for anything.

1 Like

@finity Learnt something, thanks.

I always do too.

That’s why I’ve learned to put “should” in pretty much every answer. I’ve been wrong too many times. Even when I was sure that I “knew” it. :grinning:

Yes that’s what i want, but for some unknown reason it doesn’t work… nor the first neither the second automation…

Your trigger is odd to me. I think this would work better… just my opinion. There are many ways to do this, this is one option:

- alias: Accendi Luce Studio
  initial_state: true
  trigger:
    - platform: state
      entity_id: binary_sensor.motion_sensor_158d0001ddac9e
      to: 'on'
  condition:
    condition: or
    conditions:
      - condition: sun
        after: 'sunset'
        after_offset: "00:30:00"
      - condition: sun
        before: 'sunrise'

The problem with your trigger is that it will not trigger at night because of your condition before sunrise. 7 pm is not before sunrise.

So you need to have an ‘or’ condition. saying before sunrise OR after sunset. Time in home assistant resets at midnight, hence why you have to use OR and not AND.

Ok thanks, tonight i will test yours and let you know…

Yes, it’s working but as I wrote in another thread I have my automation.yaml not validated also if it seems all automations are working… I posted my fully automations.yaml so please give a look at it and try to check where is the error also if yamlint.com says it’ valid.

Your link isn’t working for me.

I solved… it was an error inside the automation about gearbest prices…

An “automation about gearbest prices” caused your lights to turn off randomly?

Could you post the automation that was doing that?

No, that was the error about automations.yaml not validated…

Oh OK.

Did you get the random light off thing straightened out?

Still not… i am trying to understand why.

can you post your yaml without using that yamlint link. That link doesn’t work.

I finally solved that problem. Which yaml you want i post?

whatever is causing your issue

Ah, ok… it was an automation inside mi home app that i forgot to disable, so nothing to do with yaml errors…