Is this the correct syntax for selecting a conditional trigger time

using the workday binary_sensor to select action in an automation, would this be correct? only have the 11 and 11:30 triggers lead to action on work days?

  - alias: Turn off morning switches at 11
    id: Turn off morning switches at 11
    trigger:
      - platform: time
        at: '11:00'
      - platform: time
        at: '11:30'
      - platform: time
        at: '12:00'
    condition:
      - >
        {{states('input_select.activity') not in ['Slapen','Gym']}}
      - >
        {{trigger.to_state.state not in ['11:00','11:30'] or
           is_state('binary_sensor.workday_sensor','on')}}

Secondly, I cant seem to find why the workday binary sensors creates a binary_sensor.workday_sensor, instead of binary_sensor.workday, which would suffice. The suffix _sensor really is redundant?

# https://home-assistant.io/components/binary_sensor.workday/
# https://github.com/home-assistant/core/blob/60838cf7edd82c9165dd323325148bd35969ecbc/homeassistant/components/workday/binary_sensor.py
  - platform: workday
    country: NL

creates that, and in the code there’s no mentioning of the suffix

No, you need to wrap your statement into a Template Condition.

thanks, but I am not sure that would be necessary? to elaborate: I had it functioning with the 3 triggers, and the first condition only.

It triggers every day on the given times, checks the activity condition , and performs the action.

Today I only wanted to add the 2nd condition, that it shouldn’t act on the 2 times when not a workday.

I was merely insecure whether the trigger.to_state.state was the correct trigger for checking these times?
Coming to think of it, I could of course also use the sensor.time for that

{{states('sensor.time') not in ['11:00','11:30']}}

You are right, did miss this shorthand syntax so far. I suspect the state of the Time Trigger is different from the format to specificy. So, triggering at ‘11:00’ could result in trigger.to_state.state being someting like ‘11:00:00’.

Maybe use traditional syntax here:

condition:
  - "{{states('input_select.activity') not in ['Slapen','Gym']}}"
  - condition: OR
    conditions:
      - condition: time
        after: '11:30:00'
      - condition: state
        entity_id: binary_sensor.workday_sensor
        state: "on"

The sensor’s name is computed from the “name” attribute and by default that name is “Workday Sensor”. Add a custom “name” to override this.

can confirm

    condition:
      - >
        {{states('input_select.activity') not in ['Slapen','Gym']}}
      - >
        {{states('sensor.time') not in ['11:00','11:30'] or
           is_state('binary_sensor.workday_sensor','on')}}

to work, the trigger.to_state.state version doesnt.

yeah thanks, I could do that indeed, forgot about that.
Or create a PR :wink:

-edit_

these work too:

{{as_timestamp(trigger.now)|timestamp_custom('%H:%M')}}
# or            
{{trigger.now.strftime('%H:%M')}}

see: Automation trigger variables - Home Assistant for the Available Trigger data