#How to make sure the action sequence only waits in case of a particular trigger

1 messages · Page 1 of 1 (latest)

urban void
#

I have an automation with 2 triggers, one of which has below id: temp.
It should only wait in case of that particular trigger and else immediately execute the second action and the rest of the actions sequence. I fear though like this it will simply check if the id triggered, and always continue with the switch.turn_on.

    triggers:
      - trigger: time
        at:
          entity_id: input_datetime.alarmclock_wd
          offset: -00:30:00
        id: time
      - trigger: numeric_state
        entity_id: sensor.opentherm_dhw_temperature
        below: 35
        id: temp
    []
    actions:
      - if:
          - condition: trigger
            id: temp
        then:
          - wait_template: >
              {{states('sensor.time') > states('input_datetime.alarmclock_wd')}}
# this should fire always, either after the above wait, or, when triggered by the other trigger, directly
      - action: switch.turn_on
        target:
          entity_id: switch.opentherm_dhw_comfort_mode

#

How to make sure the action sequence only waits in case of a particular trigger

half fjord
#

No, that's the way I'd do it. (though your template won't necessarily do the comparison properly at the moment as it's doing a string compare)
The thing to watch out for is the automation mode - if it's set to single then while your automation is waiting for the template, it won't be able to trigger based on time

urban void
#

o right, I forgot about that string compare...

#

and the triggers wont fire that close to each other probably.

#

it just that I figured the wait would only work for the actions in the 'then'.

half fjord
#

It's not about firing close to each other - you are forcing the temp trigger to wait until after the input_datetime that the time trigger will always run before

urban void
#

btw, in a related automation I have action: input_select.select_previous data: {} target: entity_id: input_select.activiteit but that selects the previous in the list of options does it, not the actual previous selection?

half fjord
#

If they run close together it would actually work, it's only if the temp triggers more than half an hour earlier that they will clash

urban void
#

ok, will revisit this, with that help, thanks

half fjord
urban void
#

not sure how I could prevent a clash other than the already used condition of - > {% set delay = states('input_number.zonneboiler_periode')|int(23) %} {{now() - this.attributes.last_triggered > timedelta(hours=delay) if this.attributes.last_triggered is not none else true}} making sure it didnt ran previously within that timeframe

half fjord
#

Why do you need to wait for the alarmclock time
Can't you just use a condition to cancel the times it triggers before that?

#

It's going to run at the alarm time regardless of the temp trigger anyway because of the other trigger

urban void
#

its only going to run at alarm time, if the temp is below a certain level.

#

let me post the full automation

#

btw I made this test, and that indeed shows the wait is executed under the if

automation:

  - id: test_if_wait
    triggers:
      - trigger: state
        entity_id: input_boolean.test
        to: 'on'
        id: test
      - trigger: state
        entity_id: input_boolean.test_2
        to: 'on'
        id: test_2
    actions:
      - if:
          - condition: trigger
            id: test
        then:
          - delay: 10
      - action: notify.mobile_app_marijn
        data:
          title: Test if wait
          message: >
            {{trigger.id}} Uitgevoerd
#

so, this would mean, either fire half an hour before the alarm, if the temp is low, or, fire if the temp is low, and make sure it is not in the middle of the night, but at least a few minutes before alarm clock time. Dont run if the automation ran within the set time frame

half fjord
urban void
#

you mean, in stead of the if action, just add a condition (in the condition block) not to fire in between lets say 23:00-06:00 ? That might actually work indeed 😉

#

like:

  - alias: "Example referencing a time helper"
    condition: time
    before: 23:00
    after: input_datetime.alarmclock_wd
    offset: - 00:30 # can we use offsets in the condition? must check that
#

no we cant, so cant use the input_datetime I have, but can do hard coded:

      - condition: time
        before: '23:00'
        after: '06:00'
#

if this is not what you meant above, Id appreciate you could show me what you did mean, because hardcoded like this is just too generic, given the fact I change those alarmclock settings frequently, and I want to heat up as close to the wakeup as possible. The earlier construct of the wait template ensures that is taken into consideration

half fjord
#

You can use entities in the before and after keys

#

No offset by default though, but you could change to a template condition to reimplement it

urban void
#

check:```
conditions:
- condition: time
before: '23:00'

after: '06:00'

  - >
   {{now() >
    (today_at(states('input_datetime.alarmclock_wd'))
    - timedelta(minutes = 30))}}```