Automation that triggers a script

long story shot … im sending an alarm from my iOSdevice- the alarm is ok recieved and handled by HA. the time set in the alarm should be used in an automatin that fires a sunrice script… problem. The automation dosent trigger the script . The script runs fine when i manuel pres “run”
made an test automation to just to cut al the other things away…

alias: TEST 13:22 - Automation → Script
description: ""
triggers:
  - at: "13:22:00"
    trigger: time
actions:
  - target:
      entity_id: script.solopgangslys_sovevaerelse_9m50s
    action: script.turn_on
mode: single

And the original automation

alias: Solopgang - 10 min før iOS alarm
description: Starter solopgangslys 10 min før næste iOS-alarm
triggers:
  - entity_id: sensor.korrigeret_ios_alarm
    trigger: state
conditions:
  - condition: template
    value_template: |
      {{ states('sensor.korrigeret_ios_alarm') not in
         ['unknown', 'unavailable', '', none] }}
actions:
  - variables:
      alarm_ts: "{{ as_timestamp(states('sensor.korrigeret_ios_alarm')) }}"
      now_ts: "{{ as_timestamp(now()) }}"
      delay_seconds: "{{ (alarm_ts - now_ts - 600) | int(0) }}"
  - condition: template
    value_template: "{{ delay_seconds > 0 }}"
  - delay:
      seconds: "{{ delay_seconds }}"
  - target:
      entity_id: script.solopgangslys_sovevaerelse_9m50s
    action: script.turn_on
mode: single
max_exceeded: silent

I cant even tell where i have been so frawith this automations , but many test … im giving up and call in the cavalery :slight_smile:

The script

alias: Solopgangslys - soveværelse (9m50s)
sequence:
  - variables:
      duration: 590
      step_seconds: 10
      steps: 59
      start_brightness: 8
      end_brightness: 210
      start_kelvin: 2000
      end_kelvin: 4000
  - repeat:
      count: "{{ steps | int }}"
      sequence:
        - variables:
            fraction: "{{ (repeat.index - 1) / (steps - 1) if steps > 1 else 1 }}"
            brightness: >-
              {{ (start_brightness + fraction * (end_brightness -
              start_brightness)) | int }}
            kelvin: >-
              {{ (start_kelvin + fraction * (end_kelvin - start_kelvin)) | int
              }}
            color_temp_mireds: "{{ (1000000 / kelvin) | int }}"
        - target:
            entity_id:
              - light.lightstrip_under_seng_lys
              - light.loft
              - light.skab_1
              - light.skab_2
              - light.skab_3
              - light.skab_4
          data:
            brightness: "{{ brightness }}"
            color_temp: "{{ color_temp_mireds }}"
            transition: "{{ step_seconds }}"
          action: light.turn_on
        - delay:
            seconds: "{{ step_seconds }}"
  - target:
      entity_id:
        - light.lightstrip_under_seng_lys
        - light.loft
        - light.skab_1
        - light.skab_2
        - light.skab_3
        - light.skab_4
    data:
      brightness: "{{ end_brightness }}"
      color_temp: "{{ (1000000 / end_kelvin) | int }}"
      transition: 5
    action: light.turn_on
mode: single
icon: mdi:weather-sunset-up
description: ""

Ps im sorry for the wron word “trigger” when speaking af script . how about “run”

Firstly you can’t ‘trigger’ a script, only automations can be triggered. Secondly it’s impossible to read the yaml you posted in that format, please repost it but surround the code block with 3 backticks on the line before and after it, someting like this.
```
yaml: code

```

1 Like

I agree,
You can use the </> button like this… How to format your code in forum posts
OR… Here is an example of how to fix formatting from the site FAQ Page.
How to help us help you - or How to ask a good question.

1 Like