#Pulling attributes from !input

12 messages ยท Page 1 of 1 (latest)

topaz lake
#

I have an input in an automation...

  input:
    alarm_time:
      name: Alarm Time
      description: Set the alarm time (when you want the light at full brightness).
      selector:
        entity:
          filter:
            - domain: input_datetime

I then have some variables and my trigger...

variables:
  start_before: !input start_before
  alarm_time: !input alarm_time

trigger:
  - platform: template
    #value_template: "{{ now().timestamp() | timestamp_custom('%H:%M') == (state_attr('input_datetime.sunrise_alarm', 'timestamp') - 1 ) | timestamp_custom('%H:%M', false) }}"
    value_template: "{{ now().timestamp() | timestamp_custom('%H:%M') == state_attr(alarm_time, 'timestamp') | timestamp_custom('%H:%M', false) }}"

The commented out trigger works, but I'd like to understand why the current one does not (the difference being input_datetime.sunrise_alarm being replaced with the alarm_time variable)
I messed around in the template editor and also get errors. Could someone explain why it's not working and possibly how I would go about achieving what I want?
Thanks!

warm grove
#

'alarm_time' should not be in quotes if it's a variable

topaz lake
warm grove
#

that doesn't make sense

#

state_attr pulls an attribute from an entity

#

alarm_time is not an entity but the state of an entity

#
{% set alarm_time = 'input_datetime.sunrise_alarm' %}
{{ state_attr(alarm_time, 'timestamp') }}

That would pull the timestamp attribute from the input_datetime

topaz lake
#

Aaah. Interesting. Makes sense. ๐Ÿ‘
I am still getting an error though...

Template variable error: 'alarm_time' is undefined when rendering '{{ now().timestamp() | timestamp_custom('%H:%M') == state_attr(alarm_time, 'timestamp') | timestamp_custom('%H:%M', false) }}'

With...

variables:
  start_before: !input start_before
  alarm_time: !input alarm_time

trigger:
  - platform: template
    #value_template: "{{ now().timestamp() | timestamp_custom('%H:%M') == (state_attr('input_datetime.sunrise_alarm', 'timestamp') - 1 ) | timestamp_custom('%H:%M', false) }}"
    value_template: "{{ now().timestamp() | timestamp_custom('%H:%M') == state_attr(alarm_time, 'timestamp') | timestamp_custom('%H:%M', false) }}"
lime aurora
#

I just want to be clear here. This is a blueprint, correct? Automatons don't have inputs. Automation Blueprints and Script Blueprints do, and I believe that is the only place (currently) that they are used.
I bring this up because if you are trying to use this with a straight automation, there are other problems.

topaz lake
#

It's a blueprint, correct.

topaz lake
# lime aurora I just want to be clear here. This is a blueprint, correct? Automatons don't hav...

Thanks, bud ๐Ÿ‘Š
I didn't realize there was such a distinction between automations and automations from blueprints.
I was able to refine my Googling and figured it out.
https://www.home-assistant.io/docs/automation/trigger/#trigger-variables

Apparently in blueprints the variables aren't set until after the trigger.

Home Assistant

All the different ways how automations can be triggered.

lime aurora
#

Crap, I'm sorry, I should have picked up on that. I'm supposed to be one of the BP experts and it didn't dawn on me.