Conditional action in an automation script

Hi,

Can someone help me ?
I’ve an automation rule running each time I just arrived at home.
This rule is pretty simple. It logs the entry in a slack channel and then I run some rest command delayed by 10 seconds. Each rest_command calls an url what launch a TTS on my voice system.

Is there any way to not launch rest_command on a condition ?
For example, rest_command.arrose_les_plantes says how many plants I’ve to feed. But, i don’t want to listen “you’ve 0 plant to feed” each time i’m arriving home.

My automation rules is :

automation 5:
  alias: "l arriving Home"
  trigger:
   platform: state
   entity_id: input_select.me_status_dropdown
   to: 'Just Arrived'
  action:
   - service: notify.home
     data_template:
      message: >
       je suis rentré à la maison.
   - service: rest_command.me_in
   - delay: 00:03:00
   - service: rest_command.temperature
   - delay: 00:00:10
   - service: rest_command.temperature_ext
   - delay: 00:00:10
   - service: rest_command.arrose_les_plantes
#   - delay: 00:00:10
#   - service: rest_command.arrose
   - delay: 00:00:10
   - service: rest_command.meteodujour
   - delay: 00:00:10
   - service: rest_command.calendar

Thanks for your help…

Yes, you can do this! It looks like you only have one command that you “sometimes” want to not happen, so this makes things a bit easier.

As the second example on this page shows, you can have a condition in the action of an automation. So, assuming you can see the number of plants that need watering in home assistant, you can apply a numeric_state condition of above 0, and then call the rest_command.arrose after that. If the condition is not met, the automation action will end before calling the command.

Hi,

Thanks for your help.

The main question is : if I do :

action:
- service: notify.notify
data:
message: Testing conditional actions
- condition: or
conditions:
- condition: template
value_template: ‘{{ states.sun.sun.attributes.elevation < 4 }}’
- condition: template
value_template: ‘{{ states.sensor.sensorluz_7_0.state < 10 }}’
- service: scene.turn_on
entity_id: scene.DespiertaDespacho

and I’ve to add another action after, how can I do that ? the other added action should be always done.

1 Like