Trigger with Or-condition never fires

First greetings to all and thanks for the huge amount of hints and help.
But still, it does not help me :confused:

Home Assistant runs as a docker installation on a Synology Diskstation, I did update recently. Most devices are Zigbee2mqtt which is not relevant for the problem.

My goal is to switch on my Christmas decoration in the morning. The start time shall be different for the weekend. The action simply turns on an input_boolean switch. That triggers the real switching. I found this idea in this forum. I summed up everything in a package file from where I copy parts and add english comment as the names and descriptions are in German. I do not change the code.

For completeness, this is the switch which should be toggled by the automation (innen is german for inside, lichter is lights):

input_boolean:
  # Switch to toggle group of light
  xmas_lichter_innen:
    name: "Weihnachtsbeleuchtung im Haus"
    # initial: off

I can also use it to manually turn on/off the lights.

These are the input-fields for giving different starttimes (germen startzeit)

input_datetime:
  # time when switch should turn on during the week
  xmas_innen_startzeit_morgens:
    name: "Weihnachtsbeleuchtung Zeit zum Einschalten morgens innen"
    has_date: false
    has_time: true
    initial: '06:30'

  # time when switch should turn on at weekends
  xmas_innen_startzeit_morgens_we:
    name: "Weihnachtsbeleuchtung Wochenend-Zeit zum Einschalten morgens innen"
    has_date: false
    has_time: true
    initial: '08:00'

That was the easy part, now for the automation.
The trigger should fire at both the start-time I entered in the input_datetime fields for weekdays and weekends. The condition should decide:

  1. is the time equal to weekdays start-time and do we have a weekday?
    or
  2. is the time equal to weekends start-time and do we have weekend?

If one of both is true, the input_boolean should be turned on.

automation:
  - id: xmas_innen_morgens_ein
    description: Weihnachtsbeleuchtung innen morgens ein zu fester Zeit
    alias: Weihnachtsbeleuchtung innen morgens ein
    trigger:
      - platform: time
        at: input_datetime.xmas_innen_startzeit_morgens
      - platform: time
        at: input_datetime.xmas_innen_startzeit_morgens_we
    condition:
      - condition: or
        conditions:
          - condition: template
            value_template: >-
              {{ states.sensor.time.state == states.input_datetime.xmas_innen_startzeit_morgens.state[0:5]
                 and now().weekday() < 5
              }}
          - condition: template
            value_template: >-
              {{ states.sensor.time.state == states.input_datetime.xmas_innen_startzeit_morgens_we.state[0:5]
                 and now().weekday() > 4
              }}
    action:
      - service: input_boolean.turn_on
        entity_id: input_boolean.xmas_lichter_innen
    mode: single

And this does not fire, I never found an entry in the logbook or the logfile (homeassistant.components.automation: debug).

Yes, I checked the YAML with YAML Validator and I read conditions manual. I pasted the template and parts of the template into the developer tools and watched the parts of the template to show the expected values (I love that automatic update). I also tried now().strftime instead of sensor.time and other stuff.
I have the same automation for outside lights and for both to turn them off in the evening. As an experienced programmer I am able to keep my errors consistent, so none of them four works :slight_smile:

Can anyone give me a hint what I am doing wrong?
Any relevant information missing?

I am fighting nearly two weeks now and I hope to get my lights working until christmas. At least the turn on for sunset with a delay depending on the weather :grin:

I don’t see any issue with your code. Is the automation turned on?
Did you try to remove the conditions to see if the trigger works?


 And also checking that the templates do actually validate to true when you want them to?

Did you reload automations?

Do you have other YAML automations that work, or is this your first one? (see docs for mixing editor and YAML)

Does the light come on if you execute it automatically?

@Burningstone, Automations were turned on. I have set up another automation without the conditions. That worked.
But I will give it a try.

@anon43302295, yes, that’s why I love the template editor. I showed me last week that True and "True" is not the same. That was quite tricky.

@Troon, Configurations->ServerControls just shows me “Server Management -> restart”. Which I tried.
Also I called the service “automations.reload” from Developer Tools. But normally I stop the docker-container and restart it because:

  • I do not know wether automations inside a packages are part of “automation reload”

If I trigger the automation manually, it works. That is in Logbook I can see an entry for “Weihnachtsbeleuchtung innen morgens ein” and the activated input_boolean.

I have written the package-yaml from scratch, other automations work, even from that package. That is e.g. the automations triggered by the input-switch, turning on lights in the evening by sunset and delay etc.

Ok, try removing the conditiona and replace the action part with this:

action:
  service: persistent_notification.create
  data:
    message: >
      Condition 1 is: {{ (states('sensor.time') == states('input_datetime.xmas_innen_startzeit_morgens')[0:5]) and now().weekday() < 5 }}
      Condition 2 is: {{ (states('sensor.time') == states('input_datetime.xmas_innen_startzeit_morgens_we')[0:5]) and now().weekday() > 4 }}

This way once it triggers, it shows you in a persistent notification what the state of your conditions is.

@Burningstone So this is really interesting :thinking:

Steps I took:

  1. copy the automation in question, renamed it and pasted in your action.
  2. added xmas_innen_startzeit_morgens is: {{ states('input_datetime.xmas_innen_startzeit_morgens')[0:5] }}
  3. Put some stuff in the template editor, then changed the input-time

The template editor gives the desired result, the automation not.
For completeness the automation code:

  - id: xmas_innen_morgens_notify
    description: Weihnachtsbeleuchtung innen morgens ein zu fester Zeit
    alias: Weihnachtsbeleuchtung innen morgens ein (notify)
    trigger:
      - platform: time
        at: input_datetime.xmas_innen_startzeit_morgens
      - platform: time
        at: input_datetime.xmas_innen_startzeit_morgens_we
    condition: []
    action:
      service: persistent_notification.create
      data:
        message: >
          xmas_innen_startzeit_morgens is: {{ states('input_datetime.xmas_innen_startzeit_morgens')[0:5] }}
          Condition 1 is: {{ (states('sensor.time') == states('input_datetime.xmas_innen_startzeit_morgens')[0:5]) and now().weekday() < 5 }}
          Condition 2 is: {{ (states('sensor.time') == states('input_datetime.xmas_innen_startzeit_morgens_we')[0:5]) and now().weekday() > 4 }}
    mode: single

I exchanged the sensor.time with now().strftime('%H:%M') and now the condition 1 is true.

Let’s see when I replace that in my automations

So I changed the action to

    action:
      service: persistent_notification.create
      data:
        message: >
          Condition 1a is: {{ (now().strftime('%H:%M') == states('input_datetime.xmas_innen_startzeit_morgens')[0:5]) and now().weekday() < 5 }}
          Condition 1b is: {{ (states('sensor.time') == states('input_datetime.xmas_innen_startzeit_morgens')[0:5]) and now().weekday() < 5 }}
          Condition 2 is: {{ (now().strftime('%H:%M') == states('input_datetime.xmas_innen_startzeit_morgens_we')[0:5]) and now().weekday() > 4 }}

The Notification says:
Condition 1a is: True Condition 1b is: False Condition 2 is: False
So I consider ‘sensor.time’ to be the culprit.

BTW my original automation fired as well, so my problem is solved.

@Burningstone thank you for the invaluable hint with the notification :clap:

I assume it has something to do with the type of the value, that one is converted to a string and the other is not.