Best way to code input boolean selection

I am setting up a Alarm Clock automation and need suggestions on best way to use input_boolean selection to fire if daily state is equal to on.

Here is input_boolean in my configuration.yaml file
input_boolean:
monday:
name: 1_Monday
initial: on
tuesday:
name: 2_Tuesday
initial: on
wednesday:
name: 3_Wednesday
initial: on
thursday:
name: 4_Thursday
initial: on
friday:
name: 5_Friday
initial: on
saturday:
name: 6_Saturday
initial: off
sunday:
name: 7_Sunday
initial: off

Here is the automation I currently use which has the dates listed and I just comment out the days for the alarm to not fire.

#-----------------------------------
#----Wake Up Alarm for Work Days

- id: alarm clock
  alias: "Alarm Clock Work Days"
#  hide_entity: true
  condition:
    - condition: time
      weekday:
#        - mon
        - tue
#        - wed
        - thu
        - fri
#        - sat
#        - sun
  trigger:
    platform: time
    at: '8:00:00' #Changed from after to at per log
  action:
    - service: media_player.media_play
      data:
        entity_id: media_player.runeaudio_mpd
    - service: light.turn_on
      entity_id:
        - light.cree_connected_a19_60w_equivalent_fe06c273_10
        - light.sengled_e11g13_0306678e_1
        - light.sengled_e11g13_03092691_1
        - light.sengled_e11g13_03092ed4_1

My schedule changes alot and need a way to just turn on or off each day
What I need is a way to have a condition check each day if input_boolean is on or not then if on run alarm.

Thanks for any help

- id: alarm clock
  alias: "Alarm Clock Work Days"
  condition:
    condition : or
      conditions:
        -  condition : template
           value_template: '{{ (now().strftime("%a") == 'Mon') and (states.input_boolean.1_Monday.state == 'on')}}
         -  condition : template
           value_template: '{{ (now().strftime("%a") == 'Tue') and (states.input_boolean.2_Tuesday.state == 'on')}}    
  trigger:
    platform: time
    at: '8:00:00' #Changed from after to at per log
  action:
    - service: media_player.media_play
      data:
        entity_id: media_player.runeaudio_mpd
    - service: light.turn_on
      entity_id:
        - light.cree_connected_a19_60w_equivalent_fe06c273_10
        - light.sengled_e11g13_0306678e_1
        - light.sengled_e11g13_03092691_1
        - light.sengled_e11g13_03092ed4_1

Some notes:

  1. I think it’s unlikely that input_booleans that have names that start with number will actually work.
  2. I haven’t actually run this code, so there may be formatting errors, but it should give you the JIST of what you are trying to do.

That is what I was looking for
Just need to get it working now

I added conditions for all days Mon-Sun
But when I reload automations I get the following error in the log

2017-09-09 21:51:38 ERROR (SyncWorker_0) [homeassistant.util.yaml] mapping values are not allowed here in "/config/automations.yaml", line 63, column 17 2017-09-09 21:51:38 ERROR (MainThread) [homeassistant.bootstrap] Error loading /config/configuration.yaml: mapping values are not allowed here in "/config/automations.yaml", line 63, column 17

Any ideas

Post your code and i’ll take a look.

