Where to put an automation script?

Sorry if this us a dumb question. Still learning. I want to use this script that I found in a community thread:

alias: Example 1
trigger:
  - platform: time
    at:
      - '05:00:00'
      - '05:15:00'
  - platform: homeassistant
    event: start
condition: "{{ (now() - as_datetime('19700101T00Z')).days % 2 == 0 }}"
action:
  - service: "switch.turn_{{ iif(now().hour == 5 and 0 <= now().minute < 15, 'on', 'off') }}"
    target:
      entity_id: switch.your_device

Question is, where do I enter this? I’ve looked around the UI under automations and can’t seem to find the right place.

The automation example you posted looked very familiar to me and then I realized it’s something I had created almost three years ago.

That’s an automation as opposed to a script (two different terms in Home Assistant).

Start Home Assistant’s Automation Editor like this:

  • Settings → Automation & scenes → Create Automation → Create new automation
  • Click the overflow menu in the upper right corner (three vertical dots) and select Edit in YAML.
  • Delete the existing YAML code displayed in the editing window.
  • Copy the automation example posted above and paste it into the Automation Editor’s editing window then click Save.

References

Automation
Script
Glossary

1 Like

Ha. Small world!

Did my instructions answer your question regarding where to enter the automation’s YAML code? Or do you require additional assistance?

1 Like