Strange automation behavior: Only one part of action fires

Look at this simple automation. It’s waiting for a sensor to report a code other than RDY for longer than 7 seconds. I noticed that I was getting device notifications, but not log messages. I created this simple automation to verify I’m getting the same “half” notification. But what’s really strange is the condition fails, so I don’t know why it’s firing at all!


  - alias: "LR Error"
    trigger:
      platform: state
      entity_id: "sensor.status_code"
      for:
        seconds: "7"
    condition:
      - condition: template
        # value_template: "{{ states.sensor.status_code != 'RDY' and trigger.to_state.state != 'RDY'}}" #works
        value_template: "{{ states.sensor.status_code != 'RDY' }}"
    action:
      - service: system_log.write
        data_template:
          message: "LR CODE FROM: {{ trigger.from_state.state }} TO: {{ trigger.to_state.state }}"
          level: warning
      - service: notify.my_devices
        data_template:   
          title: "LR Error"
          message: "LR CODE FROM: {{ trigger.from_state.state }} TO: {{ trigger.to_state.state }}"

When my sensor changes from XXX to RDY, despite the condition, only half of the action fires. I’m getting a device notification, but nothing in the log appears. Changing the sensor value to something else and both items fire.

Is this two bugs in one issue?

You can verify this by creating a dummy sensor

    status_code:
      value_template: >-
         XXX

And then use the developer page to manually change the state to ABC, wait 10 secs and check logs, change state to RDY, wait and check logs again. Of course you will need to use your notify service.

value_template: "{{ states.sensor.status_code.state != 'RDY' }}"
                                              ^^^^ Missing from yours

You should use this though:

value_template: "{{ states('sensor.status_code') != 'RDY' }}"

Because:

1 Like