Best practice to reduce automations? actions for condition

hi,
whats the best way to reduce automations ?

eg. i do have two/more automations triggered by the same
whatever_sunset starts something when condition sunset is true
whatever_sunrise start something different when condition sunrise is true.

I cant find a way like the good old if then else
Is there any?
If not i am fine with automation_name_condition.

thx

As far as I know there is no way to do this in Home Assistant, not sure why. However, you could do this with node-red so you may want to look in to that.

Take a look at AppDaemon

2 Likes

If you’re wanting to do what I think you are wanting to do, Node-red can do this really easily.

it depends on what “start something” means but you should be able to do it using if-else statements in the action using templates based on the trigger.

unless I’m missing something…?

Hi,
eg:

  • someone rings the bell (a tasmota switch2) that sends a mqtt message
  • if time between 8am and 11pm one player starts
  • if time between 8am and 11pm and temperature outside is > 20° another player should play
  • if time ist not between 8am and 11pm only the house bell should be triggered.

right now each row \edit execpt the trigger is the 1st line edit/ above is a separate automation and there are two aditional automations like summer and winter and these automations enables /disables the oposite automations because i just want to change the summer/winter recognition in a single place | automation.

cheers

action:
  - service: whatever service for your player
    data_template:
      entity_id: >
        {% if 8 < now().hour < 23 and sensor.outside_temp | int  < 20  %}
          media_player.one_player
        {% elif 8 < now().hour < 23 and sensor.outside_temp | int  > 20 %}
          media_player.other_player
        {% else %}
          media_player.dummy
        {% endif %}
  - service: how you want to ring the bell

This assumes that you don’t actually have a media_player.dummy in your system and that you always want to ring the bell no matter the conditions (you weren’t clear on if you only wanted to ring the bell if outside of those hours or always). If you only want the bell to ring only outside of the 8 to 23 hours you can add a condition before the last action:

action:
  - service: whatever service for your player
    data_template:
      entity_id: >
        {% if 8 < now().hour < 23 and sensor.outside_temp | int  < 20  %}
          media_player.one_player
        {% elif 8 < now().hour < 23 and sensor.outside_temp | int  > 20 %}
          media_player.other_player
        {% else %}
          media_player.dummy
        {% endif %}
  - condition:
      - condition: time
        after: '23:00:00'
        before: '08:00:00'
  - service: how you want to ring the bell

obviously, you need to put your own sensors and services in.

1 Like

thx a big time and

*if* you see *edit(h)*
give her a kiss from the lovely *else*

both are german prenames - not fins