Automation with multiple conditions

Hi all,
I cannot get the following automation with multiple conditions to work, it never posts the mqtt even tho it meets both conditions
Been Trying to work it out for a few days

  alias: Dryer - Idle
  description: ''
  trigger:
  - payload: Drying
    platform: mqtt
    topic: hass/state/dryer
  - entity_id: binary_sensor.dryer
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - condition: and
    conditions:
    - condition: template
      value_template: '{{ trigger.payload.endswith(''Drying'') }}'
    - condition: state
      entity_id: binary_sensor.dryer
      state: 'off'
  action:
  - data:
      payload: Idle
      topic: hass/state/dryer
    service: mqtt.publish

Your automation has two triggers and each uses a different platform (mqtt and state). That means the resulting Trigger State object will have different properties depending on what triggered the automation.

If triggered by the state platform, the Trigger State object will have:

  • trigger.from_state.state = on
  • trigger.to_state.state = off

What it won’t contain is trigger.payload which means the first of the two ANDed conditions won’t be satisfied and the action will not be executed.

Thank you, is there a way to create conditions based on 2 platforms?

Yes. In this particular case it requires a template that first checks if trigger.payload exists before attempting to use it.

What I don’t understand about this automation is why it can be triggered by either the binary_sensor or the mqtt topic but the condition requires both. If it is triggered by the binary_sensor, the condition will never be able to evaluate trigger.payload.

Can you explain how the dryer is being monitored and what exactly must happen for the dryer to be in idle mode?

Thanks for the help, your above hint guided me to create a sensor based on the MQTT state. Then I could create an automation with 2 conditions on the same platform.

Now it works.

I appreciate the help, thank you again

I see you are a new member and so you may not be familiar with the customs of this community forum.

When you mark a post with the Solution tag, it represents the one that either supplied the solution or led to the formulation of one.

In this case, you marked your own post as the Solution without revealing the actual solution.

Most solutions on this forum involve entities and automations so simply stating you created a sensor and an automation with 2 conditions is not actually revealing anything. The purpose of a Solution post is to help others resolve a similar (or identical) problem.

To help others, please supply the details of what you created that helped to resolve the issue. Then that post will qualify as a proper Solution.

1 Like