Multiple services in an automation action

I am trying to have multiple actions triggered at a certain time very week night, using this code in my automations.yaml:

- alias: 'Turn ON Bath2 Water Heater every weekday evening'
  trigger:
    platform: time
    at: '21:40:00'
  condition:
    condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
    - sat
    - sun
  action:
    service: telegram_bot.send_message
    data_template:
      title: '*HA Alert!*'
      target: '142454348'
      message: 1. Guest bathroom water heater turned ON for the evening cycle.
    service: switch.turn_on
    data:
      entity_id: 
        - switch.bath2_water_heater
    service: telegram_bot.send_message
    data_template:
      title: '*HA Alert!*'
      target: '142454348'
      message: 2. Guest bathroom water heater turned ON for the evening cycle.
    service: telegram_bot.send_message
    data_template:
      title: '*HA Alert!*'
      target: '142454348'
      message: 3. Guest bathroom water heater turned ON for the evening cycle.

Originally I just had 2 services; turn on the switch and then send the Telegram message to notify me.
What was happening was the switch would not turn on but I would get the Telegram message.

I modified the code to see if the problem was with the switch service, and it doesn’t seem to be because when I trigger this automation I only get the message 3 - the first 2 messages don’t get sent and the switch doesn’t turn on.

Do I have a mistake in my code that would cause only the last service call to be processed?

Thanks!

try this:

- alias: 'Turn ON Bath2 Water Heater every weekday evening'
  trigger:
    platform: time
    at: '21:40:00'
  condition:
    condition: time
    weekday:
    - mon
    - tue
    - wed
    - thu
    - fri
    - sat
    - sun
  action:
    - service: telegram_bot.send_message
      data_template:
        title: '*HA Alert!*'
        target: '142454348'
        message: 1. Guest bathroom water heater turned ON for the evening cycle.
    - service: switch.turn_on
      data:
        entity_id: 
          - switch.bath2_water_heater
    - service: telegram_bot.send_message
      data_template:
        title: '*HA Alert!*'
        target: '142454348'
        message: 2. Guest bathroom water heater turned ON for the evening cycle.
    - service: telegram_bot.send_message
      data_template:
        title: '*HA Alert!*'
        target: '142454348'
        message: 3. Guest bathroom water heater turned ON for the evening cycle.
1 Like

Perfect - thanks very much.

I obviously have some more learning to do - I have other automations that don’t have the - before the service: and even some of the examples don’t have it, such as this one:

But making the changes you suggested works perfectly! Not my water heater can turn on & off at the optimal times!

Thanks so much!

When there is one action the dash is not necessary.
The template switch is a switch btw, not a automation. As far as I know the examples in the docs are correct.

The condition in your automation is useless btw. It checks if today is one of the listed days, but all 7 days are listed. So it is always true. If that is what you want, you can leave it out.

1 Like

Oh yeah, I normally don’t have the 2 weekend days in the list but I was testing over the weekend so added them in temporarily.

One action, no dash. That probably explains why my other automation with no dash work!

Learning a lot tonight - thanks very much for the help.

Glad to help :grinning: