Condition on one state trigger?

I am at a loss how to easily modify this - I found an edge case issue I’m not sure how to implement.

I want this to NOT run if sensor.downstairs_hvac_daily_cycle changes when vacation or severe_weather are “on”.

I still want it to trigger if any other existing trigger happens, including if daily_cycle changes while both vacation and severe_weather are off

Any ideas to easily add the condition to only the one trigger? Would a condition-template maybe do it testing trigger ID and also value of vacation/severe_weather?

  - alias: "Downstairs HVAC Clear Manual Adj Value"
    trigger:
      # Trigger when programmed temp changes
      - platform: state
        entity_id:
          - sensor.downstairs_hvac_daily_cycle
      # Trigger if we go in/out of vacation or temp-hold modes
      - platform: state
        entity_id:
          - input_boolean.downstairs_hvac_vacation_mode
          - input_boolean.downstairs_hvac_severe_weather_mode
      # Trigger if thermostat is turned off to on
      - platform: state
        entity_id: climate.downstairs_thermostat
        from: 'off'
      - platform: homeassistant
        event: start
    mode: queued
    action:
      - service: input_number.set_value
        data:
          entity_id: input_number.downstairs_hvac_manual_cool_adj
          value:  0
      - service: input_number.set_value
        data:
          entity_id: input_number.downstairs_hvac_manual_heat_adj
          value:  0

  - alias: "Downstairs HVAC Clear Manual Adj Value"
    trigger:
      # Trigger when programmed temp changes
      - platform: state
        entity_id:
          - sensor.downstairs_hvac_daily_cycle
        id: "cycle_trigger"
      # Trigger if we go in/out of vacation or temp-hold modes
      - platform: state
        entity_id:
          - input_boolean.downstairs_hvac_vacation_mode
          - input_boolean.downstairs_hvac_severe_weather_mode
      # Trigger if thermostat is turned off to on
      - platform: state
        entity_id: climate.downstairs_thermostat
        from: 'off'
      - platform: homeassistant
        event: start
    conditions:
      - condition:           template
        value_template: >
           {{
                trigger.id|default(none) not in ['cycle_trigger'] 
                    or
                not is_state('input_boolean.downstairs_hvac_vacation_mode', 'on')
                    and
                not is_state('input_boolean.downstairs_hvac_severe_weather_mode', 'on')
           }}
    mode: queued
    action:
      - service: input_number.set_value
        data:
          entity_id: input_number.downstairs_hvac_manual_cool_adj
          value:  0
      - service: input_number.set_value

I would set a trigger ID for the trigger in question then you can get the desired logic as follows:

- alias: "Downstairs HVAC Clear Manual Adj Value"
    trigger:
      # Trigger when programmed temp changes
      - platform: state
        id: daily_cycle
        entity_id:
          - sensor.downstairs_hvac_daily_cycle
      # Trigger if we go in/out of vacation or temp-hold modes
      - platform: state
        entity_id:
          - input_boolean.downstairs_hvac_vacation_mode
          - input_boolean.downstairs_hvac_severe_weather_mode
      # Trigger if thermostat is turned off to on
      - platform: state
        entity_id: climate.downstairs_thermostat
        from: 'off'
      - platform: homeassistant
        event: start
    conditions:
      - not:
          - and:
              - condition: trigger
                id: daily_cycle
              - condition: state
                state: "on"
                match: any 
                entity_id:
                  - input_boolean.downstairs_hvac_vacation_mode
                  - input_boolean.downstairs_hvac_severe_weather_mode
    action:
      - service: input_number.set_value
        data:
          entity_id: input_number.downstairs_hvac_manual_cool_adj
          value:  0
      - service: input_number.set_value
        data:
          entity_id: input_number.downstairs_hvac_manual_heat_adj
          value:  0
    mode: queued

EDIT: Added And condition.

2 Likes

I like this implementation a lot - its much cleaner looking to me than the templates ideas!

I realized that an additional And condition is necessary for what you want to do, I have edited my earlier post.

I thought the “sub-conditions” under a not were already and-conditional by default? (in which case either would work?)

The Not condition is weird, in order for it to pass all the sub-conditions must return not true.

Without the And, the daily_cycle trigger will never lead to the actions being executed.

1 Like