Need help to change templates

Hello,

I am currently in the process of cleaning up and optimizing my automations.
Since I have taken a lot from the forum and I’m not exactly the professional for templates, I try to solve existing templates with the on-board means of Home Assistant or rearrange.
For this I need help to understand but times, just what the waiting templates I once found.
Is this the same


          - wait_template: |-
              {% if state_attr('vacuum.roborock_s7', 'battery_level') == 100 %}
                true
              {% else %}
                false
              {% endif %}

as the one here?


          - wait_for_trigger:
              - platform: state
                entity_id:
                  - vacuum.roborock_s7
                attribute: battery_level
                to: "100"

And is it possible to change such a template with HA conditions?


trigger:
  - platform: state
    entity_id:
      - sensor.roborock_s7_total_clean_area
condition:
  - condition: template
    value_template: >-
      {{ trigger.from_state is not none and trigger.to_state is not none and
      trigger.from_state.state not in ["unavailable"] and trigger.to_state.state
      | float(0) > trigger.from_state.state | float(0) }}

Work with translator, so apologies if not everything is correct.

Thanks for your help

Greetings
Moss

Following your example, the key difference is what happens when the battery level is at 100 when the wait action starts.

With a Wait for Template, if the battery level is at 100% when the the automation gets to this action, the wait will complete and the automation will continue…

With a Wait for Trigger if the battery level is at 100%, the wait for trigger will not allow the automation to continue until the battery level changes to some other value then back to 100.

If the battery level is not 100 when the wait action starts, they will both act exactly the same and will wait until the value changes to 100.

Are you asking if a Wait template can be replaced by a Condition? If that is your question, the answer is “no”. They are not the same. Conditions are checked immediately they do not wait. If they are not true in that instant, the automation stops.

Hi Drew.

Thank you for your reply. I suspected the difference between wait templates and wait triggers. I’ll just test if it works.

To my second question.
This is not a wait template but conditions or do I see it wrong? I wanted to know if you can solve this in HA with conditions, not as now with a value template.

Greetings
Moss

You can reduce the templating required by changing the trigger, but there is no way to perform a mathematical comparison of the “to state” and “from state” without a template.

trigger:
  - platform: state
    entity_id: sensor.roborock_s7_total_clean_area
    not_to:
      - unknown
      - unavailable
    not_from:
      - unknown
      - unavailable
condition:
  - condition: template
    value_template: "{{ trigger.to_state.state | float(0) > trigger.from_state.state | float(0) }}"

Thanks for the clarification

The desire to organize my automation arose because I simply despaired of a waiting template that I wanted to create, I couldn’t get it to work.

We have a PV system and I have tried to control our dishwasher so that it only starts with the program start when we have a surplus of PV power of 1500 watts.

This works


wait_for_trigger:
  - platform: numeric_state
    entity_id: sensor.pv_power_surplus
    above: 1500
timeout:
  hours: 0
  minutes: 5
  seconds: 0
  milliseconds: 0

This does not work, why I do not understand.


wait_template: |-
  {% if states('sensor.pv_power_surplus') >= "1500" %}
    true
  {% else %}
    false
  {% endif %}

It doesn’t work because it’s comparing text strings not numbers.

This will work:

wait_template: |-
  {% if states('sensor.pv_power_surplus') | int(0) >= 1500 %}
    true
  {% else %}
    false
  {% endif %}

In fact, it can be reduced to this:

wait_template: |-
  {{ states('sensor.pv_power_surplus') | int(0) >= 1500 }}

Thank you very much