Need a bit of help extending an automation (use of CHOOSE possibly?)

Hello all,

Could someone help me with the modification of the automation below. I would like to extend the automation to send me a text if a certain sensor called ‘sensor.weston_ett_home’ is greater than 45.

I think this is supposed to be done with using choose but I really don’t know how. Everything that is occuring below in the current automation, I would like to occur in both sides of the choose.

Thank you all so much!!

  - id: weston_leaves_work
    alias: weston Leaves Work Notification
    initial_state: true
    trigger:
      - platform: zone
        event: leave
        zone: zone.tdot
        entity_id: person.weston
    condition:
      - condition: state
        entity_id: person.weston
        state: "tdot"
        # optional: trigger only if state was this for last X time.
        for:
          hours: 3
          minutes: 0
          seconds: 0
      - condition: time
        after: "15:00:00"
        before: "18:00:00"
    action:
      # - service: input_boolean.turn_on
      #   entity_id: input_boolean.weston_travel_monitor
      - service: script.status_annc
        data_template:
          who: "kitchen"
          call_interruption: 1
          call_weston_location: 1
      - service: script.text_notify
        data:
          who: "clarice"
          message: "Weston has left work."

Since you want the rest of the sequence to always occur, you really don’t need to use a Choose action for what you have described. It can be done by adding a Condition action and your text action at the end of current action sequence. If the condition is false, any actions after it will not be executed.

  - id: weston_leaves_work
    alias: weston Leaves Work Notification
    initial_state: true
    trigger:
      - platform: zone
        event: leave
        zone: zone.tdot
        entity_id: person.weston
    condition:
      - condition: time
        after: "15:00:00"
        before: "18:00:00"
    action:
      # - service: input_boolean.turn_on
      #   entity_id: input_boolean.weston_travel_monitor
      - service: script.status_annc
        data_template:
          who: "kitchen"
          call_interruption: 1
          call_weston_location: 1
      - service: script.text_notify
        data:
          who: "clarice"
          message: "Weston has left work."
      - condition: numeric_state
        entity_id: sensor.weston_ett_home
        above: 45
      - service: script.text_notify
        data:
          who: "weston"
          message: "Your sensor is greater than 45"

As Taras mentions below, this condition will not work:

      - condition: state
        entity_id: person.weston
        state: "tdot"
        for:
          hours: 3
          minutes: 0
          seconds: 0

There is at least one way to accomplish something like this. There are probably a few other ways, but they are all going to require some sort of additional sensor or helper.

1 Like

Maybe I’ve misunderstood the automation but it appears to trigger the moment a person has left a zone and then its condition checks if the person hasn’t been in that zone for at least 3 hours.

I don’t see how the condition can ever be fulfilled. It doesn’t wait until the person is gone for 3 hours it checks if the person has already been gone for 3 hours (and they haven’t because they just left).

@Didgeridrew @123 Oh, I’m terrible at this. What I am trying to get to happen is if I am at work for at least three hours and then I leave… Actions happen.

@Didgeridrew Thank you for adjusting my code.

So to take care of the being at work for 3 hours situation. I just need to created the template sensor you suggested?

I hate to ask this but is there a hacky way to not have to do the template sensor. I agree it is a very elegant solution though.

Is there a dirtier one that can be used directly in the current adjusted automation that you have posted?

@Didgeridrew @123 Thank you both for your input on this. I feel like such a bother on here as much as I ask for assistance. :frowning:

The lowest additional effort method would be to use an Input datetime helper, an added trigger, and a Choose action… you’ll just need to set up an input datetime helper (select the kind with both date and time).

You may need to move or alter the time condition, depending on your schedule… if you normally leave work and then return after 15:00, you can leave it as is. Otherwise, move the time condition to just below default:.

  - id: weston_leaves_work
    alias: weston Leaves Work Notification
    initial_state: true
    trigger:
      - platform: zone
        event: leave
        zone: zone.tdot
        entity_id: person.weston
      - platform: zone
        id: arrive
        event: arrive
        zone: zone.tdot
        entity_id: person.weston
    condition:
      - condition: time
        after: "15:00:00"
        before: "18:00:00"
    action:
      - choose:
        - conditions:
            - condition: trigger
               id: arrive
          sequence:
            - service: input_datetime.set_datetime
              target:
                entity_id: input_datetime.XXX
              data:
                timestamp: "{{ now().timestamp() }}"
        default:
        - condition: template
          value_template: |
            {{ now() >= (states('input_datetime.XXX') | as_datetime | as_local) + timedelta(hours=3) }}
      # - service: input_boolean.turn_on
      #   entity_id: input_boolean.weston_travel_monitor
        - service: script.status_annc
          data_template:
            who: "kitchen"
            call_interruption: 1
            call_weston_location: 1
        - service: script.text_notify
          data:
            who: "clarice"
            message: "Weston has left work."
        - condition: numeric_state
          entity_id: sensor.weston_ett_home
          above: 45
        - service: script.text_notify
          data:
            who: "weston"
            message: "Your sensor is greater than 45"

Ahh, I see. Essentially an input of the time at a zone. I see what you are getting at though. Your first solution overall seems like less of an annoying headache through the life of the automation. Thank you for teaching me some things @Didgeridrew I have no doubt these ideas will come in handy in the shortly as I adjust my code for this one and in the future!! Thank you so much again!!