mbonani
(Mauricio Bonani)
August 18, 2017, 2:38am
224
I need help on identifying why my automation is not running even when the template in the trigger returns true (tested in the Developer Tools).
Sensors:
- platform: template
sensors:
alarm_clock_hour:
value_template: '{{ states.input_slider.alarm_clock_hour.state|int }}'
alarm_clock_minute:
value_template: '{{ states.input_slider.alarm_clock_minute.state|int }}'
alarm_clock_time:
value_template: >-
{{ states.sensor.alarm_clock_hour.state }}:
{%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
0
{%- endif -%}
{{ states.sensor.alarm_clock_minute.state }}
alarm_clock_time_long:
value_template: >-
{% if states.sensor.alarm_clock_hour.state|length == 1 -%}
0
{%- endif -%}
{{ states.sensor.alarm_clock_hour.state }}:
{%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
0
{%- endif -%}
{{ states.sensor.alarm_clock_minute.state }}
alarm_clock_start:
value_template: '{{ ((as_timestamp(now())|int + 300)|timestamp_custom("%H:%M")) }}'
Automation:
- alias: 'almclk_wake_up script triggered by alarm clock'
trigger:
platform: template
value_template: '{{ states.sensor.alarm_clock_start.state == states.sensor.alarm_clock_time_long.state }}'
condition:
condition: state
entity_id: input_boolean.alarm_clock_status
state: 'on'
action:
service: script.wake_up
patkap
August 18, 2017, 7:17am
225
I found post#73 to be very informative at the time: a very nice rewording of the actual documentation on automation template and time triggers. tldr:
leverage the time_date
platform in value_template just like yours:
'{{ states("sensor.time") == states("sensor.alarmclock_lights_time") }}'
the other option is to trigger evaluation every ‘/n’ time unit with a time
platform trigger
since at:
won’t take a template.
Relative time calculations can horribly complexify the template expression. I, for myself, try to stick to kiss approach, favoring decoupling in general and ultimately thinking packaging when it comes to my configuration.
mbonani
(Mauricio Bonani)
August 18, 2017, 4:07pm
226
@patkap thank you for your answer. I tried your suggestions, but unfortunately they did not work either.
This is so sad, I can’t understand why this is the only automation that’s not working.
Hi @mbonani ,
for me it works with that :
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.automa
state: 'on'
- condition: state
entity_id: calendar.jours_feries_en_france
state: 'off'
- condition: template
value_template: '{{ ((now().strftime("%s") | int + 300) | timestamp_custom("%H:%M") == states.sensor.alarm_time.state) }}'
action:
- service: light.turn_on
entity_id: light.chambre
data:
transition: 600
brightness: 255
you could test with the trigger /1 minutes …
patkap
August 18, 2017, 5:46pm
228
Just tested with the copied and pasted code you provided plus some missing bits …
input_slider:
alarm_clock_hour:
initial: 6
min: 0
max: 23
step: 1
alarm_clock_minute:
initial: 45
min: 0
max: 59
step: 1
input_boolean:
alarm_clock_status:
initial: on
sensor:
- platform: time_date
display_options:
- 'time'
- platform: template
sensors:
alarm_clock_hour:
value_template: '{{ states.input_slider.alarm_clock_hour.state|int }}'
alarm_clock_minute:
value_template: '{{ states.input_slider.alarm_clock_minute.state|int }}'
alarm_clock_time:
value_template: >-
{{ states.sensor.alarm_clock_hour.state }}:
{%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
0
{%- endif -%}
{{ states.sensor.alarm_clock_minute.state }}
alarm_clock_time_long:
value_template: >-
{% if states.sensor.alarm_clock_hour.state|length == 1 -%}
0
{%- endif -%}
{{ states.sensor.alarm_clock_hour.state }}:
{%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
0
{%- endif -%}
{{ states.sensor.alarm_clock_minute.state }}
alarm_clock_start:
value_template: '{{ ((as_timestamp(now())|int + 300)|timestamp_custom("%H:%M")) }}'
automation:
- alias: 'almclk_wake_up script triggered by alarm clock'
trigger:
platform: template
value_template: '{{ states.sensor.time.state == states.sensor.alarm_clock_time_long.state }}'
condition:
condition: state
entity_id: input_boolean.alarm_clock_status
state: 'on'
action:
service: persistent_notification.create
data_template:
title: 'Alarm!'
message: '{{ trigger.to_state.state }}
Options !
j.assuncao
(Jorge Assunção)
August 18, 2017, 8:06pm
229
@Vantskruv
I had the same problem with the time and changed the script from (now().strftime("%s") | int | timestamp_custom("%H:%M"))
to as_timestamp (now()) | timestamp_custom("%H:%M")
and now everything works fine.
mbonani
(Mauricio Bonani)
August 19, 2017, 9:14pm
230
I forgot to post I had the same problem. For some reason now().strftime("%s")
returns weird values here, as_timestamp(now())
solved it.
((now().strftime("%s")|int)|timestamp_custom("%H:%M")) == 13:23
((as_timestamp(now())|int)|timestamp_custom("%H:%M")) == 17:23
mbonani
(Mauricio Bonani)
August 19, 2017, 9:18pm
231
@Vantskruv and @j.assuncao , are you guys using Hassio?
j.assuncao
(Jorge Assunção)
August 19, 2017, 9:31pm
232
@mbonani Yes, i am using hass.io
mbonani
(Mauricio Bonani)
August 19, 2017, 10:35pm
233
Just started a test environment (Python virtualenv in a fresh installed Debian) and it worked fine:
((now().strftime("%s")|int)|timestamp_custom("%H:%M")) == 18:31
((as_timestamp(now())|int)|timestamp_custom("%H:%M")) == 18:31
It must be some problem with Hassio.
j.assuncao
(Jorge Assunção)
August 19, 2017, 11:05pm
234
@mbonani can it be the configurations of time zone being different between Home Assistant and Resin OS??
I’ve tried to gain access to Hassio core via ssh on port 22222 but it gives me an error using Putty “Disconnected: No supported authentication methods available (server sent: publickey)”. I’ve used this: https://home-assistant.io/developers/hassio/debugging/
Can you please confirm if the timezone configuration is different?
mbonani
(Mauricio Bonani)
August 19, 2017, 11:59pm
235
@j.assuncao did you use pageant to load your private key before trying to access?
mbonani
(Mauricio Bonani)
August 20, 2017, 12:11am
236
Different timezones
$ ssh -p 22222 [email protected]
root@hassio:~# date
Sun Aug 20 00:08:48 UTC 2017
$ ssh [email protected]
core-ssh:~# date
Sat Aug 19 20:09:55 EDT 2017
1 Like
j.assuncao
(Jorge Assunção)
August 20, 2017, 12:16am
237
@mbonani Yes, i used Pageant to load the key…
mbonani
(Mauricio Bonani)
August 20, 2017, 12:26am
238
Just create a file named authorized_keys
in the root of the resin-boot
partition containing your public key in the following way:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCg14Wi4…
You can copy this information from the SSH add-on configuration
1 Like
mbonani
(Mauricio Bonani)
August 20, 2017, 1:43am
239
Started another test environment, using Raspbian this time:
((now().strftime("%s")|int)|timestamp_custom("%H:%M")) == 17:41
((as_timestamp(now())|int)|timestamp_custom("%H:%M")) == 21:41
Actually it must be something related to the ARM packages
j.assuncao
(Jorge Assunção)
August 20, 2017, 1:48am
240
That is very strange @mbonani …
mbonani
(Mauricio Bonani)
August 20, 2017, 1:13pm
241
@hokagegano I just tried that:
- alias: 'alarm clock'
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_clock_status
state: 'on'
- condition: state
entity_id: input_boolean.vacation_mode
state: 'off'
- condition: template
value_template: '{{ states("sensor.alarm_clock_start") == states("sensor.alarm_clock_time_long") }}'
action:
service: script.wake_up
It didn’t work
- alias: 'alarm clock'
trigger:
- platform: time
minutes: '/1'
seconds: 0
condition:
- condition: state
entity_id: input_boolean.alarm_clock_status
state: 'on'
- condition: state
entity_id: input_boolean.vacation_mode
state: 'off'
action:
service: script.wake_up
If I remove the template the automation triggers normally. But this template is the most important part in my case.
Back to the drawing board!
mbonani
(Mauricio Bonani)
August 20, 2017, 1:22pm
242
@patkap did it work?
I noticed you used states.sensor.time.state
in the template. I used states.sensor.alarm_clock_start.state
because I want the automation to be triggered 5 minutes before the time I set using the sliders.
Anyway thanks for your help.
PS: I’ll try other approaches when I get back.
bboti86
(Botond Barabas)
August 22, 2017, 7:36pm
243
Dear All,
this might be a completely off topic question but since this is a very complex method and it seems like it is an extremely interesting functionality.
Maybe it would make sense to create a component for Home Assistant that would handle everything in one go.
What do you think?
Would it be possible?
Thanks!
B
2 Likes