Time Input Sliders Help

Hello

I am pushing my knowledge of Home Assistant even more, and have got stuck on how to to the following.

Currently i have hard coded in my automations a time that trigger after a time in the evening and stop triggering at a time in the morning. However when my wife wants this to change or its a dull day, it means i have to change the automation code.

What I was thinking about a slider that show 15 min increments from 15:00 to 22:00 and another Sliders from 05:00 to 08:00.

how do i create these any ideas ?

Thanks

1 Like

the following depends on what version of HA you are running. recently (version 0.55), input_slider was renamed to input_number and was a breaking change, but functionally they are the same.

Are you using the time as a trigger or a condition for the automation? Can you post the automation?

first you’ll want to create your two input numbers following the docs: https://home-assistant.io/components/input_number/

Then in your automation you can use those input numbers in a template to condition or trigger the automation.

Hi @squirtbrnr

here is an example of the automation

- alias: 'Turn On Lounge Lights with Motion'
  initial_state: 'on'
  trigger:
    platform: state
    entity_id: binary_sensor.motion_sensor_158d00015dc0c3
    to: 'on'
  condition:
    condition: time
    before: '06:30:00'
    after: '16:00:00'
  action:
    service: light.turn_on
    data:
      entity_id: group.lounge_lamps

I have read the input slider, but couldn’t work out how to put it into time ?

Thanks

I just ran into this helping someone with another automation. I don’t think you can use a template in the before/after of a time condition. If you can it would look something like this:

before: '{{states.input_number.number1.state | int }}:{{states.input_number.number2.state | int }}:00'
after: '{{states.input_number.number3.state | int }}:{{states.input_number.number4.state | int }}:00'

You’ll have to create 4 input numbers, 2 for your before hours and minutes and the other 2 for your after hours and minutes. if you want to decrease the number of inputs, look at an input_time component. If the above example doesn’t work then you may have to do a template condition that dose a comparison of the current time hours/minutes to the set hours/minutes. a template condition returns ‘True’ or ‘False’.

EDIT: your input number would look like this:

input_number:
  number1:
    name: Before Hours
    initial: 15
    min: 13
    max: 17
    step: 1
    mode: box
  number1:
    name: Before Minutes
    initial: 0
    min: 0
    max: 45
    step: 15
    mode: box

and here’s info on the input_datetime component. Unfortunately, I’m not familiar with it as I haven’t used it yet. https://home-assistant.io/components/input_datetime/

If you read thru’ this thread it will give you some ideas…

thanks trying to work out how to use this, i can see how you would turn something on, but now to allow automation to work during a time period…

- service: automation.turn_off
  entity_id: automation.<name>

put that in the action of an automation and it will disable the automation you call out in the entity. You would need to either manually re-enable the automation or have another automation to turn it back on. turning on/off is different than triggering.

Errm the very first post shows how to set things up as you want them using input_select, but if you read thru’ the thread it show how to do it using input_sliders (now renamed to input_number - but they do the same thing and the code is the same).

So…

in input_number.yaml

alarmhour:
  name: Alarm Hour
  icon: mdi:timer
  initial: 06
  min: 0
  max: 23
  step: 1
alarmmins:
  name: Alarm Minutes
  icon: mdi:timer
  initial: 00
  min: 0
  max: 59
  step: 1
alarmfinishhr:
  name: Finish Hour
  icon: mdi:watch-export
  initial: 07
  min: 0
  max: 23
  step: 1
alarmfinishmins:
  name: Finish Minutes
  icon: mdi:watch-export
  initial: 05
  min: 0
  max: 55
  step: 5

Automation.yaml

###############################################################################################
#                                                                                             #
# Alarm Clock                                                                                 #
#                                                                                             #
#                                                                                             #
###############################################################################################
        
 - alias: 'Wake Me Up'
   initial_state: 'on'
   trigger:
     - platform: time
       minutes: '/1'
       seconds: '0'
   condition:
      condition: or
      conditions:
        - condition: and
          conditions:
            - condition: state
              entity_id: input_boolean.alarmstatus
              state: 'on'
            - condition: state
              entity_id: input_boolean.alarmweekday
              state: 'on'
            - condition: time
              weekday:
                - mon
                - tue
                - wed
                - thu
                - fri
                - sat
            - condition: template
              value_template: '{{ now().time().strftime("%R") == states.sensor.alarm_time.state }}'
        - condition: and
          conditions:
            - condition: state
              entity_id: input_boolean.alarmstatus
              state: 'on'
            - condition: state
              entity_id: input_boolean.alarmweekday
              state: 'off'
            - condition: template
              value_template: '{{ now().time().strftime("%R") == states.sensor.alarm_time.state }}'
   action:
     - service: tts.google_say
       data:
         entity_id: media_player.speaker_1
         message: "Good morning Sir. Time to Wake Up!"         
     - service: switch.turn_on
       entity_id: 
         - switch.zw_bedroomsunlamp_switch
         - switch.rfl_bedroom_pcmonitorandsound
     - service: light.turn_on
       entity_id: 
         - light.rfl_bedroom_ceiling_light
         - light.rfl_bedroom_uplightredbottomlamp
     - service: light.turn_on
       data:
         entity_id: light.zw_uplight_dimmer_level
         brightness_pct: 70
     - delay: '00:00:20'
     - service: switch.turn_on
       entity_id: switch.veho_power
                   
 - alias: Turn off Alarm
   initial_state: 'on'
   trigger:
     - platform: time
       minutes: '/1'
       seconds: '0'   
   condition:
     - condition: template
       value_template: '{{ now().time().strftime("%R") == states.sensor.alarm_time_fin.state }}'     
   action:
     - service: homeassistant.turn_off
       entity_id:
         - light.rfl_bedroom_ceiling_light
         - light.rfl_bedroom_uplightredbottomlamp
         - switch.zw_bedroomsunlamp_switch
         - switch.rfl_bedroom_pcmonitorandsound
         - switch.zw_tvandsoundbar_switch

I have an input_boolean to turn it on and off as well. There are other ways probably more efficient but this works. There are new components which would probably make this better but I haven’t got round to looking at them yet. The alarm thread does have many other examples of how you could achieve what you want.

Hopefully that helps you get yours setup :slight_smile:

The card in the frontend looks like this…
image

1 Like