Hi all.
I managed to show the correct value in the tab is the following code:
value_template: '{% if states.input_slider.alarmhour.state| length < 4 %}0{{ states.input_slider.alarmhour.state | int }}{% endif %}{% if states.input_slider.alarmhour.state| length > 3 %}{{ states.input_slider.alarmhour.state | int }}{% endif %}:{% if states.input_slider.alarmminutes.state | length < 4 %}0{{ states.input_slider.alarmminutes.state | int }}{% endif %}{% if states.input_slider.alarmminutes.state | length > 3 %}{{ states.input_slider.alarmminutes.state | int }}{% endif %}'
Dracoy
(Dracoy)
August 3, 2016, 1:30am
55
I tried the code you used but the time I get is 8:0:30.0 any ideas?
I guess I’m having a hard time figuring out what to update on sensor and automation section. Thank you guys!
To fix this, I have created 2 new sensors; sensor.alarm_hour
and sensor.alarm_minutes
. These will take the value from the sliders and Round it to 0.
Then update the sensor.alarm_time
and the automation to use the 2 new sensors.
Here is the complete code.
input_slider:
alarmhour:
name: Hour
icon: mdi:timer
initial: 9
min: 0
max: 23
step: 1
alarmminutes:
name: Minutes
icon: mdi:timer
initial: 0
min: 0
max: 55
step: 5
input_boolean:
alarmstatus:
name: Wake Me Up
initial: off
icon: mdi:alarm-check
alarmweekday:
name: Weekdays Only
initial: off
icon: mdi:calendar
sensor:
platform: template
sensors:
alarm_hour:
friendly_name: 'Hour'
value_template: '{{ states("input_slider.alarmhour") | round(0) }}'
alarm_minutes:
friendly_name: 'Minutes'
value_template: '{{ states("input_slider.alarmminutes") | round(0) }}'
alarm_time:
friendly_name: 'Time'
value_template: '{{ states("sensor.alarm_hour") }}:{% if states("sensor.alarm_minutes")|length == 1 %}0{% endif %}{{ states("sensor.alarm_minutes") }}'
group:
default_view:
view: yes
entities:
- group.alarmclock
alarmclock:
name: Wake Me Up
entities:
- sensor.alarm_time
- input_slider.alarmhour
- input_slider.alarmminutes
- input_boolean.alarmstatus
- input_boolean.alarmweekday
automation
- alias: 'Wake Me Up'
trigger:
platform: template
value_template: '{{ now.time().strftime("%-H") == states.sensor.alarm_hour.state and now.time().strftime("%-M") == states.sensor.alarm_minutes.state }}'
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
- condition: and
conditions:
- condition: state
entity_id: input_boolean.alarmstatus
state: 'on'
- condition: state
entity_id: input_boolean.alarmweekday
state: 'off'
action:
service: notify.notify
data:
message: 'Good morning. Time to Wake Up!'
title: ""
3 Likes
openha
(Open Home automation)
August 9, 2016, 7:23pm
57
I’ve fixed the “.0” problem by using round():
value_template: ‘{{ states.input_slider.alarmhour.state | round(0) }}:{% if states.input_slider.alarmminutes.state|length == 1 %}0{% endif %}{{ states.input_slider.alarmminutes.state | round(0) }}’
1 Like
I think this is a great example that deserves more publicity.
So it would be great if someone would add it here:
1 Like
Hi, I just found this discussion. I have a problem with time triggered automation …
Now I’ve edit new configuration, just for testing input_slider and time trigger :
homeassistant:
# Name of the location where Home Assistant is running
name: E.R.S.A
latitude: -6.1744
longitude: 106.8294
elevation: 2
# C for Celcius, F for Fahrenheit
unit_system: imperial
time_zone: Asia/Jakarta
# Show links to resources in log and frontend
# introduction:
# View all events in a logbook
logbook:
# Track the sun
#sun:
# Enables support for tracking state changes over time.
history:
# Checks for available updates
updater:
# Allows you to issue voice commands from the frontend
conversation:
# Enables the frontend
frontend:
# Discover some devices automatically
# discovery:
http:
api_password: admin
mqtt:
broker: 127.0.0.1
port: 1883
client_id: home-assistant-1
keepalive: 60
sensor:
platform: template
sensors:
alarm_time:
friendly_name: 'Time'
value_template: '{% if states.input_slider.alarmhour.state| length < 4 %}0{{ states.input_slider.alarmhour.state | int }}{% endif %}{% if states.input_slider.alarmhour.state| length > 3 %}{{ states.input_slider.alarmhour.state | int }}{% endif %}:{% if states.input_slider.alarmminutes.state | length < 4 %}0{{ states.input_slider.alarmminutes.state | int }}{% endif %}{% if states.input_slider.alarmminutes.state | length > 3 %}{{ states.input_slider.alarmminutes.state | int }}{% endif %}:00'
input_slider:
alarmhour:
name: Hour
icon: mdi:timer
initial: 9
min: 0
max: 23
step: 1
alarmminutes:
name: Minutes
icon: mdi:timer
initial: 1
min: 0
max: 59
step: 1
group:
Test:
- sensor.alarm_time
- input_slider.alarmhour
- input_slider.alarmminutes
automation:
alias: 'Wake Me Up'
trigger:
platform: time
after: '{{ states.sensor.alarm_time.state }}'
action:
service: persistent_notification.create
data:
message: "{{ states.sensor.alarm_time.state }}"
title: "message"
Bad news, till now that code didnt work well for me.
But if I changed parameter trigger value to “minutes: ‘/1’”, notification appeared perfectly.
Please help me.
1 Like
choch
September 26, 2016, 1:29pm
60
Found a better way to format the slider values:
value_template: ‘{{ “%0.02d:%0.02d” | format(states(“input_slider.peter_hour”) | int, states(“input_slider.peter_minutes”) | int) }}’
1 Like
nahornyy
(Nahornyy)
September 30, 2016, 3:32am
61
After upgrade to 29.4 my alarm clock don’t work.
I am use this string as triger:
value_template: ‘{{ now().time().strftime("%-H") == states.sensor.alarm_hour.state and now().time().strftime("%-M") == states.sensor.alarm_minutes.state }}’
Try…
value_template: '{{ now().strftime("%-H") == states.sensor.alarm_hour.state and now().strftime("%-M") == states.sensor.alarm_minutes.state }}'
Here is my latest sample code…
Changes:
Fix now()
issue caused by changes in version 0.29
Format the sensor template base on suggestion from @choch (thanks!)
Remove input_boolean.alarmstatus
because we can now turn on/off the automation from the front end introduced in version 0.28 (replace by automation.wake_me_up
in group)
Sample code:
input_slider:
alarmhour:
name: Hour
icon: mdi:timer
initial: 9
min: 0
max: 23
step: 1
alarmminutes:
name: Minutes
icon: mdi:timer
initial: 0
min: 0
max: 55
step: 5
input_boolean:
alarmweekday:
name: Weekdays Only
initial: off
icon: mdi:calendar
sensor:
platform: template
sensors:
alarm_time:
friendly_name: 'Time'
value_template: '{{ "%0.02d:%0.02d" | format(states("input_slider.alarmhour") | int, states("input_slider.alarmminutes") | int) }}'
group:
default_view:
view: yes
entities:
- group.alarmclock
alarmclock:
name: Wake Me Up
entities:
- automation.wake_me_up
- sensor.alarm_time
- input_slider.alarmhour
- input_slider.alarmminutes
- input_boolean.alarmweekday
automation:
- alias: 'Wake Me Up'
trigger:
platform: template
value_template: '{{ now().strftime("%H") == "%0.02d" | format(states("input_slider.alarmhour") | int) and now().strftime("%M") == "%0.02d" | format(states("input_slider.alarmminutes") | int) }}'
condition:
condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.alarmweekday
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.alarmweekday
state: 'off'
action:
service: notify.notify
data:
message: 'Good morning. Time to Wake Up!'
title: ""
2 Likes
nahornyy
(Nahornyy)
September 30, 2016, 6:05am
64
Does not work.
But I noticed - if I move the slider “minutes” to the current time - avtomation work. And if I move slider even for a several minutes forward - automation dont work.
lv-88
October 2, 2016, 11:44am
65
Yeah broken here too
On the latest version, and tried the updated code above, but does not work unfourtantly.
I have updated the above sample code because there was an indentation mistake in the automation.
lv-88
October 3, 2016, 4:34pm
67
Hey!
I updated it but it behaves odd, if I press the automation and trigger it from hass manually then it triggers, but when setting a time and all that to let it activate like that then it doesn’t work I tried copying everything you did but ever since I updated hass to latest version it’s a no go, don’t know what else to do
Thanks for being so quick and awesome to respond btw!
weird. i changed my code back to earlier version and it also failed. Maybe it is a bug in version 0.29.6. anyone has any success?
After further testing, I found out this automation works in version 0.28.2. After I upgraded back to 0.29.6 and change the now.time().strftime to now().strftime, it stop working…
- alias: 'Wake Me Up'
trigger:
platform: template
value_template: '{{ now().strftime("%-H") == states.sensor.alarm_hour.state and now().strftime("%-M") == states.sensor.alarm_minutes.state }}'
condition:
condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.alarmweekday
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.alarmweekday
state: 'off'
action:
service: notify.telegram
data_template:
message: 'Good morning. Time to Wake Up!'
title: ""
What error do you get? I’m having a problem with a similar automation: thread
adi
(Adithyan)
October 9, 2016, 2:27pm
72
@nahornyy @lv-88
Did either of you figure this out? I have a similar problem too!
template triggers only check for their triggers when one of the entity’s specified in value_template it’s state changes if their state does not change the template trigger value is not checked and no trigger will trigger.
a workaround might be to create a time sensor with hours & minutes and add this sensors in value_template somehow without it having an effect like so perhpas (not tested)
sensor:
- platform: template
sensors:
time:
value_template: '{{ now().strftime("%H:%M")}}'
and change the value template to include the sensor.time like so for example
value_template: '{{ (now().strftime("%-H") == states.sensor.alarm_hour.state and now().strftime("%-M") == states.sensor.alarm_minutes.state) and states.sensor.time == states.sensor.time }}'
the time sensors state will change every minute so the trigger is being checked at least every minute.
A better way is to use the a time trigger that checks every minute with a template condition
something like (not tested)
automation:
- alias: 'Wake Me Up'
trigger:
platform: time
minutes: '/1'
seconds: 0
condition:
condition: or
conditions:
- condition: and
conditions:
- condition: state
entity_id: input_boolean.alarmweekday
state: 'on'
- condition: time
weekday:
- mon
- tue
- wed
- thu
- fri
- condition: state
entity_id: input_boolean.alarmweekday
state: 'off'
- condition: template
value_template: '{{ now().strftime("%-H") == states.sensor.alarm_hour.state and now().strftime("%-M") == states.sensor.alarm_minutes.state }}'
action:
service: notify.telegram
data_template:
message: 'Good morning. Time to Wake Up!'
title: ""