Script syntax errors <Missing property "condition". Why?

Hi. I am trying my first Script in YAML and so far unable to ID the cause of Studio Code Server in HA telling me I am ‘Missing property “condition”.’ at 3 points in my script.

My Objective is to set a “part_of_day” input_text helper value depending on the time of day so I can use that Helper entity value in various automations and avoid re-calculating at each need.
I thought to code this as a ‘script’ so I can run it from in Automations or stand-alone.

My script with the 3 errors showing in SCS within HA desktop is


The last ‘off-screen’ bit is

    # Now set the Part_Of_Day value
    - service: input_text.set_value
      target:
        entity_id: input_text.part_of_day
      data:
        value: l_pod
# End of set_part_of_day script

What am I missing?
Any other issues with my approach?

Many thanks.

Have you tried removing all the comments?

None of your sequences are valid.

The sequence must be a list of services.

This is not a service:

sequence:
  - l_pod: "Mornibg"

You need to write the entire service for each choose option, e.g.

sequence:
  - service: input_text.set_value
    target:
      entity_id: input_text.part_of_day
    data:
      value: Morning

Or use a data template instead of the choose sequence.

Thanks tom_I. :slightly_smiling_face:
That’s how I had it originally and thought “I can make this cleaner, neater and shorter”. !!!
Adding all those repeating code snippets back goes against 45+ years’ good programming practice.
Ok, I’ll give it a go.

EDIT: And working ok now. Again, my thanks tom_l.

set_part_of_day:
  alias: etc...
  description: etc...
  sequence:
    - service: input_text.set_value
      target:
        entity_id: input_text.part_of_day
      data:
        value: >
          {% if today_at(states('input_datetime.starttime_morning') ) < now() < today_at(states('input_datetime.starttime_afternoon') ) %}
            Morning
          {% elif today_at(states('input_datetime.starttime_afternoon') ) < now() < today_at(states('input_datetime.starttime_evening') )  %}
            Afternoon
          {% elif today_at(states('input_datetime.starttime_evening') ) < now() < today_at(states('input_datetime.starttime_nighttime') )  %}
            Evening
          {% elif today_at(states('input_datetime.starttime_nighttime') ) < now() < today_at(states('input_datetime.starttime_morning') )  %}
            Nighttime
          {% else %}
            ERROR
          {% endif %}

However there is an even easier way if you want to drop the input_datetimes:

Hi. Now that Times of Day (TOD) integration page looks interesting.
But I’m slightly confussed by what it says. I see it’s only " used by 1.9% of the active installations" and does

YAML Configuration
Alternatlively, this integration can be configured and set up manually via YAML instead. This has some additional functionality over the UI version.

imply that the integration does not need to be installed because you can do the same (and more) by using YAML code similar to the example given?
Or does installing the Times of Day integration give you the platform: tod that the example YAML uses?

I also found very helpful:

The sensor state is ON when this condition after + after_offset <= current time < before + before_offset.

I’d been wondering about that Starttime <= Time < Endtime question re Before and After on condition: time blocks. The documentation at HA Docs - Time Condition leaves it unstated.

Very useful. Thank you.

It does not need to be installed it is part of Home Assistant’s core program.

You will have to restart if you define the sensors in yaml. You won’t have to if you use the UI.