What is wrong with this simple script that triggers every hour?

I wrote a script that sets a percentage to my blinder every 30 minutes.

alias: Fechamento gradual persiana escritório
description: Fecha a persiana escritório gradualmente
triggers:
  - at: "14:30:00"
    trigger: time
  - at: "15:00:00"
    trigger: time
  - at: "15:30:00"
    trigger: time
  - at: "16:00:00"
    trigger: time
  - at: "16:30:00"
    trigger: time
  - at: "17:00:00"
    trigger: time
  - at: "17:30:00"
    trigger: time
  - at: "18:00:00"
    trigger: time
  - at: "18:30:00"
    trigger: time
conditions:
  - condition: state
    entity_id: input_boolean.persiana_automatica_escritorio
    state: "on"
  - condition: not
    conditions:
      - type: is_not_open
        condition: device
        device_id: df15be24bd85a9f8acae6ce3d53974ca
        entity_id: ff8160e90429a35e3ec83ff6aa8c0a4f
        domain: binary_sensor
actions:
  - data:
      device_name: persiana escritorio
      position: >-
        {% set current_time = now().strftime("%H:%M") %} {% if current_time ==
        "14:30" %} 15   {% elif current_time == "15:00" %} 30   {% elif
        current_time == "15:30" %} 35   {% elif current_time == "15:45" %} 45  
        {% elif current_time == "16:00" %} 55  {% elif current_time == "16:30"
        %} 60 {% elif current_time == "17:00" %} 65   {% elif current_time ==
        "17:30" %} 75   {% elif current_time == "18:00" %} 85   {% elif
        current_time == "18:30" %} 92   {% endif %}
    action: script.persiana_quarto_patch
mode: single

here’s the trace:

Executed: May 16, 2025 at 4:32:13 PM
Error: Error rendering data template: TypeError: Type is not JSON serializable: LoggingUndefined
Result:
params:
  domain: script
  service: persiana_quarto_patch
  service_data:
    device_name: persiana escritorio
    position: ''
  target: {}
running_script: true
child_id:
  domain: script
  item_id: persiana_quarto_patch
  run_id: bd87511bf417307f351a3fdb36b6ec81

it’s sending no position. The only way this can happen is if the script triggers 1 or more minutes after the current_time, as in that case the position is going to be undefined. Is it possible to happen? Could it be that my raspberry pi 5 is so slow that it takes more than 1 minute to trigger?

I’m not 100% sure it’s your problem but have you thought about using the time pattern trigger instead of specific times?

You don’t have an else statement and if you’re testing it, the template will produce an empty string for the position.

It’s not super likely, but it is possible. To guard against it you can use the variable trigger.now.

alias: Fechamento gradual persiana escritório
description: Fecha a persiana escritório gradualmente
triggers:
  - trigger: time
    at: 
      - "14:30:00"
      - "15:00:00"
      - "15:30:00"
      - "16:00:00"
      - "16:30:00"
      - "17:00:00"
      - "17:30:00"
      - "18:00:00"
      - "18:30:00"
conditions:
  - condition: state
    entity_id: input_boolean.persiana_automatica_escritorio
    state: "on"
  - condition: not
    conditions:
      - type: is_not_open
        condition: device
        device_id: df15be24bd85a9f8acae6ce3d53974ca
        entity_id: ff8160e90429a35e3ec83ff6aa8c0a4f
        domain: binary_sensor
actions:
  - variables:
      position: |
        {% set times = {"1430": 15, "1500": 30,
        "1530": 35, "1545": 45, "1600": 55, "1630": 60, 
        "1700": 65, "1730": 75, "1800": 85, "1830": 92 }%}
        {{ times.get( (trigger.now).strftime('%H%M'), 100) }}
  - data:
      device_name: persiana escritorio
      position: "{{ position }}"
    action: script.persiana_quarto_patch
mode: single