Automation coding for 'not state'

This is my current automation code:

- alias: 'Turn AC to idle with button click if not already idle'
  trigger: # trigger on no motion
    platform: event
    event_type: click
    event_data:
      entity_id: binary_sensor.switch_158d0001a9dbdc
      click_type: single   
  condition: # check climate.panasonic_aircon state isn't already idle
    condition: or
    conditions:
      - condition: state
        entity_id: 'climate.panasonic_aircon'
        state: 'auto'
      - condition: state
        entity_id: 'climate.panasonic_aircon'
        state: 'heat'
      - condition: state
        entity_id: 'climate.panasonic_aircon'
        state: 'cool'
      - condition: state
        entity_id: 'climate.panasonic_aircon'
        state: 'fan'
  action: # turn the AC to idle mode
    - service: persistent_notification.create
      data:
        message: "I just the AC to idle"
        title: "AC Notification"
    - service: climate.set_operation_mode
      data:
        entity_id: climate.panasonic_aircon
        operation_mode: idle

Can someone please help me with using a value template for the condition part of the automation?

2 Likes

I figured it out:

  condition:
  - condition: template
    value_template: "{{ not is_state('climate.panasonic_aircon', 'idle') }}"
32 Likes

thanks for this code. I was searching for this.

1 Like

Perfect and working !!! Thanks for sharing.

Doing the same as template condition:

condition:
  - condition: template
    value_template: "{{ states('climate.panasonic_aircon') != 'idle' }}"

But meanwhile automations became a lot smarter (easy GUI power) and Jinja template is not needed anymore for this simple use-case:

condition: not
conditions:
  - condition: state
    entity_id: climate.panasonic_aircon
    state: idle
3 Likes