Switch on device with three conditions (input_datetime included)

Hello everybody,

I’m new to HA (coming from OpenHAB) and now I am trying to get my configured automations from OH to Home Assistant.

I want to automate my washing machine and switch it on, when the following conditions are true:

  • automation is active (helper boolean.washingmachine)
  • selected time on lovelace is reached (helper input_datetime.washingmachine)
  • solar panels will produce at least the energy I selected on dashboard (helper number.washingmachine)
    The important thing is that when the time has arrived but the solar panels do not produce enough energy, then the automation should start as soon as the solar panels will reach the selected energy.

Trigger of the automation could be the automation boolean becoming true, but the I get confused about the conditions I have to set, so I hope anyone could help me :roll_eyes:

Trigger off the time and the panels providing enough power — will trigger when either is true.

Add conditions to check time is in the past and panels are providing enough power — will allow the action to run only when both are true.

So you say I should set the time and the panels as trigger or as condition?

Both, something like this:

trigger:
  - platform: time
    at: input_datetime.washingmachine
  - platform: numeric_state
    entity_id: sensor.solar_power
    above: input_number.washingmachine

condition:
  - condition: time
    after: input_datetime.washingmachine
  - condition: numeric_state
    entity_id: sensor.solar_power
    above: input_number.washingmachine

action:

You trigger when either thing happens, because you don’t know which will be first; and you include conditions for both. That way, the action will run when the second thing of the pair becomes true.

I’m not 100% sure if the combination of at: in the trigger and after: in the condition will work properly. You could use this shorthand template condition instead of the two lines for the time one:

- "{{ now()|as_timestamp|timestamp_custom('%H:%M:%S') >= states('input_datetime.washingmachine') }}"

Thank you very much, you helped me a lot, it’s working now!

Here’s the code:

alias: Waschmaschinen-Automatik ausführen
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ now()|as_timestamp|timestamp_custom('%H:%M:%S') >=
      states('input_datetime.washingmachine') }}
  - platform: numeric_state
    entity_id: sensor.solar_power
    above: input_number.washingmachine
    enabled: false
  - platform: state
    entity_id:
      - input_boolean.washingmachine
    to: "on"
condition:
  - or:
      - and:
          - condition: time
            after: input_datetime.washingmachine
          - condition: state
            entity_id: input_boolean.washingmachine
            state: "off"
      - and:
          - condition: time
            after: input_datetime.washingmachine
          - condition: state
            entity_id: input_boolean.washingmachine
            state: "on"
          - condition: numeric_state
            entity_id: sensor.solar_power
            above: input_number.washingmachine
action:
  - service: input_boolean.turn_off
    data: {}
    target:
      entity_id: input_boolean.washingmachine
mode: single

I have mixed the conditions as I want to decide if the minimum solar power should be considered or not. After execution the automation boolean helper is switched off.