My Automatons are not triggering

I have a fewe motion sensors that trigger some events. For example if i go into the kitchen after a certain time it turns the lights on and another that turns them off after a period of time. Changed my router reconnected every thing and now they do not trigger.
I can go into Automatons and click execute and they work. Anyone know what i am doing wrong.

- alias: Turn on kitchen light when there is movement
  initial_state: true
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d00020e5e79
    to: 'on'
  condition:
    condition: and
    conditions:
     condition: time
     after: '19:00:00'
     before: '07:00:00'
  action:
    service: homeassistant.turn_on
    entity_id: switch.other_thing
  1. You dont need “and” when you only have one condition (and “and” is default anyway)
  2. Time can never be both before 07:00 AND after 19:00 at the same time.

You need to split the conditions to two different conditions, and use “or”

 condition:
   condition: or
   conditions:
   - condition: time
     after: '19:00:00'
   - condition: time
     before: '07:00:00'

(Not tested, might contain a typo or two)

This caught me out a few times early on. It’s natural to think of night-time as “between 1900 and 0700”, but from the clock’s point of view, it’s 1900 to 2359 on one day, then resets to 0000 on the next day as a completely separate “section of time”.

Of course, you can code day-time as after 0700 and before 1900, and that would work just fine.

@Olen @Troon

Actually, for a time condition, that works and it means just what you would think – between 7:00 PM in the evening and 7:00 AM the next morning. (It’s not the same as with the sun condition, which, BTW, should be changed to allow this, which I’ve looked into doing, but it’s a bit more complicated than it seems on the surface.) So, anyway, that’s not the problem.

@ronbentley9

Have you looked at the history of binary_sensor.motion_sensor_158d00020e5e79? Is it changing to 'on' from something else? Is the automation turned on? Have you tried calling the automation.trigger service from the SERVICES tab with skip_condition set to false during the specified time range?

Thanks for you help. It was me being stupid. The code worked but it was past 7 am when i checked it. so it did not trigger :slight_smile: Sometimes you just need to check the obvious.

Would be very interested on how i could get this to work on the sun condition because as you alluded to It depends on the time of year it would need to trigger the automation.

I have the following in one of my automations:

- id: awning_up_sun_down
  alias: Awning up at sunset
  trigger:
  - platform: numeric_state
    entity_id: sun.sun
    value_template: "{{ state_attr('sun.sun', 'elevation') }}"
    below: 12.0
  - platform: numeric_state
    entity_id: sun.sun
    value_template: "{{ state_attr('sun.sun', 'azimuth') }}"
    above: 272.0
  condition: 
  - condition: template
    value_template: "{{ state_attr('sun.sun', 'azimuth') | float > 272 }}"
  - condition: template
    value_template: "{{ state_attr('sun.sun', 'elevation') | float < 12 }}"
  - condition: template
    value_template: "{{ states('sensor.awning') != 'up' }}"
  action:
  - service: script.awning_up

The point is that the sun will disappear behind a building when it is BOTH below 12° elevation and its azimuth is above 272°.
So I wait for both of these to be true.

If the sun is below 12° above horizon, it will still shine in if it has not passed behind the building at 272°.
(This happens in the spring and autumn, when the sun is low in the sky).
But in the summer, the sun can be well past 272°, and still be above the 12° elevation of the building.

So when both conditions are true (and I don’t know which one will be true first, because that depends on the season), the awning will be moved to the “up” position.

See previous post for one way to do it. Also, see sun conditions for documentation on the sun condition and its various options.

Been using Sun for a week now and very impressed. Turns on and off at the right time.

Thanks everyone