Hefford27
(Graham Hefford)
November 20, 2017, 4:39pm
1
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.
Hefford27
(Graham Hefford)
November 20, 2017, 4:51pm
3
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/
keithh666
(Keith Hull)
November 20, 2017, 6:02pm
5
If you read thru’ this thread it will give you some ideas…
I didn’t find a component to create an alarm clock for my difficult morning, so i implement that.
It’s composed with simple modules
input_boolean :
reveil:
name: Reveil positionné
initial: off
icon: mdi:alarm
lightreveil:
name: Reveil Naturel
initial: off
icon: mdi:theme-light-dark
We declare 2 input_boolean to turn on the TV and to turn on bedroom’s light
input_select:
choixreveil:
name: "reveil matin"
icon: mdi:alarm
initial: "06:35"
op…
Hefford27
(Graham Hefford)
November 20, 2017, 8:00pm
6
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.
keithh666
(Keith Hull)
November 20, 2017, 10:02pm
8
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
The card in the frontend looks like this…
1 Like
Hello, how do you create the views for FinTime and Time from the imput_numbers?
keithh666
(Keith Hull)
April 10, 2020, 4:16pm
10
I use the following template sensors…
- platform: template
sensors:
alarm_hour:
# friendly_name: 'Hour'
entity_id: input_number.alarmhour
value_template: '{{ states("input_number.alarmhour") | round(0) }}'
alarm_minutes:
# friendly_name: 'Minutes'
entity_id: input_number.alarmmins
value_template: '{{ states("input_number.alarmmins") | round(0) }}'
alarm_time:
friendly_name: 'Time'
entity_id:
- sensor.alarm_hour
- sensor.alarm_minutes
value_template: '{% if states("sensor.alarm_hour")|length == 1 %}0{% endif %}{{ states("sensor.alarm_hour") }}:{% if states("sensor.alarm_minutes")|length == 1 %}0{% endif %}{{ states("sensor.alarm_minutes") }}'
alarm_hour_fin:
# friendly_name: 'FinHour'
entity_id: input_number.alarmfinishhr
value_template: '{{ states("input_number.alarmfinishhr") | round(0) }}'
alarm_minutes_fin:
# friendly_name: 'FinMinutes'
entity_id: input_number.alarmfinishmins
value_template: '{{ states("input_number.alarmfinishmins") | round(0) }}'
alarm_time_fin:
friendly_name: 'FinTime'
entity_id:
- sensor.alarm_hour_fin
- sensor.alarm_minutes_fin
value_template: '{% if states("sensor.alarm_hour_fin")|length == 1 %}0{% endif %}{{ states("sensor.alarm_hour_fin") }}:{% if states("sensor.alarm_minutes_fin")|length == 1 %}0{% endif %}{{ states("sensor.alarm_minutes_fin") }}'
alarm_hoursat:
# friendly_name: 'Hoursat'
entity_id: input_number.alarmhoursat
value_template: '{{ states("input_number.alarmhoursat") | round(0) }}'
alarm_minutessat:
# friendly_name: 'Minutessat'
entity_id: input_number.alarmminssat
value_template: '{{ states("input_number.alarmminssat") | round(0) }}'
alarm_timesat:
friendly_name: 'Timesat'
entity_id:
- sensor.alarm_hoursat
- sensor.alarm_minutessat
value_template: '{% if states("sensor.alarm_hoursat")|length == 1 %}0{% endif %}{{ states("sensor.alarm_hoursat") }}:{% if states("sensor.alarm_minutessat")|length == 1 %}0{% endif %}{{ states("sensor.alarm_minutessat") }}'
alarm_hour_finsat:
# friendly_name: 'FinHour'sat
entity_id: input_number.alarmfinishhrsat
value_template: '{{ states("input_number.alarmfinishhrsat") | round(0) }}'
alarm_minutes_finsat:
# friendly_name: 'FinMinutessat'
entity_id: input_number.alarmfinishminssat
value_template: '{{ states("input_number.alarmfinishminssat") | round(0) }}'
alarm_time_finsat:
entity_id:
- sensor.alarm_hour_finsat
- sensor.alarm_minutes_finsat
friendly_name: 'FinTimesat'
value_template: '{% if states("sensor.alarm_hour_finsat")|length == 1 %}0{% endif %}{{ states("sensor.alarm_hour_finsat") }}:{% if states("sensor.alarm_minutes_finsat")|length == 1 %}0{% endif %}{{ states("sensor.alarm_minutes_finsat") }}'
Hope that helps
1 Like