Help with a script

I have the following script which was working ok until I try to change the order of the

#- service: automation.trigger
    #entity_id:
    #- automation.set_alarm_at_night 

and move it at the end of the code.
like this

go_to_bed:
  alias: Goodnight
  icon: mdi:bed-empty
  sequence:
  #- service: automation.trigger
    #entity_id:
    #- automation.set_alarm_at_night  
  - service: light.turn_on
    data:
      entity_id: light.bedside_lamp
      
  - service: homeassistant.turn_off
    data:
      entity_id:
      - media_player.lg_tv_webos_2
      - climate.living_room_ac
  
  - service: script.close_cover
    data:
      entity_id: cover.50758014840d8e91f4fd # main window
  - delay: '00:00:40'
  
  - service: script.close_cover
    data:
      entity_id: cover.50758014840d8e91f036 # erker
  - delay: '00:00:15'
  
  - service: script.close_cover
    data:
      entity_id: cover.50758014840d8e91eaa2 #bedroom
  - delay: '00:00:15'
  
  - service: script.close_cover
    data:
      entity_id: cover.50758014840d8e918632 #kid
  - delay: '00:00:10'
  
  - service: homeassistant.turn_off
    data:
      entity_id:
      - light.77626641ecfabc96e072
      - light.77626641ecfabc976395
      - switch.kitchen_main_kitchen
      - switch.kitchen_main_kitchen_spot  
      - switch.balcony_main_channel  
      - switch.balcony_balcony_1
      - switch.balcony_balcony_2
      - switch.bedroom_balcony
      - switch.kid_balcony
  - delay: '00:00:04'
  
  - service: homeassistant.turn_off
    data:
      entity_id:
      - switch.book
      - switch.book_main_book_2
  - delay: '00:00:04'


  - service: homeassistant.turn_off
    data:
      entity_id:      
      - switch.sonoff_1000a05283
      - switch.sonoff_10009bd11e
      - switch.sonoff_10001bb5c7
      
  - delay: '00:00:15'
  - service: automation.trigger
    entity_id:
    - automation.set_alarm_at_night

Yesterday evening it won’t arm the alarm as it should be.
Anyone can tell me why?

Moreover, I would like to add the script the following code in order to know what is “on”
I give it some tries but never manage to get any notifications.
Apparently I am doing something wrong, but I can not find out what.
Ideally, I want to add it at the end of the script

#  - service: notify.pushbullet_notification
#    data: 
#      title: 'What is on'
#      message:
#      value_template: >
#        {{ states['cover'] | selectattr('state','eq', 'open') | map(attribute='name') | list | join(', ') }}
#        {{ states['cover'] | selectattr('state','eq', 'unknown') | map(attribute='name') | list | join(', ') }}
#        {{ states['switch'] | selectattr('state','eq', 'on') | map(attribute='name') | list | join(', ') }}
#        {{ states['light'] | selectattr('state','eq', 'on') | map(attribute='name') | list | join(', ') }}

What conditions do you have on the automation?

As for your notification, it’s not formatted correctly and you’re not using data_template. You copied value_template from something else then pasted it past message. It needs to be the messages template.

  - service: notify.pushbullet_notification
    data_template: 
      title: 'What is on'
      message: >
        {{ states['cover'] | selectattr('state','eq', 'open') | map(attribute='name') | list | join(', ') }}
        {{ states['cover'] | selectattr('state','eq', 'unknown') | map(attribute='name') | list | join(', ') }}
        {{ states['switch'] | selectattr('state','eq', 'on') | map(attribute='name') | list | join(', ') }}
        {{ states['light'] | selectattr('state','eq', 'on') | map(attribute='name') | list | join(', ') }}

Also, it can be greatly simplified.

  - service: notify.pushbullet_notification
    data_template: 
      title: 'What is on'
      message: >
        {{ states | selectattr('domain', 'in', ['cover', 'switch', 'light']) | selectattr('state', 'in', ['open', 'unknown', 'on']) | map(attribute='name') | list | join(', ') }}

It is not condition based, I have a button on HA to call the script.

Thanks for the notification, I will change my code accordingly.

If it’s a script, just call the script instead of triggering an automation.

1 Like

didn’t understand right your question.

the automation (and the condition) is the following.
I “moved” the condition in the action as an example I saw sometime ago

### Alarm Automations #############
- alias: set_alarm_at_night
  trigger:
    platform: time
    at: "01:30"
    
  #condition:
    #condition: state
    #entity_id: alarm_control_panel.mqtt_alarm
    #state: "disarmed"

  action:
    - condition: state
      entity_id: alarm_control_panel.mqtt_alarm
      state: "disarmed"
    - service: mqtt.publish
      data:
        topic: "paradoxdCTL/in"
        payload: '{