Automation issue: why isn't this wait_template waiting

I don’t understand that. Both techniques, as I suggested them, used the same trigger, right:

automation:
- trigger:
  - platform: state
    entity_id: cover.raamverduistering_stookhok

How could the behavior of the trigger change depending on what was done in the action section?

Maybe you need the condition I later suggested:

automation:
- trigger:
  - platform: state
    entity_id: cover.raamverduistering_stookhok
  condition:
  - condition: template
    value_template: >
      {{ trigger.to_state.attributes.current_position !=
         trigger.from_state.attributes.current_position }}

I think you could do the same thing more directly with an input_select.

input_select:
  raamverduistering_stookhok:
    options:
    - stationary
    - opening
    - closing
    initial: stationary
automation:
- trigger:
  - platform: state
    entity_id: cover.raamverduistering_stookhok
  condition:
  - condition: template
    value_template: >
      {{ trigger.to_state.attributes.current_position !=
         trigger.from_state.attributes.current_position }}
  action:
  - service: script.raamverduistering_stookhok
    data_template:
      old: "{{ trigger.from_state.attributes.current_position }}"
      new: "{{ trigger.to_state.attributes.current_position }}"
script:
  raamverduistering_stookhok:
    mode: restart
    sequence:
    - service: input_select.select_option
      entity_id: input_select.raamverduistering_stookhok
      data_template:
        option: "{{ 'opening' if new|float > old|float else 'closing' }}"
    - delay: 2
    - service: input_select.select_option
      entity_id: input_select.raamverduistering_stookhok
      data:
        option: stationary

Then you could do your notifying based on state changes of input_select.raamverduistering_stookhok in a separate automation. And, of course, change your icon customizations based on the one input_select instead of two input_boolean's.

2 Likes

better! this removes the issue I have with both booleans having to be toggled at the same time. very nice!

1 Like

I suppose you could even extend the options to include closed, opened & partially_opened, and at the end of the script, use new|float to decide if the cover was fully closed, fully opened, or somewhere in between.

as a matter of fact, I was already tinkering with that …:wink: My notification does something alike already.

for reference up to the post before the above, I can confirm all issues gone! no incidental double turned on booleans, which are now replaced by the input_select. Ive simply added the notification to the one automation as final step:

  raamverduistering_stookhok:
    mode: restart
    sequence:
    - service: input_select.select_option
      entity_id: input_select.raamverduistering_stookhok
      data_template:
        option: >
          {{'opening' if new|float > old|float else 'closing'}}
    - delay: 2 # might require 3, to be seen in practice
    - service: input_select.select_option
      entity_id: input_select.raamverduistering_stookhok
      data:
        option: stationary
    - condition: state
      entity_id: input_boolean.notify_developing
      state: 'on'
    - service: notify.system
      data_template:
        title: Cover is no longer moving
        message: >-
          {{as_timestamp(now())|timestamp_custom('%X')}} - Cover is
          {%- set position = state_attr('cover.raamverduistering_stookhok','current_position')|int %}
          {%- set phrase = 'positioned at: ' %}
          {%- if is_state('cover.raamverduistering_stookhok','closed')%} Closed
          {%- elif position|int == 100 %} Open
          {%- else %} {{phrase}}{{position}}
          {% endif %}

very nice indeed, so thanks again. And again. Aa.

Do you remember when we found a now() template that DID update in use ?
I think it was something stupid like : -

{{ as_timestamp(now()) | int % 2 == 0 }}

Basically this flip-flops every 2 seconds
I haven’t tried it but maybe if you incorporated something like : -

{% set notused = as_timestamp(now()) | int % 2 == 0 %}

In the template it would ‘maybe’ get looked at every 2 seconds ??? and then update the rest of the template too ???

Not sure if I’d rely on it though as this is completely undocumented

When a template is rendered has more to do with where that template is used than by the template itself. E.g., if it’s used in a condition of an automation, then it is rendered when a trigger fires. But if it’s used in a template trigger, or a template sensor, that’s a different story. It’s that use case that determines when to render the template. E.g., as currently implemented, there would be no way to get that template to render based on time changing if it was used in a template trigger. But if it was used in a template sensor, then one can use the sensor’s entity_id option to force when the template is evaluated.

True

I just didn’t consider that, Sorry !

well here is the final (…) version then, with the extended options in the end phase:

script:
  raamverduistering_stookhok:
    mode: restart
    sequence:
      - service: input_select.select_option
        entity_id: input_select.raamverduistering_stookhok
        data_template:
          option: >
            {{'Opening' if new|float > old|float else 'Closing'}}
      - delay: 2
      - service: input_select.select_option
        entity_id: input_select.raamverduistering_stookhok
        data_template:
          option: >
            {% if new|float == 100 %} Open
            {% elif new|float == 0 %} Closed
            {% else %} Stationary
            {% endif %}
      - condition: state
        entity_id: input_boolean.notify_developing
        state: 'on'
      - service: notify.system
        data_template:
          title: Cover is no longer moving
          message: >-
            {% set state = states('input_select.raamverduistering_stookhok') %}
            {{as_timestamp(now())|timestamp_custom('%X')}} - Cover is
            {%- if is_state('cover.raamverduistering_stookhok','closed')%} Closed
            {%- elif new|int == 100 %} Open
            {%- else %} {{state|lower}} at {{new|int}} %
            {% endif %}

input_boolean hasn’t got an initial anymore, because the new options also include an expansion on stationary, which can be open and closed completely.

input_select:
  raamverduistering_stookhok:
    options:
      - Stationary
      - Opening
      - Closing
      - Open
      - Closed
#    initial: Stationary

because the input_select can be manipulated in the frontend, and here it is only used to store the state the automation sets it to, Ive also created a safer sensor, to show in the frontend:

sensor:
  - platform: template
    sensors:
      cover_stookhok_position:
        friendly_name: Stookhok position
        value_template: >
          {% set position = state_attr('cover.raamverduistering_stookhok','current_position')%}
          {% set state = states('input_select.raamverduistering_stookhok')%}
          {% if state == 'Stationary' %} {{state}} at {{position|int}} %
          {% else %} {{state}}
          {% endif %}

Question, considering the above: there is no backend option to set for an input_select, to not allow manual manipulating somehow?

1 Like