Triggers don't work together

I have 2 triggers.
The first should trigger when there is an excess of 2000 W.
The second should be present when a certain time is reached.
If I put both trigger in their own automation, everything works.

But as soon as I make both into an automation, the solar trigger is no longer executed.

trigger:
  - platform: numeric_state
    entity_id: sensor.solarnet_power_grid
    below: -2000
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: template
    value_template: >-
      {{ now().strftime('%Y-%m-%d %H:%M') >=
      (as_datetime(states('input_datetime.geschirrspuler_ziel_zeit')) -
      timedelta(minutes=states('sensor._porgramm_duration') |
      int)).strftime('%Y-%m-%d %H:%M' ) }}

If i remove the template part it works fine.

Anyone an idea?

trigger:
  - platform: numeric_state
    entity_id: sensor.solarnet_power_grid
    below: -2000
    for:
      hours: 0
      minutes: 0
      seconds: 0
  - platform: template
    value_template: >-
      {% set gzz = states('input_datetime.geschirrspuler_ziel_zeit') | as_datetime | as_local %}
      {% set pd = states('sensor._porgramm_duration') | int(0) %}
      {{ now() >= gzz - timedelta(minutes = pd) }}

Go to Developer Tools > States and confirm the spelling of the following entity_id:

sensor._porgramm_duration
       ^
       |
Does it actually have an underscore here?
2 Likes

And also is it porgramm or programm?

I thought that would have been covered by my request to “confirm the spelling”. :wink:

My mistake - I thought you were only referring to the underscore :joy:

That leading underscore is problematic because I would be surprised to learn that Home Assistant created it like that. When creating a slug, it typically removes/converts non-compliant leading characters.

Example

1 Like

Ah thanks the typo i have to change, but was not the issue :smiley:

Argh yes the underscore was the issue. Think was an issue with replacement. Added now:
sensor.geschirrspuler_porgramm_duration → yes programm i have to fix as well :wink:

But it doesn’t work as expected. Once the trigger has been executed, it takes about 10-15 minutes until it is executed again. Is that normal?

A Template Trigger will trigger when its template reports true after having reported false. It will not trigger again until the template reports false first and then changes to true. It’s the change from false to true that serves to trigger it.

Reference: Template Trigger

1 Like

@123 thanks again. Then that’s my issue.

A couple of questions:

  1. What happens if the condition returns false? Does the trigger still have to return false first?
  2. In my example, is this for both triggers together or is each trigger considered individually?
  3. This is impractical for the solar use case. Is there a trick/workaround to reset it periodically every 15 minutes?

My second use case is: I have a group of hygrometers to measure humidity. If one in the group reaches the max value (>60%) a message will be sent. If a second hygrometer in the group reaches this value, no more messages will be sent as long as the 1st value is still over >60%. Do you have a good idea how solve this?

What happens if the condition returns false? Does the trigger still have to return false first?

Are you referring to the automation’s condition? Or are you referring to the Template Trigger’s template?

In my example, is this for both triggers together or is each trigger considered individually?

Each trigger is independent.

This is impractical for the solar use case. Is there a trick/workaround to reset it periodically every 15 minutes?

A Time Pattern Trigger can be configured to trigger every 15 minutes.

Create a new topic for it.

To the automation condition

Ok

Unfortunately, I didn’t see anything to make the time pattern trigger conditional.

What would work is to split the automation into two and trigger on solar grid changes and then do the check in the condition (below -2000)

What I don’t like about this solution, is that the automation condition is duplicated in two automation (except for the solar grid check).

Is there a way to reuse the automation conditions for two automations?

What happens if the condition returns false? Does the trigger still have to return false first?

Yes. What happens in the automation’s condition has no bearing on the Template Trigger’s behavior.

The Time Pattern Trigger may have a fixed interval but the automation can have a condition. It’s the combination of trigger and condition that determines if the automation executes its actions.

Maybe I’ll start from the scratch and describe the use case.

The automation should start when the power grid produces more than 2000 W or a certain target time (depending on the program) is reached.

The “other” conditions are something like: door must be closed, remote control must be on, program must be selected.

I tried to put this in an automation so that I can reuse the “other” condition and not duplicate them.
The solar grid trigger will not work, if it is permanently above -2000, i.e. i need a trigger with time pattern or on the solar grid state change. Therefore the check solar grid -2000 must be a condition and not a trigger. My objective was to reuse this “other” conditions for both cases:

  1. target time reached + other conditions
    or
  2. polar grid reached + other conditions

Currently I can only achieve this by duplicating it a)in two automations or b) duplicating in the code condition block.

  1. Is it possible to reuse the other condition somehow?
  2. Is there a completely different approach to my problem?

Ok got it. Just trigger every 15 min and make 1 additional or condition. That’s it. Sometime it’s so easy :slight_smile: