NodeRed vs native automation

Have you tried using?

trigger:
- "{{ is_state('binary_sensor.dark', 'on') and is_state('binary_sensor.home', 'on') }}"
action:
- service: light.turn_on
  entity_id: light.front_porch
1 Like

While I understand what you want to achieve , proposed syntax by you could not work as you expected because its semantical meaning could be: trigger when both of those sensors changed state together and both changed to on. Which I assume is not the goal.

Template helps it because it wraps 2 events into one template event (which triggers everytime one of them changes) then allows to evaluate boolean conditions.

IMO it adds to missunderstanding of how native automation works. not it’s illogical. behaviour is hidden/wrapped hiden lexical constructs. I’ve even saw a comment that native automations are not event based but state based which I bet it’s not true.

That’s not how it works. The trigger occurs when both have the state equal to on. Not when they go to on at the same time.

Yes… sadly, that doesn’t work.

It would work exactly like a template trigger of the same nature, as written above:

    - platform: template
      value_template: "{{ is_state('binary_sensor.dark', 'on') and is_state('binary_sensor.home', 'on') }}"

This means it would trigger on the state change of EITHER of those entities but not actually trigger unless both of the conditions specified in the template were true.

Well over half of my automations use exactly this syntax. Just one template trigger to serve as a trigger and a condition. If additionally non-triggering conditions are needed, then the automation will also have a condition template specifying those.

The only other pattern that gets frequent use is:

- trigger:
    - platform: state
      entity_id:
        - this.one
        - that.one
        - another.one

… for when I want to trigger without a “condition”. Generally speaking, though, these automations contain condition/choose commands in the “action” section.

It does work for conditions, so that’s a plus.

1 Like

it would work or it works?
AND operator is boolean one. It cannot provide OR based trigger at the same time. In other words its meaning is given, it’s strict and should be respected.
This is why I think this syntax should not make happen for what you think. I’m not saying that it’s not possible to make engine interpret this phrase as you wish. But imo it would be braking rules leading to furhter confusions.

A bit different thing is when it’s wrapped by template. And likely it how it is. Just guessing

It works this way now with a template.

The other proposed code is only proposed. It doesn’t work currently.

I see it as a “trigger” and a “condition”. Just like template trigger. I don’t see it being any different just because it’s wrapped in a template. But, I guess every user has their preferences.

Trigger templates get resolved based on the sensors used in the template. That means every time a state changes for binary_sensor.dark and binary_sensor.home occur, the template gets resolved. If the template resolves true, it triggers.

Yes I know.
I’m commenting on swifty’s proposal of getting rid of template syntax from the automation

- trigger:
    - binary_sensor.dark == 'on' and binary_sensor.home == 'on'

To me such syntax would have meaning: “trigger when both sensors turns on at the same time”.
Template is another thing and I admitted that in comments above.

I guess I don’t understand the point you’re attempting to make then. What you’re stating as ‘strict should be respected’ is next to impossible and impractical, hence why it’s designed the way it is.

I feel we don’t understand eachother. Probably the language barrier. So let it be.

In one sense yes, but in a much larger sense no.
With the new templating engine any template is evaluated when any of its components ‘update’ (in fact, pretty much like the old one) so ‘a’ flips on an off all day, with ‘b’ staying off, nothing happens. (ditto if the two are reversed) but any item changing causes re-evaluation, and if both happen to be on then the trigger should fire (I’m lost as to how this doesn’t work, stated earlier in the thread).
I’m also lost as to why this wouldn’t be translatable, pseudo code isn’t English or Russian or Anything feed it into Google and the words transfer the meaning.

When dark
Motion detected
Light on
10 minutes no motion
Light off

Not easy to trash that