#Need help with conditions in automation.

1 messages · Page 1 of 1 (latest)

timber badge
#

I'm curious if this condition

          - condition: time
            before: '23:30:00'

in the below snippet from a larger automation, will apply to only the action right after it or both action below it...

  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - door_left_opened
      sequence:
      - repeat:
          sequence:
          - condition: time
            before: '23:30:00'
          - action: notify.notify_to_all_devices
            metadata: {}
            data:
              message: TTS
              data:
                priority: high
                ttl: 0
                media_stream: alarm_stream
                tts_text: WARNING! Door is open
          - action: notify.notify_to_all_devices
            metadata: {}
            data:
              title: Door Open
              message: WARNING! Door is open
              data:
                car_ui: true
                channel: DoorOpenAlert
                push:
                  sound: Alert_SpartanConnecting_Haptic.caf
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          while:
          - condition: state
            entity_id: binary_sensor.door_sensor_contact
            state: 'on'
molten talon
#

the condition only allows the sequence to proceed if it's true

#

anything after it won't be executed if it's false

#

if you want more finegrained control, use if/then or choose

timber badge
#

Basically I want notification to always fire and TTS to not fire after 23:30..

molten talon
#

then put the notification first

#

before the condition

timber badge
#

like this you mean?

  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - door_left_opened
      sequence:
      - repeat:
          sequence:
          - action: notify.notify_to_all_devices
            metadata: {}
            data:
              title: Door Open
              message: WARNING! Door is open
              data:
                car_ui: true
                channel: DoorOpenAlert
                push:
                  sound: Alert_SpartanConnecting_Haptic.caf
          - condition: time
            before: '23:30:00'
          - action: notify.notify_to_all_devices
            metadata: {}
            data:
              message: TTS
              data:
                priority: high
                ttl: 0
                media_stream: alarm_stream
                tts_text: WARNING! Door is open
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          while:
          - condition: state
            entity_id: binary_sensor.door_sensor_contact
            state: 'on'
molten talon
#

yes

timber badge
#

will the notification and TTS be repeated at interval of 10 seconds still though while the door is open?

molten talon
#

it will also skip the delay

timber badge
#

or will condition break the delay and while as well after 23:00

molten talon
#

use an if/then

timber badge
#

I have not used if before, how to use that?

molten talon
#

or just follow the UI prompts

timber badge
#

like this?

  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
        - door_left_opened
      sequence:
      - repeat:
        - if:
          - alias: notify and tts before 23:00
            condition: time
            before: '23:30:00'
          then:
            sequence:
            - action: notify.notify_to_all_devices
              metadata: {}
              data:
                title: Door Open
                message: WARNING! Door is open
                data:
                  car_ui: true
                  channel: DoorOpenAlert
                  push:
                    sound: Alert_SpartanConnecting_Haptic.caf
            - action: notify.notify_to_all_devices
              metadata: {}
              data:
                message: TTS
                data:
                  priority: high
                  ttl: 0
                  media_stream: alarm_stream
                  tts_text: WARNING! Door is open
          else:
            - action: notify.notify_to_all_devices
              metadata: {}
              data:
                title: Door Open
                message: WARNING! Door is open
                data:
                  car_ui: true
                  channel: DoorOpenAlert
                  push:
                    sound: Alert_SpartanConnecting_Haptic.caf
          - delay:
              hours: 0
              minutes: 0
              seconds: 10
              milliseconds: 0
          while:
          - condition: state
            entity_id: binary_sensor.door_sensor_contact
            state: 'on'
molten talon
#

what you asked for:

Basically I want notification to always fire and TTS to not fire after 23:30..

#

you didn't need to repeat the notification, just leave it where it was at the top and only use the if for the TTS

#

what you have should work, it's just unnecessarily repetitive

timber badge
#

Yea that's what I was thinking.. one sec let me modify it.

#

so this should be it..

  actions:
  - choose:
    - conditions:
      - condition: trigger
        id:
          - door_left_opened
      sequence:
        - repeat:
            sequence:
              - action: notify.notify_to_all_devices
                metadata: {}
                data:
                  title: Door Open
                  message: WARNING! Door is open
                  data:
                    car_ui: true
                    channel: DoorOpenAlert
                    push:
                      sound: Alert_SpartanConnecting_Haptic.caf
              - if:
                - condition: time
                  before: '23:30:00'
                then:
                  - action: notify.notify_to_all_devices
                    metadata: {}
                    data:
                      message: TTS
                      data:
                        priority: high
                        ttl: 0
                        media_stream: alarm_stream
                        tts_text: WARNING! Door is open
              - delay:
                  hours: 0
                  minutes: 0
                  seconds: 10
                  milliseconds: 0
            while:
              - condition: state
                entity_id: binary_sensor.door_sensor_contact
                state: 'on'
#

this will repeat the notification and tts every 10 second while the door is open state.. but tts will only fire if its before 23:30.. right?

molten talon
#

yes

#

it will do TTS at 3am, though

#

is that what you want?

timber badge
#

hmm? why?

molten talon
#

because it's before 23:30

timber badge
#

no.. it should not do TTS after 23:30 basically I don't want my phone saying something while I am sleeping.. just notification is fine.

molten talon
#

3:00 isn't after 23:30

#

you need to provide a range

timber badge
#

where do I have 3:00?

#

how to provide a range?

molten talon
#

I just gave you an example

#

you understand the problem?

#

that if will only be true for 30mins

#

always, the docs:

timber badge
#
              - if:
                - condition: time
                  before: '23:30:00'
                  after: '06:00:00'

like this you mean maybe?

molten talon
#

yes

timber badge
#

Ah!

#

I mean it makes sense.

#

BTW I still don't understand how just having before part makes it 30 mins only?

molten talon
#

you were only preventing TTS for 30mins

#

23:30-24:00

timber badge
#

Oh! but it would be any time after 23:30 right not just 30 mins?

molten talon
#

there are only 30mins after 23:30

#

do you have more time after 23:30?

timber badge
#

Oh! OK.. my bad.. not used to 24 hour time.. I try to use it every now then..

#

after 24 its 1 so..

molten talon
#

0, actually

#

anyway, I think you get it

timber badge
#

I was thinking like 24 == 12 or 0 then you have 1

#

but in 24 hour time 24 is the end

#

anyways.. thanks for the help.

#

I'll try this quickly one sec.

#

its 23:00 ATM

#

I'll try now and after half hour again.

timber badge
#

The automation is working as expected. Thanks for all the help.

#

how do I mark this as solved?

molten talon
#

I just did. It's a tag