Automation - trigger for state - crazy behaviour (maybe a bug?)

@Mutt, unfortunately, I got error when I tried to add automation.

I had to use service_template like so:

- alias: Pump Control
  trigger:
    - platform: state
      entity_id: binary_sensor.bs_pump_enable
  action:
    - service_template: switch.turn_{{trigger.to_state.state}}
      entity_id: switch.floor_pump

and there was a typo in value_template, it should be:

{{ vkit or vbth or vcdr or vbed or vkid }}

It should be vkid instead of vkis :grinning:

Thank You so much for help. I only tested this on a spare Pi and my test system but it looks like everything works. I’ve changed switches many times and it just works :slight_smile:

I’m more and more confused when I start to learn HA more. Automations bypass the delays when you fire them twice, but value_template’s don’t. This all is very confusing :confused:
I still think that this behavior (in automation) is a bug.

Sorry about the typos (two ! :scream: ), glad you found them and have a working solution
There is a distinction between the two.
One is intended to operate on a value crossing (as discussed), whereas the binary_sensor pretty much always works on a template (never done one that doesn’t) but it’s the delay_on you are in love with.
They are both as design.
But you get an idea how a proper description leads you to a more appropriate solution.
I’m still waiting for Petro or pnbruckner or Teras to come back with a 3 line solution or some such :rofl:

Are you using an editor (notepad++, atom etc.) or the built-in tools (automation editor :face_vomiting:) ? The former is harder but you learn more faster.

Edit: I’ll modify the above so there’s less chance of someone copying bad code.

having a small jump-in, so forgive me if I miss something already discussed, but why won’t you simply use a group with these entities, and use that group’s state to trigger?
you can play with the ‘all’ option if you need them all to be on or off the set the specific behavior

the above template would the simply be:

binary_sensor:
  - platform: template
    sensors:
      bs_pump_enable:
        value_template: >
          {{ is_state('group.valves','on') }}
        delay_on: '00:00:30'
        friendly_name: Pump Enable

of course this group by default will only turn-off when all valves are off, but that’s where the 'all option can change behavior

Marius,
Yep, and I did say exactly that in my solution post.

The reasons I didn’t go with that are : -

  1. Misiu is a beginner so groups would be an extra step
  2. This introduces him to templates in a simple and clear way to use multiple elements.
  3. Is extendable to other uses (with or without delay on / delay off)
  4. Is very easy to maintain (in case he adds another valve (unlikely but…)

My $0.02 anyway

1 Like

ok sorry, hence my opening remark…

otoh, most certainly novices should get a good grasp of the inner workings of Hassio, groups is among the very basic and powerful aspects of HA.

As this would demonstrate, it wouldn’t even need a template to do as he desires.

tbh, maintainability using the group technique is way beyond (much easier and les error prone because of that) that of the templates of course. Only change the entities in the group, and you’re set.

I agree almost entirely,

But unless you have your head round it, the inclination (when changing the logic) is to go to where the logic is written, and not go to where the group is written.
We both ended at the same spot so it’s more down to the OP

But, how would he not need a template ?
Ahh! You mean go back to a simple automation but triggered on the group, so his delay would not be compromised, true

Misiu, if you consider your problem (as posted) solved can you please mark the post you feel helped you the most, as the solution.
This helps people searching for similar solutions AND the people working on the forum trying to help others (they spend less time reading problems that have a solution.

Sorry for not doing that earlier and once again thank you for Your help! :clap:

Not a problem, I’m impressed with
a) how you have managed so far
b) the fact that it is obvious that you have tried various things before asking for help
Happy Automating

I’m not ashamed of asking for help, but before I ask for it I always try to do something on my own :slight_smile:
It this case the lack of knowledge how HA works in the inside was the reason all my trials failed.

I hope that other newcomers will find this topic helpful like I did.