The B.A.BA of "automation"

Here’s an example to help you get started.

alias: example
trigger:
  - platform: state
    entity_id: input_boolean.summer
condition: []
action:
  - service: 'switch.turn_{{ trigger.to_state.state }}'
    target:
      entity_id: switch.module1
  - delay:
      seconds: 5
  - service: light.turn_on
    target:
      entity_id: light.led
    data:
       color_name: "{{ iif(trigger.to_state.state == 'on', 'green', 'red') }}"

When the Input Boolean is turned on, it turns on a switch, waits 5 seconds, then sets a light’s color to green.

When the Input Boolean is turned off, it turns off a switch, waits 5 seconds, then sets a light’s color to red.


EDIT

Correction. Fixed typos.

you likely don’t need a script or a scene.

just start with the example of the automation posted above (tho I wouldn’t start out right from the start with the templates - it’s a little advanced for where you seem to be right now)

you seem to be trying to run before you can walk.

start basic (ex. when this one trigger happens then do this one action). Once you have the basics figured out then move on to something a bit more complex, then on to the next level. etc.

yes yes I understand, and I know it’s to help me as much as possible. Thanks a lot.
I’ll try to move forward a bit and let you know. thanks again.
I can’t reply yesterday because i’m new.

thank you too.

When I read these things, I usually get the general idea.
However, in the example here, I’m interpreting:
when triggering “summer”, I change the state
of the switch module 1 (I do not interpret a switch to ON, but a change of state), wait 5 sec, then turn on the lights, and conditions in green if trigger switched to ON, and in red otherwise…

I do not interpret an ON condition of the summer trigger to switch the switch module 1 to ON, and to OFF if summer trigger is OFF…

I am wrong… ? :speak_no_evil:

Both input_boolean and switch have on and off states. The State Trigger is detecting when the input_boolean changes state. Whatever state it changes to is represented by the variable trigger.to_state.state.

All right !!
so in fact you shorthanded everything in this " _{{ trigger.to_state.state }}’ to stipulate that the switch follows the same state as the trigger…?

what is “dumb” for my situation is that I can’t recover my “input boolean summer” input as a trigger in an automation… because otherwise I think that afterwards I could have made everything flow simply by the automatic system creation of automation by HA…

That’s right. Everything between the {{ }} part is code that will be evaluated (executed) at runtime and the result of that code will then be filled in. This is called templating. In this case he used the trigger object to get the new state. Here’s some more information about the trigger object in the docs.

Doing things this way is pretty popular these days, as it allows for shorter and more powerful automations. It’s also more complicated and can easily become pretty confusing. There’s also simpler ways to write automations, although they will often be longer and you may have to split things into multiple ones. Maybe take a look at the UI editor for automations too. It has come a long way since and is pretty usable for basic stuff.

Offtopic: Je suppose que tu connais le site de la communauté francophone pour HA (https://forum.hacf.fr) ? Ils ont un forum avec pas mal de monde et du coup ça t’éviterais de traduire tout (surtout que les traductions sur des thèmes techniques peuvent partir en vrille avec les mauvais termes et personne comprend ce que tu demandes :wink:).

Hello and thank you for your answere. With all yours ideas, I progress :slight_smile:

Yes but I have begin here, and I wouldn’t make “duplicate”. But perhaps I’m going to slide on this site soon.
Thank you again

Hello to you ! :slight_smile:

good, with your comments and help, I was able to start and move forward.
I did something basic, and it works in the timeline.
however, I expose myself to operating anomalies if I intervene and change data.

Here is my “code” and I explain myself:

"
alias: AUTOMATISATION FILTRATION ETE
description: “”
trigger:

  • platform: state
    entity_id:
    • input_boolean.filtration_ete
      from: “off”
      to: “on”
      condition: []
      action:
  • type: turn_on
    device_id: 1ea6475bc6b42120527e9f592682a298
    entity_id: switch.switch_pompe
    domain: switch
  • delay:
    hours: 0
    minutes: 0
    seconds: 5
    milliseconds: 0
  • type: turn_on
    device_id: 8356bf47044fc0de7b1a1a36e45c06f5
    entity_id: switch.4_relais_vitesses_pompe_l2
    domain: switch
  • delay:
    hours: 0
    minutes: 1
    seconds: 0
    milliseconds: 0
  • if:
    • type: is_not_open
      condition: device
      device_id: 12d1c1745e3eda555bc7d130958f3e47
      entity_id: binary_sensor.contact_debit_tamper
      domain: binary_sensor
      then:
    • type: turn_on
      device_id: ea4d0240dffa6a7f93d3ae2d0bef5f7a
      entity_id: switch.switch_regul_ph_cl
      domain: switch
    • condition: time
      after: “08:00:00”
      before: “20:00:00”
      weekday:
      • mon
      • tue
      • wed
      • thu
      • fri
      • sat
      • sun
        else:
    • stop: ERREUR PAS DE DEBIT DETECTE
      error: false
      mode: single

"

so, as long as I don’t touch anything, it works.

as stated, I made the code logically in timeline: if that, then snap that, if that ok, then that… etc etc.

on the other hand, if one of the elements of my chronology changes state (and which would block in my chronological sequence), I would like it to react accordingly.

For example, if my binary_sensor.contact_debit_tamper goes is_open, switch.switch_regul_ph_cl should go turn_off, then switch.4_relais_vitesses_pompe_l2 too, then after 10 seconds, switch.switch_pompe too.

it will be the same procedure if I stop my

  • input_boolean.filtration_ete

(pass in inverse from: “on” to: “off” )

also, this part:

else:
- stop: ERROR NO FLOW DETECTED
error: false

gives me nothing (feedback, information, action, notification, …)

well, I know it’s beginner level a bit boring I guess, and I’m sorry about that.

thank you in advance for your help !

Sylvain

Hello,

my problem does not seem to be very attractive :sweat_smile:

The problem is that your posts are very difficult to understand. I know this is due to the language barrier / bad automatic translation. But it makes it hard to help you if we don’t really know what you want, because the translation doesn’t make sense.

Also, your yaml is badly formatted, which makes it completely unreadable.

I would suggest you repost your question on HACF.

#18 line 3

As described in the docs the stop message will only be in the automation trace. If you want it to be more obvious, use persistent notification.

- service: persistent_notification.create
  data:
    title:  Erreur
    message: "ERREUR PAS DE DEBIT DETECTE"