Different triggers sequence is it possible

how to:
I want that when sensor A detects movement for the first time, it will turn on the X light and when it detects the second time movement that day, it will turn on the Z light - is this possible?

Sure it is possible. Assuming nothing else but the the automation can turn light x on:

trigger:
  - platform: state
    entity_id: binary_sensor.movement
    from: 'off'
    to: 'on'
action:
  - if:
      - "{{ states.light.x.last_changed < today_at() }}"
    then:
      - service: light.turn_on
        target:
          entity_id: light.x
    else:
      - service: light.turn_on
        target:
          entity_id: light.z
3 Likes

Another possible way is something like:

trigger:
  - platform: state
    entity_id: binary_sensor.movement
    from: 'off'
    to: 'on'
    id: movement
  - platform: time
    at: "00:00:00"
    id: midnight
action:
  - if: "{{ trigger.id == "movement" }}"
    then:
      - service: light.turn_on
        entity_id: "light.{{ 'y' if states('counter.movements')|int > 0 else 'x' }}"
      - service: counter.increment
        entity_id: counter.movements
    else:
      - service: counter.reset
        entity_id: counter.movements
  - if:
      - "{{ states.light.x.last_changed < today_at() }}"

Should I add something after “today_at…”?

is there a way to do it in visual editor ?

No, the default if no value is specified is midnight (the beginning of the day).

I don’t use it but I’m guessing you should be able to supply a template condition. This:

      - "{{ states.light.x.last_changed < today_at() }}"

Is shorthand for:

      - condition: template
        value_templaate: "{{ states.light.x.last_changed < today_at() }}"
1 Like