condition:
condition : or
conditions:
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Mon’) and states.input_b$
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Tue’) and (states.input_b$
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Wed’) and (states.input_b$
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Thu’) and (states.input_b$
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Fri’) and (states.input_b$
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Sat’) and (states.input_b$
- condition : template
value_template: '{{ (now().strftime("%a") == ‘Sun’) and (states.input_b$
trigger:
platform: time
at: ‘08:00:00’ #Changed from after to at per log
action:
- service: media_player.media_play #turn_on
data:
entity_id: media_player.runeaudio_mpd
- service: light.turn_on
entity_id:
- light.cree_connected_a19_60w_equivalent_fe06c273_10
- light.sengled_e11g13_0306678e_1
- light.sengled_e11g13_03092691_1
- light.sengled_e11g13_03092ed4_1

You’ve got past errors. See where all those $ end the stings. Also, if you would please use the </> tool when posting code it would keep your formatting and give me a place to start from.

I was able to work out most of what you were trying to say.
You will have to replace the names of the input_booleans below with the names of your input_booleans.
This is valid yaml:

- alias: test
  trigger:
    platform: time
    at: '08:00:00' #Changed from after to at per log

  condition:
    condition: or
    conditions:
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Mon") and (states.input_mon.state=="on")}}'
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Tue") and (states.input_tue.state=="on")}}'
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Wed") and (states.input_wed.state=="on")}}'
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Thu") and (states.input_thu.state=="on")}}'
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Fri") and (states.input_fri.state=="on")}}'
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Sat") and (states.input_sat.state=="on")}}'
      - condition : template
        value_template: '{{ (now().strftime("%a") == "Sun") and (states.input_sun.state=="on")}}'
  action:
    - service: media_player.media_play #turn_on
      data:
        entity_id: media_player.runeaudio_mpd
    - service: light.turn_on
      entity_id:
        - light.cree_connected_a19_60w_equivalent_fe06c273_10
        - light.sengled_e11g13_0306678e_1
        - light.sengled_e11g13_03092691_1
        - light.sengled_e11g13_03092ed4_1

I still can not get this to work.
Reduced it down to just one line for the current day to troubleshoot it and its still not working.

  condition:
    condition: template
      value_template: '{{ (now().strftime("%a") == "Mon") and states.input_boolean.monday.state=="on")}}'

Copied it from the code you provided.

Thanks…

Yea, but it’s not.

You are missing the opening paren before the phrase states.input_boolean.monday

Got it working.
Thanks for the help

Here is the code to help anyone else trying this.
The name’s have 1_ etc before them to keep them sorted correctly

In configuration.yaml

input_boolean:
  monday:
    name: 1_Monday
    initial: on
  tuesday:
    name: 2_Tuesday
    initial: on
  wednesday:
    name: 3_Wednesday
    initial: on
  thursday:
    name: 4_Thursday
    initial: on
  friday:
    name: 5_Friday
    initial: on
  saturday:
    name: 6_Saturday
    initial: off
  sunday:
    name: 7_Sunday
    initial: off

This is the Automation

#-----------------------------------
#----Wake Up Alarm for Work Days

- id: Alarm Clock
  alias: "Alarm Clock Work Days"
#  hide_entity: true

  condition:
    condition: or
    conditions:
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Mon") and (states.input_boolean.monday.state=="on")}}'
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Tue") and (states.input_boolean.tuesday.state=="on")}}'
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Wed") and (states.input_boolean.wednesday.state=="on")}}'
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Thu") and (states.input_boolean.thursday.state=="on")}}'
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Fri") and (states.input_boolean.friday.state=="on")}}'
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Sat") and (states.input_boolean.saturday.state=="on")}}'
      - condition: template
        value_template: '{{ (now().strftime("%a") == "Sun") and (states.input_boolean.sunday.state=="on")}}'

trrigger:
    platform: time
    at: '08:00:00' #Changed from after to at per log
  action:
    - service: media_player.media_play
      data:
        entity_id: media_player.runeaudio_mpd
    - service: light.turn_on
      entity_id:
        - light.cree_connected_a19_60w_equivalent_fe06c273_10
        - light.sengled_e11g13_0306678e_1
        - light.sengled_e11g13_03092691_1
1 Like

Now that I have this working of course I want to make it better.
Created a input_select to pick the wake up time.
But not sure how to use that variable in my automation

Here is the input_select

input_select:
  alarmtime:
    name: "Alarm Time"
    icon: mdi:alarm
    initial: "08:00:00"
    options:
      - "07:00:00"
      - "07:30:00"
      - "08:00:00"
      - "08:30:00"
      - "09:00:00"
      - "09:30:00"
      - "10:00:00"

And my automation.
Just can’t figure out how to use the variable from input_select
instead of hard coded time.

Here is the trigger and action I am using now

  trigger:
    platform: time
    at: '08:00:00' #Changed from after to at per log
  action:
    - service: media_player.media_play
      data:
        entity_id: media_player.runeaudio_mpd
    - service: light.turn_on
      entity_id:
        - light.cree_connected_a19_60w_equivalent_fe06c273_10
        - light.sengled_e11g13_0306678e_1
        - light.sengled_e11g13_03092691_1
        - light.sengled_e11g13_03092ed4_1

change your trigger to run every 5 minutes.
Then add to your template yet another condition where the current time matches your input time.
There are LOTS of examples of Home Assistant alarm clocks
Here’s one that eventually gets to what you want:

I have looked at all of the other examples of alarm clocks and it just looks to me like they handle it in a overly complicated way.

Maybe that is required.

Do you know of a way to just use the input_select variable alarmtime
to replace the “08:00:00” I have hard coded.

Thanks…