Automation - if else - is that possible in one automation?

Yeah… that’s all a matter of perspective/opinion. Personally, I dislike gui based coding. It makes the process 10x slower and not much easier to read. If you want click oriented automations & flow charts, move to node red.

I will not move from HA now, everything is working fine. I just wanted to mention that for non professional developer like me it’s sometimes good to have a gui that’s also check the integrity of the logic, avoiding spending too much time trying to get the solution in the forum. But you’re right, there should be some good reasons not to integrate that kind of gui in HA.

Node red is an addon for HA, so you don’t need to move away from it. Also, there is a built in UI for automations.

1 Like

Sorry and thanks, I just discovered it now, will give a try!

1 Like

Yeah, you’ll have to ‘rewrite’ your automations in node-red. But from what I understand, it works great for people who don’t think like a developer.

I used to think as a developer when I was studying IT end of the 80s, but it was Turbo Pascal… ;0)

Hi every one,
I have some problem with an - if else - automation working on comparision of the enity “next allarm” (HA phone app sensor). I want to compare my wife and my next allarm and set an helper with the lowest value. I will use thi helper to trigger all the morning automation. So, my automation is the follow one

service: input_datetime.set_datetime
target:
entity_id: input_datetime.orario_sveglia
data_template:
datetime: >-
{% if ‘sensor.marco_s9_prossimo_allarme’ < ‘sensor.isa_s9_prossimo_allarme’ %}
{{ as_timestamp(states(‘sensor.marco_s9_prossimo_allarme’)) | timestamp_custom(‘%Y-%m-%d %H:%M:00’) }}
{%- elif ‘sensor.marco_s9_prossimo_allarme’ >= ‘sensor.isa_s9_prossimo_allarme’ %}
{{ as_timestamp(states(‘sensor.isa_s9_prossimo_allarme’)) | timestamp_custom(‘%Y-%m-%d %H:%M:00’) }}
{%- endif %}

where:

  • “Sensor.xxxx_S9_prossimo allarme” are mine (marco) and my wife (isa) next allarm sensor.
  • “input_datetime.orario_sveglia” is the helper that i want to set whit the lowest value of the two “next allarm” sensor.

Test note:

  • both the “next alarm” sensors are show correctly in HA —> no App problem
  • The timestamp of the helper works because when i lunch the automation its value change with one of the two “next allarm” sensor time. (not the correct one and this is the problem)… —> no timestamp or helper error

After different test it seem that work only the “if” part of the automation… in fact, if I put “…marco…” in the second time stamp the helper is update with marco’s next allarm value and viceversa with “…Isa…”.

I’m totally beginer in YAML (I only worked in C++)…so I need your help please!!

Thanks

SOLVED (thanks to @koying):

{% if as_timestamp(states(‘sensor.marco_s9_prossimo_allarme’)) > as_timestamp(states(‘sensor.isa_s9_prossimo_allarme’)) %}
{{ as_timestamp(states(‘sensor.isa_s9_prossimo_allarme’)) | timestamp_custom(‘%Y-%m-%d %H:%M:00’) }}
{%- else %}
{{ as_timestamp(states(‘sensor.marco_s9_prossimo_allarme’)) | timestamp_custom(‘%Y-%m-%d %H:%M:00’) }}
{%- endif %}

Hi all. Enjoyed reading this thread. Wondering if anyone can help me with a light automation.
Trigger is always motion detected.
Condition is always illuminance.
I would like to set a scene depending on time of day, so scene.morning between 0600-0800… scene.daytime between 0800-2000 and scene.night between 2000-0600.
Thanks