YAML got you down? Try OttoScript

OttoScript is a new language designed for writing Automations, which aims to be easy to read and learn, yet flexible and powerful. My goal was build something that anyone can get started with in 15 minutes, yet can scale up to all but the most complex home automations. Here’s an example OttoScript:

AUTO morning_routine
  IF input_boolean.vacation_mode != 'on'
    DISARM alarm_control_panel.main
    UNLOCK AREA entry
  OPEN cover.master_bedroom_window

It shouldn’t take much to figure out what’s going on here - which is kind of the point! I wanted OttoScript to abstract away most of the technical details so that I could spend my time on deciding on what to do, rather than how to do it. I’ve been running (nearly) my entire home setup on OttoScript for the last couple weeks and, at least for me, it’s made updating and refining automations tremendously easier and more fun.

Cool things about OttoScript:

  1. It doesn’t have many fussy rules. The line breaks, indentation, and even capitalization are purely for human readability. You could put the whole thing on one line, all in lower case and it would still work.
  2. It supports variables (and even global variables) right out of the box. Want to turn off a light, then turn it back on to the same brightness it was before? Try this:
@prior = light.office_light:brightness
 DIM light.office_light TO 0
 DIM light.office_light TO @prior
  1. Information about what triggered your automation is automatically available to your automation in the @trigger variable, so you can have conditions based on which light changed
  2. Areas and entities are both supported, and doing the same thing to multiple entities usually just requires a comma separated list like this:
    DIM AREA office, kitchen, dining_room TO 50%
  3. YAML config requirements are minimal (just specify which directory holds your .otto files), but optionally allows creating area groups - so you can write first_floor in your script and OttoScript will know to include the kitchen, dining_room - whatever areas you specify. You can even group your groups to create a hierarchy!
  4. The actions section (everything between the WHEN statement and the semi-colon) is free form. You can have multiple if statements and switch (aka ‘choose’) statements, and you can nest them inside each other as deep as you want. Unlike YAML, one failed condition doesn’t stop the rest of the script from running.

Current Limitations - this is only v0.4 after all….

  • Only State, Time and Sun-based triggers are currently supported. Event/Numeric States/MQTT will come in a future release.
  • The nice, intuitive OPEN/DISARM/UNLOCK style commands only exist for a few services right now. However CALL let’s you run any HA service:
    CALL automation.trigger ON automation.icky_yaml WITH (prejudice=extreme)
    so there’s very little you can’t do with OttoScript.
  • The only way to disable an automation is to delete it from the file (of course, you can work around this for now by creating input_booleans and checking those at the start of the automation).
  • There isn’t a nice installer - you’ll have to clone two different repositories into the correct locations (If anyone has experience building custom components and wants to offer assistance, it will greatly speed up the process of getting this into HACS). It also requires that you have PyScript installed (which you should anyway, because it’s awesome).
  • Debugging information is written out the HomeAssistant logs, which isn’t super convenient.
  • When you update your scripts, you have to manually reload PyScript to get it to register.

Code contributions and feedback are greatly appreciated! I’ve had a blast writing this and I hope others find it useful. Huge thanks to @craigb for PyScript, without which OttoScript wouldn’t exist.

OttoScript (Main repository)
Latest release: https://github.com/qui3xote/ottoscript/releases/tag/v0.4

OttoPyScript (necessary shim for running on HA)
Latest release: https://github.com/qui3xote/ottopyscript/releases/tag/v0.3